Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[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

authored by

Samuel Newman and committed by
GitHub
5cb49314 318b29d3

+80 -73
+1 -1
package.json
··· 58 58 "icons:optimize": "svgo -f ./assets/icons" 59 59 }, 60 60 "dependencies": { 61 - "@atproto/api": "^0.14.14", 61 + "@atproto/api": "^0.14.16", 62 62 "@bitdrift/react-native": "^0.6.8", 63 63 "@braintree/sanitize-url": "^6.0.2", 64 64 "@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet",
+3 -3
src/components/dms/EmojiReactionPicker.tsx
··· 95 95 ? t.palette.negative_100 96 96 : t.palette.primary_500, 97 97 } 98 - : alreadyReacted && { 99 - backgroundColor: t.palette.primary_200, 100 - }, 98 + : alreadyReacted 99 + ? {backgroundColor: t.palette.primary_200} 100 + : t.atoms.bg, 101 101 {height: 40, width: 40}, 102 102 a.justify_center, 103 103 a.align_center,
+43 -31
src/screens/Messages/components/ChatListItem.tsx
··· 185 185 lastMessageSentAt = convo.lastMessage.sentAt 186 186 } 187 187 if (ChatBskyConvoDefs.isDeletedMessageView(convo.lastMessage)) { 188 + lastMessageSentAt = convo.lastMessage.sentAt 189 + 188 190 lastMessage = isDeletedAccount 189 191 ? _(msg`Conversation deleted`) 190 192 : _(msg`Message deleted`) 191 193 } 192 - if (ChatBskyConvoDefs.isMessageAndReactionView(convo.lastMessage)) { 193 - const isFromMe = 194 - convo.lastMessage.reaction.sender.did === currentAccount?.did 195 - const lastMessageText = convo.lastMessage.message.text 196 - const fallbackMessage = _( 197 - msg({ 198 - message: 'a message', 199 - comment: `If last message does not contain text, fall back to "{user} reacted to {a message}"`, 200 - }), 201 - ) 202 194 203 - if (isFromMe) { 204 - lastMessage = _( 205 - msg`You reacted ${convo.lastMessage.reaction.value} to ${ 206 - lastMessageText 207 - ? `"${convo.lastMessage.message.text}"` 208 - : fallbackMessage 209 - }`, 195 + if (ChatBskyConvoDefs.isMessageAndReactionView(convo.lastReaction)) { 196 + if ( 197 + !lastMessageSentAt || 198 + new Date(lastMessageSentAt) < 199 + new Date(convo.lastReaction.reaction.createdAt) 200 + ) { 201 + const isFromMe = 202 + convo.lastReaction.reaction.sender.did === currentAccount?.did 203 + const lastMessageText = convo.lastReaction.message.text 204 + const fallbackMessage = _( 205 + msg({ 206 + message: 'a message', 207 + comment: `If last message does not contain text, fall back to "{user} reacted to {a message}"`, 208 + }), 210 209 ) 211 - } else { 212 - const senderDid = convo.lastMessage.reaction.sender.did 213 - const sender = convo.members.find(member => member.did === senderDid) 214 - if (sender) { 210 + 211 + if (isFromMe) { 215 212 lastMessage = _( 216 - msg`${sanitizeDisplayName( 217 - sender.displayName || sender.handle, 218 - )} reacted ${convo.lastMessage.reaction.value} to ${ 213 + msg`You reacted ${convo.lastReaction.reaction.value} to ${ 219 214 lastMessageText 220 - ? `"${convo.lastMessage.message.text}"` 215 + ? `"${convo.lastReaction.message.text}"` 221 216 : fallbackMessage 222 217 }`, 223 218 ) 224 219 } else { 225 - lastMessage = _( 226 - msg`Someone reacted ${convo.lastMessage.reaction.value} to ${ 227 - lastMessageText 228 - ? `"${convo.lastMessage.message.text}"` 229 - : fallbackMessage 230 - }`, 220 + const senderDid = convo.lastReaction.reaction.sender.did 221 + const sender = convo.members.find( 222 + member => member.did === senderDid, 231 223 ) 224 + if (sender) { 225 + lastMessage = _( 226 + msg`${sanitizeDisplayName( 227 + sender.displayName || sender.handle, 228 + )} reacted ${convo.lastReaction.reaction.value} to ${ 229 + lastMessageText 230 + ? `"${convo.lastReaction.message.text}"` 231 + : fallbackMessage 232 + }`, 233 + ) 234 + } else { 235 + lastMessage = _( 236 + msg`Someone reacted ${convo.lastReaction.reaction.value} to ${ 237 + lastMessageText 238 + ? `"${convo.lastReaction.message.text}"` 239 + : fallbackMessage 240 + }`, 241 + ) 242 + } 232 243 } 233 244 } 234 245 } ··· 241 252 }, [ 242 253 _, 243 254 convo.lastMessage, 255 + convo.lastReaction, 244 256 currentAccount?.did, 245 257 isDeletedAccount, 246 258 convo.members,
+29 -34
src/state/queries/messages/list-conversations.tsx
··· 317 317 (old?: ConvoListQueryData) => 318 318 optimisticUpdate(logRef.convoId, old, convo => ({ 319 319 ...convo, 320 - lastMessage: { 320 + lastReaction: { 321 321 $type: 'chat.bsky.convo.defs#messageAndReactionView', 322 322 reaction: logRef.reaction, 323 323 message: logRef.message, ··· 326 326 })), 327 327 ) 328 328 } else if (ChatBskyConvoDefs.isLogRemoveReaction(log)) { 329 - if (ChatBskyConvoDefs.isMessageView(log.message)) { 330 - for (const [_queryKey, queryData] of queryClient.getQueriesData< 331 - InfiniteData<ChatBskyConvoListConvos.OutputSchema> 332 - >({ 333 - queryKey: [RQKEY_ROOT], 334 - })) { 335 - if (!queryData?.pages) { 336 - continue 337 - } 338 - 339 - for (const page of queryData.pages) { 340 - for (const convo of page.convos) { 341 - if ( 342 - // if the convo is the same 343 - log.convoId === convo.id && 344 - ChatBskyConvoDefs.isMessageAndReactionView( 345 - convo.lastMessage, 346 - ) && 347 - ChatBskyConvoDefs.isMessageView( 348 - convo.lastMessage.message, 349 - ) && 350 - // ...and the message is the same 351 - convo.lastMessage.message.id === log.message.id && 352 - // ...and the reaction is the same 353 - convo.lastMessage.reaction.sender.did === 354 - log.reaction.sender.did && 355 - convo.lastMessage.reaction.value === log.reaction.value 356 - ) { 357 - // refetch, because we don't know what the last message is now 358 - debouncedRefetch() 329 + const logRef: ChatBskyConvoDefs.LogRemoveReaction = log 330 + queryClient.setQueriesData( 331 + {queryKey: [RQKEY_ROOT]}, 332 + (old?: ConvoListQueryData) => 333 + optimisticUpdate(logRef.convoId, old, convo => { 334 + if ( 335 + // if the convo is the same 336 + logRef.convoId === convo.id && 337 + ChatBskyConvoDefs.isMessageAndReactionView( 338 + convo.lastReaction, 339 + ) && 340 + ChatBskyConvoDefs.isMessageView(logRef.message) && 341 + // ...and the message is the same 342 + convo.lastReaction.message.id === logRef.message.id && 343 + // ...and the reaction is the same 344 + convo.lastReaction.reaction.sender.did === 345 + logRef.reaction.sender.did && 346 + convo.lastReaction.reaction.value === logRef.reaction.value 347 + ) { 348 + return { 349 + ...convo, 350 + // ...remove the reaction. hopefully they didn't react twice in a row! 351 + lastReaction: undefined, 352 + rev: logRef.rev, 359 353 } 354 + } else { 355 + return convo 360 356 } 361 - } 362 - } 363 - } 357 + }), 358 + ) 364 359 } 365 360 } 366 361 },
+4 -4
yarn.lock
··· 80 80 tlds "^1.234.0" 81 81 zod "^3.23.8" 82 82 83 - "@atproto/api@^0.14.14": 84 - version "0.14.14" 85 - resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.14.14.tgz#5d2d2e6156eab6ca0d463c114b4a3865275e9aac" 86 - integrity sha512-ryawcnmazVSWYfq11ujPHauY77GfkM3mF0rZOkqENN2Ptnl6BZXJvpA0zLA/sQ5YBLcHXSEWg5Xdq+8i1l+8gA== 83 + "@atproto/api@^0.14.16": 84 + version "0.14.16" 85 + resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.14.16.tgz#7b59eb83a27e906e0dc442d3de0f0d3869092b4a" 86 + integrity sha512-xzUK3KVdp1TDJJ09Di2rvS/fisVctvMHO7Er0XhYviL3V4lxGQPNT3pHwbTbbb22QP7xH/d5ghCgfdIoS5Z8/A== 87 87 dependencies: 88 88 "@atproto/common-web" "^0.4.0" 89 89 "@atproto/lexicon" "^0.4.9"