Ensure mute state stays in sync after mutation (#10067)
This commit is contained in:
@@ -850,6 +850,16 @@ export class Convo {
|
||||
this.commit()
|
||||
}
|
||||
|
||||
updateMuted(muted: boolean) {
|
||||
if (this.convo) {
|
||||
this.convo = {
|
||||
...this.convo,
|
||||
muted,
|
||||
}
|
||||
}
|
||||
this.commit()
|
||||
}
|
||||
|
||||
async processPendingMessages() {
|
||||
logger.debug(
|
||||
`processing messages (${this.pendingMessages.size} remaining)`,
|
||||
|
||||
@@ -119,5 +119,20 @@ export function ConvoProvider({
|
||||
})
|
||||
}, [convo, queryClient])
|
||||
|
||||
useEffect(() => {
|
||||
const [root, id] = getConvoKey(convoId)
|
||||
return queryClient.getQueryCache().subscribe(event => {
|
||||
const queryKey = event.query.queryKey as string[]
|
||||
if (queryKey[0] === root && queryKey[1] === id) {
|
||||
const data = event.query.state.data as
|
||||
| ChatBskyConvoDefs.ConvoView
|
||||
| undefined
|
||||
if (data && convo.convo && data.muted !== convo.convo.muted) {
|
||||
convo.updateMuted(data.muted)
|
||||
}
|
||||
}
|
||||
})
|
||||
}, [convo, convoId, queryClient])
|
||||
|
||||
return <ChatContext.Provider value={service}>{children}</ChatContext.Provider>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user