From d825995ef4acbbbb9d03576e50a52a65b6a297a4 Mon Sep 17 00:00:00 2001 From: David Kaspar Date: Tue, 28 Jan 2025 11:39:46 +0100 Subject: [PATCH 1/2] Exclude FileHeaderEvent from note search results (direct note id search and free text) --- .../vitorpamplona/amethyst/model/LocalCache.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index b1e88fb1a..99ffbf264 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -1855,7 +1855,17 @@ object LocalCache { if (key != null) { val note = getNoteIfExists(key) - if (note != null) { + if ((note != null) && + !( + note.event is GenericRepostEvent || + note.event is RepostEvent || + note.event is CommunityPostApprovalEvent || + note.event is ReactionEvent || + note.event is LnZapEvent || + note.event is LnZapRequestEvent || + note.event is FileHeaderEvent + ) + ) { return listOfNotNull(note) } } @@ -1866,7 +1876,8 @@ object LocalCache { note.event is CommunityPostApprovalEvent || note.event is ReactionEvent || note.event is LnZapEvent || - note.event is LnZapRequestEvent + note.event is LnZapRequestEvent || + note.event is FileHeaderEvent ) { return@filter false } @@ -1897,7 +1908,8 @@ object LocalCache { addressable.event is CommunityPostApprovalEvent || addressable.event is ReactionEvent || addressable.event is LnZapEvent || - addressable.event is LnZapRequestEvent + addressable.event is LnZapRequestEvent || + addressable.event is FileHeaderEvent ) { return@filter false } From 1bd52f163f996964b237c5872cd1262ca09f8f72 Mon Sep 17 00:00:00 2001 From: David Kaspar Date: Tue, 28 Jan 2025 11:55:17 +0100 Subject: [PATCH 2/2] extract logical expression for which notes to exclude from search results --- .../amethyst/model/LocalCache.kt | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index 99ffbf264..be90a35c4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -1845,6 +1845,21 @@ object LocalCache { ) } + /** + * Will return true if supplied note is one of events to be excluded from + * search results. + */ + private fun excludeNoteEventFromSearchResults(note: Note): Boolean = + ( + note.event is GenericRepostEvent || + note.event is RepostEvent || + note.event is CommunityPostApprovalEvent || + note.event is ReactionEvent || + note.event is LnZapEvent || + note.event is LnZapRequestEvent || + note.event is FileHeaderEvent + ) + fun findNotesStartingWith( text: String, forAccount: Account, @@ -1855,30 +1870,13 @@ object LocalCache { if (key != null) { val note = getNoteIfExists(key) - if ((note != null) && - !( - note.event is GenericRepostEvent || - note.event is RepostEvent || - note.event is CommunityPostApprovalEvent || - note.event is ReactionEvent || - note.event is LnZapEvent || - note.event is LnZapRequestEvent || - note.event is FileHeaderEvent - ) - ) { + if ((note != null) && !excludeNoteEventFromSearchResults(note)) { return listOfNotNull(note) } } return notes.filter { _, note -> - if (note.event is GenericRepostEvent || - note.event is RepostEvent || - note.event is CommunityPostApprovalEvent || - note.event is ReactionEvent || - note.event is LnZapEvent || - note.event is LnZapRequestEvent || - note.event is FileHeaderEvent - ) { + if (excludeNoteEventFromSearchResults(note)) { return@filter false } @@ -1903,14 +1901,7 @@ object LocalCache { return@filter false } + addressables.filter { _, addressable -> - if (addressable.event is GenericRepostEvent || - addressable.event is RepostEvent || - addressable.event is CommunityPostApprovalEvent || - addressable.event is ReactionEvent || - addressable.event is LnZapEvent || - addressable.event is LnZapRequestEvent || - addressable.event is FileHeaderEvent - ) { + if (excludeNoteEventFromSearchResults(addressable)) { return@filter false }