Display join requests on chat list (#10679)
This commit is contained in:
@@ -48,7 +48,7 @@ export function MembersAndRequests({
|
|||||||
? l({
|
? l({
|
||||||
message: `${requestCount}+ requests`,
|
message: `${requestCount}+ requests`,
|
||||||
comment:
|
comment:
|
||||||
'Displayed when there are more than 50 requests to join a group chat',
|
'Displayed when there are more than 20 requests to join a group chat',
|
||||||
})
|
})
|
||||||
: l({
|
: l({
|
||||||
message: plural(requestCount, {
|
message: plural(requestCount, {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
type ModerationDecision,
|
type ModerationDecision,
|
||||||
type ModerationOpts,
|
type ModerationOpts,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
|
import {plural} from '@lingui/core/macro'
|
||||||
import {useLingui} from '@lingui/react/macro'
|
import {useLingui} from '@lingui/react/macro'
|
||||||
import {useQueryClient} from '@tanstack/react-query'
|
import {useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
@@ -213,6 +214,20 @@ function GroupChatItem({
|
|||||||
primaryProfileModeration={moderation}
|
primaryProfileModeration={moderation}
|
||||||
isBlockedAccount={false}
|
isBlockedAccount={false}
|
||||||
isDeletedAccount={false}
|
isDeletedAccount={false}
|
||||||
|
subtitle={
|
||||||
|
convo.details.joinRequestCount
|
||||||
|
? convo.details.joinRequestCount > 20
|
||||||
|
? l({
|
||||||
|
message: '20+ new join requests',
|
||||||
|
context:
|
||||||
|
'Displayed when there are more than 20 requests to join a group chat',
|
||||||
|
})
|
||||||
|
: plural(convo.details.joinRequestCount, {
|
||||||
|
one: '# new join request',
|
||||||
|
other: '# new join requests',
|
||||||
|
})
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
showProfileBadges={false}
|
showProfileBadges={false}
|
||||||
selected={selected}
|
selected={selected}
|
||||||
showMenu={showMenu}>
|
showMenu={showMenu}>
|
||||||
|
|||||||
@@ -489,12 +489,22 @@ export function ListConvosProviderInner({
|
|||||||
// Join link data not included in the log event, trigger refetch to get it
|
// Join link data not included in the log event, trigger refetch to get it
|
||||||
debouncedRefetch()
|
debouncedRefetch()
|
||||||
} else if (
|
} else if (
|
||||||
ChatBskyConvoDefs.isLogIncomingJoinRequest(log) ||
|
|
||||||
ChatBskyConvoDefs.isLogApproveJoinRequest(log) ||
|
ChatBskyConvoDefs.isLogApproveJoinRequest(log) ||
|
||||||
ChatBskyConvoDefs.isLogRejectJoinRequest(log) ||
|
ChatBskyConvoDefs.isLogRejectJoinRequest(log)
|
||||||
ChatBskyConvoDefs.isLogOutgoingJoinRequest(log)
|
|
||||||
) {
|
) {
|
||||||
// TODO Update join request count here when available. -dsb
|
queryClient.setQueriesData(
|
||||||
|
{queryKey: [RQKEY_ROOT]},
|
||||||
|
(old?: ConvoListQueryData) =>
|
||||||
|
updateGroupConvoJoinRequestCount(log, old, -1),
|
||||||
|
)
|
||||||
|
} else if (ChatBskyConvoDefs.isLogIncomingJoinRequest(log)) {
|
||||||
|
queryClient.setQueriesData(
|
||||||
|
{queryKey: [RQKEY_ROOT]},
|
||||||
|
(old?: ConvoListQueryData) =>
|
||||||
|
updateGroupConvoJoinRequestCount(log, old, 1),
|
||||||
|
)
|
||||||
|
} else if (ChatBskyConvoDefs.isLogOutgoingJoinRequest(log)) {
|
||||||
|
// Viewer isn't in the chat yet, no need to do anything
|
||||||
} else if (ChatBskyConvoDefs.isLogAddReaction(log)) {
|
} else if (ChatBskyConvoDefs.isLogAddReaction(log)) {
|
||||||
queryClient.setQueriesData(
|
queryClient.setQueriesData(
|
||||||
{queryKey: [RQKEY_ROOT]},
|
{queryKey: [RQKEY_ROOT]},
|
||||||
@@ -762,6 +772,29 @@ function optimisticUpdate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateGroupConvoJoinRequestCount(
|
||||||
|
log: {convoId: string; rev: string},
|
||||||
|
old: ConvoListQueryData | undefined,
|
||||||
|
delta: 1 | -1,
|
||||||
|
) {
|
||||||
|
return optimisticUpdate(log.convoId, old, convo => {
|
||||||
|
// Join requests are only meaningful for group convos.
|
||||||
|
if (!ChatBskyConvoDefs.isGroupConvo(convo.kind)) {
|
||||||
|
return {...convo, rev: log.rev}
|
||||||
|
}
|
||||||
|
const current = convo.kind.joinRequestCount ?? 0
|
||||||
|
const next = Math.max(0, current + delta)
|
||||||
|
return {
|
||||||
|
...convo,
|
||||||
|
kind: {
|
||||||
|
...convo.kind,
|
||||||
|
joinRequestCount: next === 0 ? undefined : next,
|
||||||
|
},
|
||||||
|
rev: log.rev,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function removeMemberFromConvoView(
|
function removeMemberFromConvoView(
|
||||||
convo: ChatBskyConvoDefs.ConvoView,
|
convo: ChatBskyConvoDefs.ConvoView,
|
||||||
did: string,
|
did: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user