Skip to content

Commit

Permalink
ndb: switch to nostrdb notes
Browse files Browse the repository at this point in the history
This is a refactor of the codebase to use a more memory-efficient
representation of notes. It should also be much faster at decoding since
we're using a custom C json parser now.

Changelog-Changed: Improved memory usage and performance when processing events
  • Loading branch information
jb55 committed Aug 3, 2023
1 parent 55bbe8f commit cebd1f4
Show file tree
Hide file tree
Showing 110 changed files with 2,142 additions and 1,788 deletions.
45 changes: 39 additions & 6 deletions damus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
4C285C8E28399BFE008A31F1 /* SaveKeysView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C285C8D28399BFD008A31F1 /* SaveKeysView.swift */; };
4C28A4122A6D03D200C1A7A5 /* ReferencedId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C28A4112A6D03D200C1A7A5 /* ReferencedId.swift */; };
4C2B10282A7B0F5C008AA43E /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C2B10272A7B0F5C008AA43E /* Log.swift */; };
4C2B7BF22A71B6540049DEE7 /* Id.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C2B7BF12A71B6540049DEE7 /* Id.swift */; };
4C2CDDF7299D4A5E00879FD5 /* Debouncer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C2CDDF6299D4A5E00879FD5 /* Debouncer.swift */; };
4C30AC7229A5677A00E2BD5A /* NotificationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C30AC7129A5677A00E2BD5A /* NotificationsView.swift */; };
4C30AC7429A5680900E2BD5A /* EventGroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C30AC7329A5680900E2BD5A /* EventGroupView.swift */; };
Expand Down Expand Up @@ -229,7 +230,6 @@
4CA352A02A76AE80003BB08B /* Notify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA3529F2A76AE80003BB08B /* Notify.swift */; };
4CA352A22A76AEC5003BB08B /* LikedNotify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA352A12A76AEC5003BB08B /* LikedNotify.swift */; };
4CA352A42A76AFF3003BB08B /* UpdateStatsNotify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA352A32A76AFF3003BB08B /* UpdateStatsNotify.swift */; };
4CA352A62A76B020003BB08B /* Pubkey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA352A52A76B020003BB08B /* Pubkey.swift */; };
4CA352A82A76B37E003BB08B /* NewMutesNotify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA352A72A76B37E003BB08B /* NewMutesNotify.swift */; };
4CA352AA2A76BF3A003BB08B /* LocalNotificationNotify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA352A92A76BF3A003BB08B /* LocalNotificationNotify.swift */; };
4CA352AC2A76C07F003BB08B /* NewUnmutesNotify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA352AB2A76C07F003BB08B /* NewUnmutesNotify.swift */; };
Expand Down Expand Up @@ -268,6 +268,10 @@
4CB9D4A72992D02B00A9A7E4 /* ProfileNameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB9D4A62992D02B00A9A7E4 /* ProfileNameView.swift */; };
4CB9D4A92992D2F400A9A7E4 /* FollowsYou.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB9D4A82992D2F400A9A7E4 /* FollowsYou.swift */; };
4CBCA930297DB57F00EC6B2F /* WebsiteLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CBCA92F297DB57F00EC6B2F /* WebsiteLink.swift */; };
4CC14FEF2A73FCCB007AEB17 /* IdType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC14FEE2A73FCCB007AEB17 /* IdType.swift */; };
4CC14FF12A73FCDB007AEB17 /* Pubkey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC14FF02A73FCDB007AEB17 /* Pubkey.swift */; };
4CC14FF52A740BB7007AEB17 /* NoteId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC14FF42A740BB7007AEB17 /* NoteId.swift */; };
4CC14FF92A741939007AEB17 /* Referenced.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC14FF82A741939007AEB17 /* Referenced.swift */; };
4CC6193A29DC777C006A86D1 /* RelayBootstrap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6193929DC777C006A86D1 /* RelayBootstrap.swift */; };
4CC7AAE7297EFA7B00430951 /* Zap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC7AAE6297EFA7B00430951 /* Zap.swift */; };
4CC7AAEB297F0AEC00430951 /* BuilderEventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC7AAEA297F0AEC00430951 /* BuilderEventView.swift */; };
Expand Down Expand Up @@ -589,6 +593,7 @@
4C285C8D28399BFD008A31F1 /* SaveKeysView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaveKeysView.swift; sourceTree = "<group>"; };
4C28A4112A6D03D200C1A7A5 /* ReferencedId.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReferencedId.swift; sourceTree = "<group>"; };
4C2B10272A7B0F5C008AA43E /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
4C2B7BF12A71B6540049DEE7 /* Id.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Id.swift; sourceTree = "<group>"; };
4C2CDDF6299D4A5E00879FD5 /* Debouncer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Debouncer.swift; sourceTree = "<group>"; };
4C30AC7129A5677A00E2BD5A /* NotificationsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsView.swift; sourceTree = "<group>"; };
4C30AC7329A5680900E2BD5A /* EventGroupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventGroupView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -762,7 +767,6 @@
4CA3529F2A76AE80003BB08B /* Notify.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notify.swift; sourceTree = "<group>"; };
4CA352A12A76AEC5003BB08B /* LikedNotify.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LikedNotify.swift; sourceTree = "<group>"; };
4CA352A32A76AFF3003BB08B /* UpdateStatsNotify.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateStatsNotify.swift; sourceTree = "<group>"; };
4CA352A52A76B020003BB08B /* Pubkey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pubkey.swift; sourceTree = "<group>"; };
4CA352A72A76B37E003BB08B /* NewMutesNotify.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewMutesNotify.swift; sourceTree = "<group>"; };
4CA352A92A76BF3A003BB08B /* LocalNotificationNotify.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalNotificationNotify.swift; sourceTree = "<group>"; };
4CA352AB2A76C07F003BB08B /* NewUnmutesNotify.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewUnmutesNotify.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -808,6 +812,10 @@
4CB9D4A62992D02B00A9A7E4 /* ProfileNameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileNameView.swift; sourceTree = "<group>"; };
4CB9D4A82992D2F400A9A7E4 /* FollowsYou.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowsYou.swift; sourceTree = "<group>"; };
4CBCA92F297DB57F00EC6B2F /* WebsiteLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebsiteLink.swift; sourceTree = "<group>"; };
4CC14FEE2A73FCCB007AEB17 /* IdType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdType.swift; sourceTree = "<group>"; };
4CC14FF02A73FCDB007AEB17 /* Pubkey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pubkey.swift; sourceTree = "<group>"; };
4CC14FF42A740BB7007AEB17 /* NoteId.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteId.swift; sourceTree = "<group>"; };
4CC14FF82A741939007AEB17 /* Referenced.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Referenced.swift; sourceTree = "<group>"; };
4CC6193929DC777C006A86D1 /* RelayBootstrap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayBootstrap.swift; sourceTree = "<group>"; };
4CC7AAE6297EFA7B00430951 /* Zap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Zap.swift; sourceTree = "<group>"; };
4CC7AAEA297F0AEC00430951 /* BuilderEventView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuilderEventView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1309,7 +1317,7 @@
4C363A8F28247A1D006E126D /* NostrLink.swift */,
50088DA029E8271A008A1FDF /* WebSocket.swift */,
4C28A4112A6D03D200C1A7A5 /* ReferencedId.swift */,
4CA352A52A76B020003BB08B /* Pubkey.swift */,
4C2B7BF12A71B6540049DEE7 /* Id.swift */,
);
path = Nostr;
sourceTree = "<group>";
Expand Down Expand Up @@ -1555,6 +1563,25 @@
path = Profile;
sourceTree = "<group>";
};
4CC14FEC2A73FC9A007AEB17 /* Types */ = {
isa = PBXGroup;
children = (
4CC14FED2A73FCBB007AEB17 /* Ids */,
);
path = Types;
sourceTree = "<group>";
};
4CC14FED2A73FCBB007AEB17 /* Ids */ = {
isa = PBXGroup;
children = (
4CC14FEE2A73FCCB007AEB17 /* IdType.swift */,
4CC14FF02A73FCDB007AEB17 /* Pubkey.swift */,
4CC14FF42A740BB7007AEB17 /* NoteId.swift */,
4CC14FF82A741939007AEB17 /* Referenced.swift */,
);
path = Ids;
sourceTree = "<group>";
};
4CC7AAEE297F11B300430951 /* Events */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1652,6 +1679,7 @@
children = (
4C1D4FB32A7967990024F453 /* build-git-hash.txt */,
4CA3529C2A76AE47003BB08B /* Notify */,
4CC14FEC2A73FC9A007AEB17 /* Types */,
F7F0BA23297892AE009531F3 /* Modifiers */,
4C4A3A5A288A1B2200453788 /* damus.entitlements */,
4CE4F9DF285287A000C00DD9 /* Components */,
Expand Down Expand Up @@ -1684,6 +1712,7 @@
4CE6DEF627F7A08200C66700 /* damusTests */ = {
isa = PBXGroup;
children = (
4C0379642A7BFE8E0037B8C4 /* Events */,
4C9B0DEC2A65A74000CBDA21 /* Util */,
4C0C03962A61E2670098B3B8 /* Fixtures */,
4C7D097D2A0C58B900943473 /* WalletConnectTests.swift */,
Expand Down Expand Up @@ -2087,6 +2116,7 @@
4C3EA67728FF7A9800C48A62 /* talstr.c in Sources */,
4CE6DEE927F7A08100C66700 /* ContentView.swift in Sources */,
4CEE2AF5280B29E600AB5EEF /* TimeAgo.swift in Sources */,
4CC14FF12A73FCDB007AEB17 /* Pubkey.swift in Sources */,
4CA9275D2A28FF630098A105 /* LongformView.swift in Sources */,
4C75EFAD28049CFB0006080F /* PostButton.swift in Sources */,
504323A92A3495B6006AE6DC /* RelayModelCache.swift in Sources */,
Expand Down Expand Up @@ -2124,7 +2154,6 @@
4CE0E2AF29A2E82100DB4CA2 /* EventHolder.swift in Sources */,
4C5D5C992A6AF8F80024563C /* NdbNote.swift in Sources */,
4CF0ABF029857E9200D66079 /* Bech32Object.swift in Sources */,
4CA352A62A76B020003BB08B /* Pubkey.swift in Sources */,
4C3D52B8298DB5C6001C5831 /* TextEvent.swift in Sources */,
4C216F362870A9A700040376 /* InputDismissKeyboard.swift in Sources */,
4C8D1A6F29F31E5000ACDF75 /* FriendsButton.swift in Sources */,
Expand Down Expand Up @@ -2180,6 +2209,7 @@
4C285C8228385570008A31F1 /* CarouselView.swift in Sources */,
3A3040F129A8FF97008A0F29 /* LocalizationUtil.swift in Sources */,
F75BA12D29A1855400E10810 /* BookmarksManager.swift in Sources */,
4CC14FEF2A73FCCB007AEB17 /* IdType.swift in Sources */,
4C3EA67F28FFC01D00C48A62 /* InvoiceView.swift in Sources */,
4CE8794829941DA700F758CC /* RelayFilters.swift in Sources */,
4CEE2B02280B39E800AB5EEF /* EventActionBar.swift in Sources */,
Expand All @@ -2197,6 +2227,7 @@
4C7D09682A0AE9B200943473 /* NWCScannerView.swift in Sources */,
4CA352A42A76AFF3003BB08B /* UpdateStatsNotify.swift in Sources */,
4C0A3F93280F66F5000448DE /* ReplyMap.swift in Sources */,
4C2B7BF22A71B6540049DEE7 /* Id.swift in Sources */,
7C95CAEE299DCEF1009DCB67 /* KFOptionSetter+.swift in Sources */,
4C7D09722A0AEF5E00943473 /* DamusGradient.swift in Sources */,
4CCEB7B029B5415A0078AA28 /* SearchingProfileView.swift in Sources */,
Expand Down Expand Up @@ -2271,6 +2302,7 @@
4C3EA64128FF553900C48A62 /* hash_u5.c in Sources */,
4C1253542A76C7D60004F4B8 /* LogoutNotify.swift in Sources */,
5C513FCC2984ACA60072348F /* QRCodeView.swift in Sources */,
4CC14FF52A740BB7007AEB17 /* NoteId.swift in Sources */,
4C19AE512A5CEF7C00C90DB7 /* NostrScript.swift in Sources */,
4C3EA64F28FF59F200C48A62 /* tal.c in Sources */,
4CB88393296F798300DC99E7 /* ReactionsModel.swift in Sources */,
Expand All @@ -2294,6 +2326,7 @@
3A4647CF2A413ADC00386AD8 /* CondensedProfilePicturesView.swift in Sources */,
D2277EEA2A089BD5006C3807 /* Router.swift in Sources */,
3A90B1812A4EA3AF00000D94 /* UserSearchCache.swift in Sources */,
4CC14FF92A741939007AEB17 /* Referenced.swift in Sources */,
4C5C7E6A284EDE2E00A22DF5 /* SearchResultsView.swift in Sources */,
4CE1399429F0669900AC6A0B /* BigButton.swift in Sources */,
7C60CAEF298471A1009C80D6 /* CoreSVG.swift in Sources */,
Expand Down Expand Up @@ -2701,7 +2734,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 8;
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -2750,7 +2783,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 8;
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
ENABLE_PREVIEWS = YES;
Expand Down
17 changes: 11 additions & 6 deletions damus/Components/Search/SearchHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ struct SearchHeaderView: View {

func unfollow(_ hashtag: String) {
is_following = false
handle_unfollow(state: state, unfollow: .t(hashtag))
handle_unfollow(state: state, unfollow: FollowRef.hashtag(hashtag))
}

func follow(_ hashtag: String) {
is_following = true
handle_follow(state: state, follow: .t(hashtag))
handle_follow(state: state, follow: .hashtag(hashtag))
}

func FollowButton(_ ht: String) -> some View {
Expand Down Expand Up @@ -104,15 +104,20 @@ struct SearchHeaderView: View {
}
}

func hashtag_matches_search(desc: DescribedSearch, ref: ReferencedId) -> Bool {
guard let ht = desc.is_hashtag, ref.key == "t" && ref.ref_id == ht
else { return false }
func hashtag_matches_search(desc: DescribedSearch, ref: FollowRef) -> Bool {
guard case .hashtag(let follow_ht) = ref,
case .hashtag(let search_ht) = desc,
follow_ht == search_ht
else {
return false
}

return true
}

func is_following_hashtag(contacts: NostrEvent?, hashtag: String) -> Bool {
guard let contacts else { return false }
return is_already_following(contacts: contacts, follow: .t(hashtag))
return is_already_following(contacts: contacts, follow: .hashtag(hashtag))
}


Expand Down
2 changes: 1 addition & 1 deletion damus/Components/TranslateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func translate_note(profiles: Profiles, privkey: Privkey?, event: NostrEvent, se
}

// Render translated note
let translated_blocks = event.get_blocks(content: translated_note)
let translated_blocks = parse_note_content(content: .content(translated_note, event.tags))
let artifacts = render_blocks(blocks: translated_blocks, profiles: profiles)

// and cache it
Expand Down
114 changes: 45 additions & 69 deletions damus/ContentParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,75 +7,56 @@

import Foundation

func tag_to_refid_ndb(_ tag: TagSequence) -> ReferencedId? {
guard tag.count >= 2 else { return nil }
enum NoteContent {
case note(NostrEvent)
case content(String, TagsSequence?)

let key = tag[0].string()
let ref_id = tag[1].string()

var relay_id: String? = nil
if tag.count >= 3 {
relay_id = tag[2].string()
init(note: NostrEvent, privkey: Privkey?) {
if note.known_kind == .dm {
self = .content(note.get_content(privkey), note.tags)
} else {
self = .note(note)
}
}

return ReferencedId(ref_id: ref_id, relay_id: relay_id, key: key)
}

func convert_mention_index_block_ndb(ind: Int, tags: TagsSequence) -> Block? {
if ind < 0 || (ind + 1 > tags.count) || tags[ind]!.count < 2 {
return .text("#[\(ind)]")
}

guard let tag = tags[ind], let fst = tag.first(where: { _ in true }) else {
return nil
}
func parsed_blocks_finish(bs: inout note_blocks, tags: TagsSequence?) -> Blocks {
var out: [Block] = []

guard let mention_type = parse_mention_type_ndb(fst) else {
return .text("#[\(ind)]")
}

guard let ref = tag_to_refid_ndb(tag) else {
return .text("#[\(ind)]")
}

return .mention(Mention(index: ind, type: mention_type, ref: ref))
}
var i = 0
while (i < bs.num_blocks) {
let block = bs.blocks[i]

if let converted = convert_block(block, tags: tags) {
out.append(converted)
}

func convert_block_ndb(_ b: block_t, tags: TagsSequence) -> Block? {
if b.type == BLOCK_MENTION_INDEX {
return convert_mention_index_block_ndb(ind: Int(b.block.mention_index), tags: tags)
i += 1
}

return convert_block(b, tags: [])
}
let words = Int(bs.words)
blocks_free(&bs)

return Blocks(words: words, blocks: out)

func parse_note_content_ndb(note: NdbNote) -> Blocks {
var out: [Block] = []
}

func parse_note_content(content: NoteContent) -> Blocks {
var bs = note_blocks()
bs.num_blocks = 0;

blocks_init(&bs)

damus_parse_content(&bs, note.content_raw)

var i = 0
while (i < bs.num_blocks) {
let block = bs.blocks[i]

if let converted = convert_block_ndb(block, tags: note.tags) {
out.append(converted)
switch content {
case .content(let s, let tags):
return s.withCString { cptr in
damus_parse_content(&bs, cptr)
return parsed_blocks_finish(bs: &bs, tags: tags)
}

i += 1
case .note(let note):
damus_parse_content(&bs, note.content_raw)
return parsed_blocks_finish(bs: &bs, tags: note.tags)
}

let words = Int(bs.words)
blocks_free(&bs)

return Blocks(words: words, blocks: out)
}

func interpret_event_refs_ndb(blocks: [Block], tags: TagsSequence) -> [EventRef] {
Expand All @@ -84,38 +65,37 @@ func interpret_event_refs_ndb(blocks: [Block], tags: TagsSequence) -> [EventRef]
}

/// build a set of indices for each event mention
let mention_indices = build_mention_indices(blocks, type: .event)
let mention_indices = build_mention_indices(blocks, type: .e)

/// simpler case with no mentions
if mention_indices.count == 0 {
let ev_refs = References.ids(tags: tags)
return interp_event_refs_without_mentions_ndb(ev_refs)
return interp_event_refs_without_mentions_ndb(tags.note.referenced_noterefs)
}

return interp_event_refs_with_mentions_ndb(tags: tags, mention_indices: mention_indices)
}

func interp_event_refs_without_mentions_ndb(_ ev_tags: LazyFilterSequence<References>) -> [EventRef] {
func interp_event_refs_without_mentions_ndb(_ ev_tags: References<NoteRef>) -> [EventRef] {

var count = 0
var evrefs: [EventRef] = []
var first: Bool = true
var first_ref: Reference? = nil
var first_ref: NoteRef? = nil

for ref in ev_tags {
if first {
first_ref = ref
evrefs.append(.thread_id(ref.to_referenced_id()))
evrefs.append(.thread_id(ref))
first = false
} else {

evrefs.append(.reply(ref.to_referenced_id()))
evrefs.append(.reply(ref))
}
count += 1
}

if let first_ref, count == 1 {
let r = first_ref.to_referenced_id()
let r = first_ref
return [.reply_to_root(r)]
}

Expand All @@ -124,19 +104,15 @@ func interp_event_refs_without_mentions_ndb(_ ev_tags: LazyFilterSequence<Refere

func interp_event_refs_with_mentions_ndb(tags: TagsSequence, mention_indices: Set<Int>) -> [EventRef] {
var mentions: [EventRef] = []
var ev_refs: [ReferencedId] = []
var ev_refs: [NoteRef] = []
var i: Int = 0

for tag in tags {
if tag.count >= 2,
tag[0].matches_char("e"),
let ref = tag_to_refid_ndb(tag)
{
if let note_id = NoteRef.from_tag(tag: tag) {
if mention_indices.contains(i) {
let mention = Mention(index: i, type: .event, ref: ref)
mentions.append(.mention(mention))
mentions.append(.mention(.noteref(note_id, index: i)))
} else {
ev_refs.append(ref)
ev_refs.append(note_id)
}
}
i += 1
Expand Down
Loading

0 comments on commit cebd1f4

Please sign in to comment.