diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-03-28 16:34:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-28 07:34:07 -0700 |
commit | 152bc3c1ec74fadc687efe97361ae7b1b5bd73c3 (patch) | |
tree | 14ed8a0bc97a040cc24ea685dad56205a8beca30 /src/components/dms/util.ts | |
parent | 55a40c2436b68dea850e54a65c5dd197132c08e4 (diff) | |
download | voidsky-152bc3c1ec74fadc687efe97361ae7b1b5bd73c3.tar.zst |
[DMs] Reactions - link up API (attempt 2) (#8074)
* update package * wire up APIs * get reactions to display * allow removing emoji * handle limits better * listen to reactions in log * update convo list with reactions * tweaks to reaction display * Handle empty message fallback case * update package * shift reacts up by 2px --------- Co-authored-by: Eric Bailey <git@esb.lol>
Diffstat (limited to 'src/components/dms/util.ts')
-rw-r--r-- | src/components/dms/util.ts | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/components/dms/util.ts b/src/components/dms/util.ts index 7315f5fc9..2bcc9c3bd 100644 --- a/src/components/dms/util.ts +++ b/src/components/dms/util.ts @@ -1,4 +1,7 @@ -import * as bsky from '#/types/bsky' +import {type ChatBskyConvoDefs} from '@atproto/api' + +import {EMOJI_REACTION_LIMIT} from '#/lib/constants' +import type * as bsky from '#/types/bsky' export function canBeMessaged(profile: bsky.profile.AnyProfileView) { switch (profile.associated?.chat?.allowIncoming) { @@ -25,3 +28,29 @@ export function localDateString(date: Date) { // not padding with 0s because it's not necessary, it's just used for comparison return `${yyyy}-${mm}-${dd}` } + +export function hasAlreadyReacted( + message: ChatBskyConvoDefs.MessageView, + myDid: string | undefined, + emoji: string, +): boolean { + if (!message.reactions) { + return false + } + return !!message.reactions.find( + reaction => reaction.value === emoji && reaction.sender.did === myDid, + ) +} + +export function hasReachedReactionLimit( + message: ChatBskyConvoDefs.MessageView, + myDid: string | undefined, +): boolean { + if (!message.reactions) { + return false + } + const myReactions = message.reactions.filter( + reaction => reaction.sender.did === myDid, + ) + return myReactions.length >= EMOJI_REACTION_LIMIT +} |