diff options
-rw-r--r-- | package.json | 2 | ||||
-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 | ||||
-rw-r--r-- | yarn.lock | 8 |
5 files changed, 81 insertions, 74 deletions
diff --git a/package.json b/package.json index b903b1410..db68a18c8 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "icons:optimize": "svgo -f ./assets/icons" }, "dependencies": { - "@atproto/api": "^0.14.14", + "@atproto/api": "^0.14.16", "@bitdrift/react-native": "^0.6.8", "@braintree/sanitize-url": "^6.0.2", "@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet", 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 } - } - } - } + }), + ) } } }, diff --git a/yarn.lock b/yarn.lock index 1e0a57607..7572c2fd2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -80,10 +80,10 @@ tlds "^1.234.0" zod "^3.23.8" -"@atproto/api@^0.14.14": - version "0.14.14" - resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.14.14.tgz#5d2d2e6156eab6ca0d463c114b4a3865275e9aac" - integrity sha512-ryawcnmazVSWYfq11ujPHauY77GfkM3mF0rZOkqENN2Ptnl6BZXJvpA0zLA/sQ5YBLcHXSEWg5Xdq+8i1l+8gA== +"@atproto/api@^0.14.16": + version "0.14.16" + resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.14.16.tgz#7b59eb83a27e906e0dc442d3de0f0d3869092b4a" + integrity sha512-xzUK3KVdp1TDJJ09Di2rvS/fisVctvMHO7Er0XhYviL3V4lxGQPNT3pHwbTbbb22QP7xH/d5ghCgfdIoS5Z8/A== dependencies: "@atproto/common-web" "^0.4.0" "@atproto/lexicon" "^0.4.9" |