mute: integrate new MutelistManager

This patch is slightly large (I think still within the guidelines tho) ,
but also pretty straightforward. I thought for a while about how I could
split this up in a straightforward way, and I couldn’t come up with
anything without breaking intermediate builds.

- Deleted a lot of old/unnecessary code (ie. the Collection extension
  for MuteItem, since we’re now using the MutelistManager sets)

- Changed damus_state.contacts to damus_state.mutelist_manager for all
  mute list manager work

- Updated MutelistView to take advantage of new code (this is probably
  the largest change in this patch)

Lighting-Address: fishcharlie@strike.me
Signed-off-by: Charlie Fish <contact@charlie.fish>
Reviewed-by: William Casarin <jb55@jb55.com>
Link: 20240210163650.42884-4-contact@charlie.fish
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Charlie Fish
2024-02-10 09:36:48 -07:00
committed by William Casarin
parent a9baef7a21
commit 1d4d2b0204
24 changed files with 123 additions and 201 deletions
-61
View File
@@ -200,64 +200,3 @@ extension MuteItem: TagConvertible {
}
}
extension Collection where Element == MuteItem {
/// Check if an event is muted given a collection of ``MutedItem``.
///
/// - Parameter ev: The ``NostrEvent`` that you want to check the muted reason for.
/// - Returns: The ``MuteItem`` that matched the event. Or `nil` if the event is not muted.
func event_muted_reason(_ ev: NostrEvent) -> MuteItem? {
return self.first { muted_item in
switch muted_item {
case .user(let pubkey, let expiration_date):
return pubkey == ev.pubkey && !muted_item.is_expired()
case .hashtag(let hashtag, let expiration_date):
return ev.referenced_hashtags.contains(hashtag) && !muted_item.is_expired()
case .word(let word, let expiration_date):
return ev.content.lowercased().contains(word.lowercased()) && !muted_item.is_expired()
case .thread(let note_id, let expiration_date):
return ev.referenced_ids.contains(note_id) && !muted_item.is_expired()
}
}
}
var users: [Pubkey] {
return self.compactMap { muted_item in
if case .user(let pubkey, _) = muted_item,
!muted_item.is_expired() {
return pubkey
} else {
return nil
}
}
}
var hashtags: [Hashtag] {
return self.compactMap { muted_item in
if case .hashtag(let hashtag, _) = muted_item,
!muted_item.is_expired() {
return hashtag
} else {
return nil
}
}
}
var words: [String] {
return self.compactMap { muted_item in
if case .word(let str, _) = muted_item,
!muted_item.is_expired() {
return str
} else {
return nil
}
}
}
var threads: [NoteId] {
return self.compactMap { muted_item in
if case .thread(let note_id, _) = muted_item,
!muted_item.is_expired() {
return note_id
} else {
return nil
}
}
}
}