From bb5026b2e96560826546f668f66c5a1f6fe0d4b1 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sun, 7 May 2023 21:33:42 -0500 Subject: [PATCH] Add list un/subscribe --- __e2e__/mock-server.ts | 24 ++++++++++++++++++++++- jest/test-pds.ts | 26 +++++++++++++++++++++++++ src/state/models/content/list.ts | 14 +++++++++++++ src/state/models/feeds/notifications.ts | 2 +- src/view/screens/ProfileList.tsx | 7 ++++--- 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/__e2e__/mock-server.ts b/__e2e__/mock-server.ts index 6744f697ff..6ddfe3ca02 100644 --- a/__e2e__/mock-server.ts +++ b/__e2e__/mock-server.ts @@ -91,6 +91,7 @@ async function main() { 'always-warn-profile', 'always-warn-posts', 'muted-account', + 'muted-by-list-account', ]) { await server.mocker.createUser(user) await server.mocker.follow('alice', user) @@ -258,11 +259,32 @@ async function main() { await server.mocker.createPost('muted-account', 'muted post') await server.mocker.createQuotePost( 'muted-account', - 'account quote post', + 'muted quote post', anchorPost, ) await server.mocker.createReply( 'muted-account', + 'muted reply', + anchorPost, + ) + + const list = await server.mocker.createMuteList( + 'alice', + 'Muted Users', + ) + await server.mocker.addToMuteList( + 'alice', + list, + server.mocker.users['muted-by-list-account'].did, + ) + await server.mocker.createPost('muted-by-list-account', 'muted post') + await server.mocker.createQuotePost( + 'muted-by-list-account', + 'account quote post', + anchorPost, + ) + await server.mocker.createReply( + 'muted-by-list-account', 'account reply', anchorPost, ) diff --git a/jest/test-pds.ts b/jest/test-pds.ts index 7f8d202323..9a1a287711 100644 --- a/jest/test-pds.ts +++ b/jest/test-pds.ts @@ -337,6 +337,32 @@ class Mocker { ]) .execute() } + + async createMuteList(user: string, name: string): Promise { + const res = await this.users[user]?.agent.app.bsky.graph.list.create( + {repo: this.users[user]?.did}, + { + purpose: 'app.bsky.graph.defs#modlist', + name, + createdAt: new Date().toISOString(), + }, + ) + await this.users[user]?.agent.app.bsky.graph.subscribeMuteList({ + list: res.uri, + }) + return res.uri + } + + async addToMuteList(owner: string, list: string, subject: string) { + await this.users[owner]?.agent.app.bsky.graph.listitem.create( + {repo: this.users[owner]?.did}, + { + list, + subject, + createdAt: new Date().toISOString(), + }, + ) + } } const checkAvailablePort = (port: number) => diff --git a/src/state/models/content/list.ts b/src/state/models/content/list.ts index 1e74e1c073..6a8bd0191c 100644 --- a/src/state/models/content/list.ts +++ b/src/state/models/content/list.ts @@ -194,6 +194,20 @@ export class ListModel { }) } + async subscribe() { + await this.rootStore.agent.app.bsky.graph.subscribeMuteList({ + list: this.list.uri, + }) + await this.refresh() + } + + async unsubscribe() { + await this.rootStore.agent.app.bsky.graph.unsubscribeMuteList({ + list: this.list.uri, + }) + await this.refresh() + } + /** * Attempt to load more again after a failure */ diff --git a/src/state/models/feeds/notifications.ts b/src/state/models/feeds/notifications.ts index 4b8f35b264..73424f03ed 100644 --- a/src/state/models/feeds/notifications.ts +++ b/src/state/models/feeds/notifications.ts @@ -111,7 +111,7 @@ export class NotificationsFeedItemModel { addedInfo?.profileLabels || [], ), isMuted: this.author.viewer?.muted || addedInfo?.isMuted || false, - mutedByList: this.author.viewer?.mutedByList || addedInfo.mutedByList, + mutedByList: this.author.viewer?.mutedByList || addedInfo?.mutedByList, isBlocking: !!this.author.viewer?.blocking || addedInfo?.isBlocking || false, isBlockedBy: diff --git a/src/view/screens/ProfileList.tsx b/src/view/screens/ProfileList.tsx index 1fe10b09ce..d4617a6084 100644 --- a/src/view/screens/ProfileList.tsx +++ b/src/view/screens/ProfileList.tsx @@ -43,11 +43,12 @@ export const ProfileListScreen = withAuthRequired( const onToggleSubscribed = React.useCallback(async () => { try { if (list.list?.viewer?.muted) { - await store.agent.app.bsky.graph.unsubscribeMuteList({list: list.uri}) - Toast.show('List unsubscribed') + await list.unsubscribe() + Toast.show('Unsubscribed from the mute list') } else { + await list.subscribe() await store.agent.app.bsky.graph.subscribeMuteList({list: list.uri}) - Toast.show('List subscribed') + Toast.show('Subscribed to the mute list') } } catch (err) { Toast.show(