diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-04-02 01:45:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-01 15:45:29 -0700 |
commit | 5cb49314d009e02179eec3bfc759376d134e2673 (patch) | |
tree | e61fe05d9d512577c448fc31989ef5ed6cfb6bd3 /src | |
parent | 318b29d3fd7d22895ed6ba9a8daff6f296d7dd58 (diff) | |
download | voidsky-5cb49314d009e02179eec3bfc759376d134e2673.tar.zst |
[Reactions] Get reactions in chat list working again with new lexicon (#8093)
* get chat list reactions working again with new lexicon * fix weird android bug where background wasn't clipped
Diffstat (limited to 'src')
-rw-r--r-- | src/components/dms/EmojiReactionPicker.tsx | 6 | ||||
-rw-r--r-- | src/screens/Messages/components/ChatListItem.tsx | 76 | ||||
-rw-r--r-- | src/state/queries/messages/list-conversations.tsx | 63 |
3 files changed, 76 insertions, 69 deletions
diff --git a/src/components/dms/EmojiReactionPicker.tsx b/src/components/dms/EmojiReactionPicker.tsx index 477f45743..bf68b6e3a 100644 --- a/src/components/dms/EmojiReactionPicker.tsx +++ b/src/components/dms/EmojiReactionPicker.tsx @@ -95,9 +95,9 @@ export function EmojiReactionPicker({ ? t.palette.negative_100 : t.palette.primary_500, } - : alreadyReacted && { - backgroundColor: t.palette.primary_200, - }, + : alreadyReacted + ? {backgroundColor: t.palette.primary_200} + : t.atoms.bg, {height: 40, width: 40}, a.justify_center, a.align_center, diff --git a/src/screens/Messages/components/ChatListItem.tsx b/src/screens/Messages/components/ChatListItem.tsx index d8e4b975c..8a760e2c9 100644 --- a/src/screens/Messages/components/ChatListItem.tsx +++ b/src/screens/Messages/components/ChatListItem.tsx @@ -185,50 +185,61 @@ function ChatListItemReady({ lastMessageSentAt = convo.lastMessage.sentAt } if (ChatBskyConvoDefs.isDeletedMessageView(convo.lastMessage)) { + lastMessageSentAt = convo.lastMessage.sentAt + lastMessage = isDeletedAccount ? _(msg`Conversation deleted`) : _(msg`Message deleted`) } - if (ChatBskyConvoDefs.isMessageAndReactionView(convo.lastMessage)) { - const isFromMe = - convo.lastMessage.reaction.sender.did === currentAccount?.did - const lastMessageText = convo.lastMessage.message.text - const fallbackMessage = _( - msg({ - message: 'a message', - comment: `If last message does not contain text, fall back to "{user} reacted to {a message}"`, - }), - ) - - if (isFromMe) { - lastMessage = _( - msg`You reacted ${convo.lastMessage.reaction.value} to ${ - lastMessageText - ? `"${convo.lastMessage.message.text}"` - : fallbackMessage - }`, + + if (ChatBskyConvoDefs.isMessageAndReactionView(convo.lastReaction)) { + if ( + !lastMessageSentAt || + new Date(lastMessageSentAt) < + new Date(convo.lastReaction.reaction.createdAt) + ) { + const isFromMe = + convo.lastReaction.reaction.sender.did === currentAccount?.did + const lastMessageText = convo.lastReaction.message.text + const fallbackMessage = _( + msg({ + message: 'a message', + comment: `If last message does not contain text, fall back to "{user} reacted to {a message}"`, + }), ) - } else { - const senderDid = convo.lastMessage.reaction.sender.did - const sender = convo.members.find(member => member.did === senderDid) - if (sender) { + + if (isFromMe) { lastMessage = _( - msg`${sanitizeDisplayName( - sender.displayName || sender.handle, - )} reacted ${convo.lastMessage.reaction.value} to ${ + msg`You reacted ${convo.lastReaction.reaction.value} to ${ lastMessageText - ? `"${convo.lastMessage.message.text}"` + ? `"${convo.lastReaction.message.text}"` : fallbackMessage }`, ) } else { - lastMessage = _( - msg`Someone reacted ${convo.lastMessage.reaction.value} to ${ - lastMessageText - ? `"${convo.lastMessage.message.text}"` - : fallbackMessage - }`, + const senderDid = convo.lastReaction.reaction.sender.did + const sender = convo.members.find( + member => member.did === senderDid, ) + if (sender) { + lastMessage = _( + msg`${sanitizeDisplayName( + sender.displayName || sender.handle, + )} reacted ${convo.lastReaction.reaction.value} to ${ + lastMessageText + ? `"${convo.lastReaction.message.text}"` + : fallbackMessage + }`, + ) + } else { + lastMessage = _( + msg`Someone reacted ${convo.lastReaction.reaction.value} to ${ + lastMessageText + ? `"${convo.lastReaction.message.text}"` + : fallbackMessage + }`, + ) + } } } } @@ -241,6 +252,7 @@ function ChatListItemReady({ }, [ _, convo.lastMessage, + convo.lastReaction, currentAccount?.did, isDeletedAccount, convo.members, diff --git a/src/state/queries/messages/list-conversations.tsx b/src/state/queries/messages/list-conversations.tsx index 066c25e21..15da91071 100644 --- a/src/state/queries/messages/list-conversations.tsx +++ b/src/state/queries/messages/list-conversations.tsx @@ -317,7 +317,7 @@ export function ListConvosProviderInner({ (old?: ConvoListQueryData) => optimisticUpdate(logRef.convoId, old, convo => ({ ...convo, - lastMessage: { + lastReaction: { $type: 'chat.bsky.convo.defs#messageAndReactionView', reaction: logRef.reaction, message: logRef.message, @@ -326,41 +326,36 @@ export function ListConvosProviderInner({ })), ) } else if (ChatBskyConvoDefs.isLogRemoveReaction(log)) { - if (ChatBskyConvoDefs.isMessageView(log.message)) { - for (const [_queryKey, queryData] of queryClient.getQueriesData< - InfiniteData<ChatBskyConvoListConvos.OutputSchema> - >({ - queryKey: [RQKEY_ROOT], - })) { - if (!queryData?.pages) { - continue - } - - for (const page of queryData.pages) { - for (const convo of page.convos) { - if ( - // if the convo is the same - log.convoId === convo.id && - ChatBskyConvoDefs.isMessageAndReactionView( - convo.lastMessage, - ) && - ChatBskyConvoDefs.isMessageView( - convo.lastMessage.message, - ) && - // ...and the message is the same - convo.lastMessage.message.id === log.message.id && - // ...and the reaction is the same - convo.lastMessage.reaction.sender.did === - log.reaction.sender.did && - convo.lastMessage.reaction.value === log.reaction.value - ) { - // refetch, because we don't know what the last message is now - debouncedRefetch() + const logRef: ChatBskyConvoDefs.LogRemoveReaction = log + queryClient.setQueriesData( + {queryKey: [RQKEY_ROOT]}, + (old?: ConvoListQueryData) => + optimisticUpdate(logRef.convoId, old, convo => { + if ( + // if the convo is the same + logRef.convoId === convo.id && + ChatBskyConvoDefs.isMessageAndReactionView( + convo.lastReaction, + ) && + ChatBskyConvoDefs.isMessageView(logRef.message) && + // ...and the message is the same + convo.lastReaction.message.id === logRef.message.id && + // ...and the reaction is the same + convo.lastReaction.reaction.sender.did === + logRef.reaction.sender.did && + convo.lastReaction.reaction.value === logRef.reaction.value + ) { + return { + ...convo, + // ...remove the reaction. hopefully they didn't react twice in a row! + lastReaction: undefined, + rev: logRef.rev, } + } else { + return convo } - } - } - } + }), + ) } } }, |