(add: boolean)
| 37 | // Adds or removes just this emoji on the cached copy, so undoing it |
| 38 | // keeps any other reaction made while this one was in flight. |
| 39 | const toggle = (add: boolean): string[] => { |
| 40 | const threadKey = dmThreadQueryKey(user, peer.id); |
| 41 | const cached = queryClient |
| 42 | .getQueryData<DmMessage[]>(threadKey) |
| 43 | ?.find(({ id }) => id === message.id); |
| 44 | const current = getOwnReactions(cached ?? message, user.id); |
| 45 | const emojis = add |
| 46 | ? Array.from(new Set([...current, emoji])) |
| 47 | : current.filter((value) => value !== emoji); |
| 48 | queryClient.setQueryData<DmMessage[]>( |
| 49 | threadKey, |
| 50 | (messages) => |
| 51 | messages && |
| 52 | applyReaction(messages, { |
| 53 | peerId: peer.id, |
| 54 | senderId: user.id, |
| 55 | messageId: message.id, |
| 56 | emojis, |
| 57 | }), |
| 58 | ); |
| 59 | |
| 60 | return emojis; |
| 61 | }; |
| 62 | |
| 63 | getDmTransport(user.id) |
| 64 | .react(peer, message.id, toggle(!isRemoving)) |
no test coverage detected