Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫
Something went wrong. Try again.
5.1 kB · 143 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144import {type ChatBskyActorDefs, ChatBskyConvoDefs} from '@atproto/api'import {type MessageDescriptor} from '@lingui/core'import {msg} from '@lingui/core/macro'
import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name'import {ArrowBoxLeft_Stroke2_Corner0_Rounded as LeaveIcon} from '#/components/icons/ArrowBoxLeft'import {ArrowBoxRight_Stroke2_Corner3_Rounded as JoinIcon} from '#/components/icons/ArrowBoxRight'import { ChainLink_Stroke2_Corner0_Rounded as ChainLinkIcon, ChainLinkBroken_Stroke2_Corner0_Rounded as ChainLinkBrokenIcon,} from '#/components/icons/ChainLink'import {type Props as SVGIconProps} from '#/components/icons/common'import { Lock_Stroke2_Corner0_Rounded as LockIcon, Unlock_Stroke2_Corner2_Rounded as UnlockIcon,} from '#/components/icons/Lock'import {PencilLine_Stroke2_Corner0_Rounded as PencilIcon} from '#/components/icons/Pencil'
export type SystemMessageAction = | { kind: 'profile' profile: ChatBskyActorDefs.ProfileViewBasic displayName: string } | {kind: 'inviteLink'}
export type SystemMessageInfo = { message: MessageDescriptor Icon: React.ComponentType<SVGIconProps> action?: SystemMessageAction}
function getProfileAction( user: ChatBskyConvoDefs.SystemMessageReferredUser, relatedProfiles: Map<string, ChatBskyActorDefs.ProfileViewBasic>,): Extract<SystemMessageAction, {kind: 'profile'}> | null { const profile = relatedProfiles.get(user.did) if (!profile) return null return { kind: 'profile', profile, displayName: createSanitizedDisplayName(profile), }}
export function getSystemMessageInfo( data: ChatBskyConvoDefs.SystemMessageView['data'], relatedProfiles: Map<string, ChatBskyActorDefs.ProfileViewBasic>, opts = {short: false},): SystemMessageInfo | null { if (ChatBskyConvoDefs.isSystemMessageDataAddMember(data)) { const action = getProfileAction(data.member, relatedProfiles) return { Icon: JoinIcon, message: action ? opts.short ? msg`${action.displayName} was added` : msg`${action.displayName} was added to the group` : opts.short ? msg`Someone was added` : msg`Someone was added to the group`, action: action ?? undefined, } } else if (ChatBskyConvoDefs.isSystemMessageDataRemoveMember(data)) { const action = getProfileAction(data.member, relatedProfiles) return { Icon: LeaveIcon, message: action ? opts.short ? msg`${action.displayName} was removed` : msg`${action.displayName} was removed from the group` : opts.short ? msg`Someone was removed` : msg`Someone was removed from the group`, action: action ?? undefined, } } else if (ChatBskyConvoDefs.isSystemMessageDataMemberJoin(data)) { const action = getProfileAction(data.member, relatedProfiles) return { Icon: JoinIcon, message: action ? opts.short ? msg`${action.displayName} joined` : msg`${action.displayName} joined the group` : opts.short ? msg`Someone joined` : msg`Someone joined the group`, action: action ?? undefined, } } else if (ChatBskyConvoDefs.isSystemMessageDataMemberLeave(data)) { const action = getProfileAction(data.member, relatedProfiles) return { Icon: LeaveIcon, message: action ? opts.short ? msg`${action.displayName} left` : msg`${action.displayName} left the group` : opts.short ? msg`Someone left` : msg`Someone left the group`, action: action ?? undefined, } } else if (ChatBskyConvoDefs.isSystemMessageDataLockConvo(data)) { return {Icon: LockIcon, message: msg`Chat locked`} } else if (ChatBskyConvoDefs.isSystemMessageDataUnlockConvo(data)) { return {Icon: UnlockIcon, message: msg`Chat unlocked`} } else if (ChatBskyConvoDefs.isSystemMessageDataLockConvoPermanently(data)) { return {Icon: LockIcon, message: msg`Chat ended`} } else if (ChatBskyConvoDefs.isSystemMessageDataEditGroup(data)) { return { Icon: PencilIcon, message: data.newName && !opts.short ? msg`Chat title changed to ${data.newName}` : msg`Chat title changed`, } } else if (ChatBskyConvoDefs.isSystemMessageDataCreateJoinLink(data)) { return { Icon: ChainLinkIcon, message: msg`Invite link created`, action: {kind: 'inviteLink'}, } } else if (ChatBskyConvoDefs.isSystemMessageDataEditJoinLink(data)) { return { Icon: ChainLinkIcon, message: msg`Invite link edited`, action: {kind: 'inviteLink'}, } } else if (ChatBskyConvoDefs.isSystemMessageDataEnableJoinLink(data)) { return { Icon: ChainLinkIcon, message: msg`Invite link enabled`, action: {kind: 'inviteLink'}, } } else if (ChatBskyConvoDefs.isSystemMessageDataDisableJoinLink(data)) { return { Icon: ChainLinkBrokenIcon, message: msg`Invite link disabled`, action: {kind: 'inviteLink'}, } } return null}