Instant Feed Update on Mute or Moderation Action (#8463)
* Implemented #2406: Instant Feed Update on Mute or Moderation Action Posts from muted or blocked users are now removed immediately from the feed. This is achieved by extending the usePostShadow hook to check if the post author is muted or blocked and return POST_TOMBSTONE accordingly. A unit test was also added to validate the new logic. Co-authored-by: Pedro Macedo <pedrosantosmacedo@tecnico.ulisboa.pt> * remove useless tests --------- Co-authored-by: Pedro Macedo <pedrosantosmacedo@tecnico.ulisboa.pt> Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
committed by
GitHub
parent
1380c5ac67
commit
269105371b
Vendored
+10
-2
@@ -14,6 +14,7 @@ import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from '#/state/qu
|
|||||||
import {findAllPostsInQueryData as findAllPostsInQuoteQueryData} from '#/state/queries/post-quotes'
|
import {findAllPostsInQueryData as findAllPostsInQuoteQueryData} from '#/state/queries/post-quotes'
|
||||||
import {findAllPostsInQueryData as findAllPostsInThreadQueryData} from '#/state/queries/post-thread'
|
import {findAllPostsInQueryData as findAllPostsInThreadQueryData} from '#/state/queries/post-thread'
|
||||||
import {findAllPostsInQueryData as findAllPostsInSearchQueryData} from '#/state/queries/search-posts'
|
import {findAllPostsInQueryData as findAllPostsInSearchQueryData} from '#/state/queries/search-posts'
|
||||||
|
import {useProfileShadow} from './profile-shadow'
|
||||||
import {castAsShadow, type Shadow} from './types'
|
import {castAsShadow, type Shadow} from './types'
|
||||||
export type {Shadow} from './types'
|
export type {Shadow} from './types'
|
||||||
|
|
||||||
@@ -43,6 +44,10 @@ export function usePostShadow(
|
|||||||
setShadow(shadows.get(post))
|
setShadow(shadows.get(post))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const authorShadow = useProfileShadow(post.author)
|
||||||
|
const wasMuted = !!authorShadow.viewer?.muted
|
||||||
|
const wasBlocked = !!authorShadow.viewer?.blocking
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function onUpdate() {
|
function onUpdate() {
|
||||||
setShadow(shadows.get(post))
|
setShadow(shadows.get(post))
|
||||||
@@ -54,15 +59,18 @@ export function usePostShadow(
|
|||||||
}, [post, setShadow])
|
}, [post, setShadow])
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
|
if (wasMuted || wasBlocked) {
|
||||||
|
return POST_TOMBSTONE
|
||||||
|
}
|
||||||
if (shadow) {
|
if (shadow) {
|
||||||
return mergeShadow(post, shadow)
|
return mergeShadow(post, shadow)
|
||||||
} else {
|
} else {
|
||||||
return castAsShadow(post)
|
return castAsShadow(post)
|
||||||
}
|
}
|
||||||
}, [post, shadow])
|
}, [post, shadow, wasMuted, wasBlocked])
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeShadow(
|
export function mergeShadow(
|
||||||
post: AppBskyFeedDefs.PostView,
|
post: AppBskyFeedDefs.PostView,
|
||||||
shadow: Partial<PostShadow>,
|
shadow: Partial<PostShadow>,
|
||||||
): Shadow<AppBskyFeedDefs.PostView> | typeof POST_TOMBSTONE {
|
): Shadow<AppBskyFeedDefs.PostView> | typeof POST_TOMBSTONE {
|
||||||
|
|||||||
@@ -499,9 +499,10 @@ function useProfileBlockMutation() {
|
|||||||
{subject: did, createdAt: new Date().toISOString()},
|
{subject: did, createdAt: new Date().toISOString()},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onSuccess(_, {did}) {
|
onSuccess(data, {did}) {
|
||||||
queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()})
|
queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()})
|
||||||
resetProfilePostsQueries(queryClient, did, 1000)
|
resetProfilePostsQueries(queryClient, did, 1000)
|
||||||
|
updateProfileShadow(queryClient, did, {blockingUri: data.uri})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -523,6 +524,7 @@ function useProfileUnblockMutation() {
|
|||||||
},
|
},
|
||||||
onSuccess(_, {did}) {
|
onSuccess(_, {did}) {
|
||||||
resetProfilePostsQueries(queryClient, did, 1000)
|
resetProfilePostsQueries(queryClient, did, 1000)
|
||||||
|
updateProfileShadow(queryClient, did, {blockingUri: undefined})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user