diff options
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 +} |