Handle new group chat log events (#10624)
This commit is contained in:
@@ -259,18 +259,26 @@ export function ListConvosProviderInner({
|
|||||||
queryClient.setQueriesData({queryKey: RQKEY('request')}, updateFn)
|
queryClient.setQueriesData({queryKey: RQKEY('request')}, updateFn)
|
||||||
}
|
}
|
||||||
} else if (ChatBskyConvoDefs.isLogReadMessage(log)) {
|
} else if (ChatBskyConvoDefs.isLogReadMessage(log)) {
|
||||||
const logRef: ChatBskyConvoDefs.LogReadMessage = log
|
|
||||||
queryClient.setQueriesData(
|
queryClient.setQueriesData(
|
||||||
{queryKey: [RQKEY_ROOT]},
|
{queryKey: [RQKEY_ROOT]},
|
||||||
(old?: ConvoListQueryData) =>
|
(old?: ConvoListQueryData) =>
|
||||||
optimisticUpdate(logRef.convoId, old, convo => ({
|
optimisticUpdate(log.convoId, old, convo => ({
|
||||||
...convo,
|
...convo,
|
||||||
unreadCount: 0,
|
unreadCount: 0,
|
||||||
rev: logRef.rev,
|
rev: log.rev,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
} else if (ChatBskyConvoDefs.isLogReadConvo(log)) {
|
||||||
|
queryClient.setQueriesData(
|
||||||
|
{queryKey: [RQKEY_ROOT]},
|
||||||
|
(old?: ConvoListQueryData) =>
|
||||||
|
optimisticUpdate(log.convoId, old, convo => ({
|
||||||
|
...convo,
|
||||||
|
unreadCount: 0,
|
||||||
|
rev: log.rev,
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
} else if (ChatBskyConvoDefs.isLogAcceptConvo(log)) {
|
} else if (ChatBskyConvoDefs.isLogAcceptConvo(log)) {
|
||||||
const logRef: ChatBskyConvoDefs.LogAcceptConvo = log
|
|
||||||
const requests = queryClient.getQueryData<ConvoListQueryData>(
|
const requests = queryClient.getQueryData<ConvoListQueryData>(
|
||||||
RQKEY('request'),
|
RQKEY('request'),
|
||||||
)
|
)
|
||||||
@@ -285,8 +293,7 @@ export function ListConvosProviderInner({
|
|||||||
}
|
}
|
||||||
queryClient.setQueryData(
|
queryClient.setQueryData(
|
||||||
RQKEY('request'),
|
RQKEY('request'),
|
||||||
(old?: ConvoListQueryData) =>
|
(old?: ConvoListQueryData) => optimisticDelete(log.convoId, old),
|
||||||
optimisticDelete(logRef.convoId, old),
|
|
||||||
)
|
)
|
||||||
queryClient.setQueriesData(
|
queryClient.setQueriesData(
|
||||||
{queryKey: RQKEY('accepted')},
|
{queryKey: RQKEY('accepted')},
|
||||||
@@ -313,67 +320,141 @@ export function ListConvosProviderInner({
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else if (ChatBskyConvoDefs.isLogMuteConvo(log)) {
|
} else if (ChatBskyConvoDefs.isLogMuteConvo(log)) {
|
||||||
const logRef: ChatBskyConvoDefs.LogMuteConvo = log
|
|
||||||
queryClient.setQueriesData(
|
queryClient.setQueriesData(
|
||||||
{queryKey: [RQKEY_ROOT]},
|
{queryKey: [RQKEY_ROOT]},
|
||||||
(old?: ConvoListQueryData) =>
|
(old?: ConvoListQueryData) =>
|
||||||
optimisticUpdate(logRef.convoId, old, convo => ({
|
optimisticUpdate(log.convoId, old, convo => ({
|
||||||
...convo,
|
...convo,
|
||||||
muted: true,
|
muted: true,
|
||||||
rev: logRef.rev,
|
rev: log.rev,
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
} else if (ChatBskyConvoDefs.isLogUnmuteConvo(log)) {
|
} else if (ChatBskyConvoDefs.isLogUnmuteConvo(log)) {
|
||||||
const logRef: ChatBskyConvoDefs.LogUnmuteConvo = log
|
|
||||||
queryClient.setQueriesData(
|
queryClient.setQueriesData(
|
||||||
{queryKey: [RQKEY_ROOT]},
|
{queryKey: [RQKEY_ROOT]},
|
||||||
(old?: ConvoListQueryData) =>
|
(old?: ConvoListQueryData) =>
|
||||||
optimisticUpdate(logRef.convoId, old, convo => ({
|
optimisticUpdate(log.convoId, old, convo => ({
|
||||||
...convo,
|
...convo,
|
||||||
muted: false,
|
muted: false,
|
||||||
rev: logRef.rev,
|
rev: log.rev,
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
} else if (ChatBskyConvoDefs.isLogAddReaction(log)) {
|
} else if (ChatBskyConvoDefs.isLogLockConvo(log)) {
|
||||||
const logRef: ChatBskyConvoDefs.LogAddReaction = log
|
|
||||||
queryClient.setQueriesData(
|
queryClient.setQueriesData(
|
||||||
{queryKey: [RQKEY_ROOT]},
|
{queryKey: [RQKEY_ROOT]},
|
||||||
(old?: ConvoListQueryData) =>
|
(old?: ConvoListQueryData) =>
|
||||||
optimisticUpdate(logRef.convoId, old, convo => ({
|
optimisticUpdate(log.convoId, old, convo => {
|
||||||
|
if (ChatBskyConvoDefs.isGroupConvo(convo.kind)) {
|
||||||
|
return {
|
||||||
|
...convo,
|
||||||
|
kind: {
|
||||||
|
...convo.kind,
|
||||||
|
lockStatus: 'locked',
|
||||||
|
},
|
||||||
|
rev: log.rev,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...convo,
|
||||||
|
rev: log.rev,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
} else if (ChatBskyConvoDefs.isLogUnlockConvo(log)) {
|
||||||
|
queryClient.setQueriesData(
|
||||||
|
{queryKey: [RQKEY_ROOT]},
|
||||||
|
(old?: ConvoListQueryData) =>
|
||||||
|
optimisticUpdate(log.convoId, old, convo => {
|
||||||
|
if (ChatBskyConvoDefs.isGroupConvo(convo.kind)) {
|
||||||
|
return {
|
||||||
|
...convo,
|
||||||
|
kind: {
|
||||||
|
...convo.kind,
|
||||||
|
lockStatus: 'unlocked',
|
||||||
|
},
|
||||||
|
rev: log.rev,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...convo,
|
||||||
|
rev: log.rev,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
} else if (ChatBskyConvoDefs.isLogLockConvoPermanently(log)) {
|
||||||
|
queryClient.setQueriesData(
|
||||||
|
{queryKey: [RQKEY_ROOT]},
|
||||||
|
(old?: ConvoListQueryData) =>
|
||||||
|
optimisticUpdate(log.convoId, old, convo => {
|
||||||
|
if (ChatBskyConvoDefs.isGroupConvo(convo.kind)) {
|
||||||
|
return {
|
||||||
|
...convo,
|
||||||
|
kind: {
|
||||||
|
...convo.kind,
|
||||||
|
lockStatus: 'locked-permanently',
|
||||||
|
},
|
||||||
|
rev: log.rev,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...convo,
|
||||||
|
rev: log.rev,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
} else if (
|
||||||
|
ChatBskyConvoDefs.isLogCreateJoinLink(log) ||
|
||||||
|
ChatBskyConvoDefs.isLogEditJoinLink(log) ||
|
||||||
|
ChatBskyConvoDefs.isLogEnableJoinLink(log) ||
|
||||||
|
ChatBskyConvoDefs.isLogDisableJoinLink(log)
|
||||||
|
) {
|
||||||
|
// Join link data not included in the log event, trigger refetch to get it
|
||||||
|
debouncedRefetch()
|
||||||
|
} else if (
|
||||||
|
ChatBskyConvoDefs.isLogIncomingJoinRequest(log) ||
|
||||||
|
ChatBskyConvoDefs.isLogApproveJoinRequest(log) ||
|
||||||
|
ChatBskyConvoDefs.isLogRejectJoinRequest(log) ||
|
||||||
|
ChatBskyConvoDefs.isLogOutgoingJoinRequest(log)
|
||||||
|
) {
|
||||||
|
// TODO Update join request count here when available. -dsb
|
||||||
|
} else if (ChatBskyConvoDefs.isLogAddReaction(log)) {
|
||||||
|
queryClient.setQueriesData(
|
||||||
|
{queryKey: [RQKEY_ROOT]},
|
||||||
|
(old?: ConvoListQueryData) =>
|
||||||
|
optimisticUpdate(log.convoId, old, convo => ({
|
||||||
...convo,
|
...convo,
|
||||||
lastReaction: {
|
lastReaction: {
|
||||||
$type: 'chat.bsky.convo.defs#messageAndReactionView',
|
$type: 'chat.bsky.convo.defs#messageAndReactionView',
|
||||||
reaction: logRef.reaction,
|
reaction: log.reaction,
|
||||||
message: logRef.message,
|
message: log.message,
|
||||||
},
|
},
|
||||||
rev: logRef.rev,
|
rev: log.rev,
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
} else if (ChatBskyConvoDefs.isLogRemoveReaction(log)) {
|
} else if (ChatBskyConvoDefs.isLogRemoveReaction(log)) {
|
||||||
const logRef: ChatBskyConvoDefs.LogRemoveReaction = log
|
|
||||||
queryClient.setQueriesData(
|
queryClient.setQueriesData(
|
||||||
{queryKey: [RQKEY_ROOT]},
|
{queryKey: [RQKEY_ROOT]},
|
||||||
(old?: ConvoListQueryData) =>
|
(old?: ConvoListQueryData) =>
|
||||||
optimisticUpdate(logRef.convoId, old, convo => {
|
optimisticUpdate(log.convoId, old, convo => {
|
||||||
if (
|
if (
|
||||||
// if the convo is the same
|
// if the convo is the same
|
||||||
logRef.convoId === convo.id &&
|
log.convoId === convo.id &&
|
||||||
ChatBskyConvoDefs.isMessageAndReactionView(
|
ChatBskyConvoDefs.isMessageAndReactionView(
|
||||||
convo.lastReaction,
|
convo.lastReaction,
|
||||||
) &&
|
) &&
|
||||||
ChatBskyConvoDefs.isMessageView(logRef.message) &&
|
ChatBskyConvoDefs.isMessageView(log.message) &&
|
||||||
// ...and the message is the same
|
// ...and the message is the same
|
||||||
convo.lastReaction.message.id === logRef.message.id &&
|
convo.lastReaction.message.id === log.message.id &&
|
||||||
// ...and the reaction is the same
|
// ...and the reaction is the same
|
||||||
convo.lastReaction.reaction.sender.did ===
|
convo.lastReaction.reaction.sender.did ===
|
||||||
logRef.reaction.sender.did &&
|
log.reaction.sender.did &&
|
||||||
convo.lastReaction.reaction.value === logRef.reaction.value
|
convo.lastReaction.reaction.value === log.reaction.value
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
...convo,
|
...convo,
|
||||||
// ...remove the reaction. hopefully they didn't react twice in a row!
|
// ...remove the reaction. hopefully they didn't react twice in a row!
|
||||||
lastReaction: undefined,
|
lastReaction: undefined,
|
||||||
rev: logRef.rev,
|
rev: log.rev,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return convo
|
return convo
|
||||||
|
|||||||
@@ -76,6 +76,35 @@ export function useListConvoMembersQuery({
|
|||||||
) {
|
) {
|
||||||
mutateList(list => list.filter(m => m.did !== data.member.did))
|
mutateList(list => list.filter(m => m.did !== data.member.did))
|
||||||
}
|
}
|
||||||
|
} else if (ChatBskyConvoDefs.isLogMemberJoin(log)) {
|
||||||
|
const data = log.message.data
|
||||||
|
if (
|
||||||
|
bsky.dangerousIsType<ChatBskyConvoDefs.SystemMessageDataMemberJoin>(
|
||||||
|
data,
|
||||||
|
ChatBskyConvoDefs.isSystemMessageDataMemberJoin,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
const newMember = log.relatedProfiles.find(
|
||||||
|
r => r.did === data.member.did,
|
||||||
|
)
|
||||||
|
if (newMember) {
|
||||||
|
mutateList(list =>
|
||||||
|
list.some(m => m.did === newMember.did)
|
||||||
|
? list
|
||||||
|
: list.concat(newMember),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (ChatBskyConvoDefs.isLogMemberLeave(log)) {
|
||||||
|
const data = log.message.data
|
||||||
|
if (
|
||||||
|
bsky.dangerousIsType<ChatBskyConvoDefs.SystemMessageDataMemberLeave>(
|
||||||
|
data,
|
||||||
|
ChatBskyConvoDefs.isSystemMessageDataMemberLeave,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
mutateList(list => list.filter(m => m.did !== data.member.did))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user