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

View File

@@ -13,51 +13,14 @@ class Contacts {
private var friend_of_friends: Set<Pubkey> = Set()
/// Tracks which friends are friends of a given pubkey.
private var pubkey_to_our_friends = [Pubkey : Set<Pubkey>]()
private var muted: Set<MuteItem> = Set()
let our_pubkey: Pubkey
var event: NostrEvent?
var mutelist: NostrEvent?
init(our_pubkey: Pubkey) {
self.our_pubkey = our_pubkey
}
func is_muted(_ item: MuteItem) -> Bool {
return muted.contains(item)
}
func set_mutelist(_ ev: NostrEvent) {
let oldlist = self.mutelist
self.mutelist = ev
let old: Set<MuteItem> = oldlist?.mute_list ?? Set<MuteItem>()
let new: Set<MuteItem> = ev.mute_list ?? Set<MuteItem>()
let diff = old.symmetricDifference(new)
var new_mutes = Set<MuteItem>()
var new_unmutes = Set<MuteItem>()
for d in diff {
if new.contains(d) {
new_mutes.insert(d)
} else {
new_unmutes.insert(d)
}
}
// TODO: set local mutelist here
self.muted = ev.mute_list ?? Set<MuteItem>()
if new_mutes.count > 0 {
notify(.new_mutes(new_mutes))
}
if new_unmutes.count > 0 {
notify(.new_unmutes(new_unmutes))
}
}
func remove_friend(_ pubkey: Pubkey) {
friends.remove(pubkey)