Add list un/subscribe

This commit is contained in:
Paul Frazee
2023-05-07 21:33:42 -05:00
parent 1dc633b07c
commit bb5026b2e9
5 changed files with 68 additions and 5 deletions
+23 -1
View File
@@ -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,
)
+26
View File
@@ -337,6 +337,32 @@ class Mocker {
])
.execute()
}
async createMuteList(user: string, name: string): Promise<string> {
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) =>
+14
View File
@@ -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
*/
+1 -1
View File
@@ -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:
+4 -3
View File
@@ -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(