home: hide users and hashtags from home timeline when you unfollow

Add the ability to resubscribe to home filters so that it will be
updated when you follow and unfollow people

Changelog-Fixed: Hide users and hashtags from home timeline when you unfollow
This commit is contained in:
William Casarin
2023-07-13 11:06:07 -07:00
parent 122655bea3
commit 31fa63debf
2 changed files with 102 additions and 22 deletions

View File

@@ -396,11 +396,21 @@ struct ContentView: View {
}
.onReceive(handle_notify(.unfollow)) { notif in
guard let state = self.damus_state else { return }
handle_unfollow_notif(state: state, notif: notif)
guard let unfollow = handle_unfollow_notif(state: state, notif: notif) else { return }
}
.onReceive(handle_notify(.unfollowed)) { notif in
guard let state = self.damus_state else { return }
let unfollow = notif.object as! ReferencedId
home.resubscribe(.unfollowing(unfollow))
}
.onReceive(handle_notify(.follow)) { notif in
guard let state = self.damus_state else { return }
handle_follow_notif(state: state, notif: notif)
guard handle_follow_notif(state: state, notif: notif) else { return }
}
.onReceive(handle_notify(.followed)) { notif in
guard let state = self.damus_state else { return }
let follow = notif.object as! ReferencedId
home.resubscribe(.following)
}
.onReceive(handle_notify(.post)) { notif in
guard let state = self.damus_state,
@@ -875,16 +885,17 @@ func timeline_name(_ timeline: Timeline?) -> String {
}
}
func handle_unfollow(state: DamusState, unfollow: ReferencedId) {
@discardableResult
func handle_unfollow(state: DamusState, unfollow: ReferencedId) -> Bool {
guard let keypair = state.keypair.to_full() else {
return
return false
}
let old_contacts = state.contacts.event
guard let ev = unfollow_reference(postbox: state.postbox, our_contacts: old_contacts, keypair: keypair, unfollow: unfollow)
else {
return
return false
}
notify(.unfollowed, unfollow)
@@ -895,13 +906,20 @@ func handle_unfollow(state: DamusState, unfollow: ReferencedId) {
state.contacts.remove_friend(unfollow.ref_id)
state.user_search_cache.updateOwnContactsPetnames(id: state.pubkey, oldEvent: old_contacts, newEvent: ev)
}
return true
}
func handle_unfollow_notif(state: DamusState, notif: Notification) {
func handle_unfollow_notif(state: DamusState, notif: Notification) -> ReferencedId? {
let target = notif.object as! FollowTarget
let pk = target.pubkey
handle_unfollow(state: state, unfollow: .p(pk))
let ref = ReferencedId.p(pk)
if handle_unfollow(state: state, unfollow: ref) {
return ref
}
return nil
}
@discardableResult