Bluesky app fork with some witchin' additions 馃挮
0
fork

Configure Feed

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

at main 89 lines 3.8 kB view raw
1import {type ChatBskyActorDefs, ChatBskyConvoDefs} from '@atproto/api' 2import {type MessageDescriptor} from '@lingui/core' 3import {msg} from '@lingui/core/macro' 4 5import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name' 6import {ArrowBoxLeft_Stroke2_Corner0_Rounded as LeaveIcon} from '#/components/icons/ArrowBoxLeft' 7import {ArrowBoxRight_Stroke2_Corner3_Rounded as JoinIcon} from '#/components/icons/ArrowBoxRight' 8import { 9 ChainLink_Stroke2_Corner0_Rounded as ChainLinkIcon, 10 ChainLinkBroken_Stroke2_Corner0_Rounded as ChainLinkBrokenIcon, 11} from '#/components/icons/ChainLink' 12import {type Props as SVGIconProps} from '#/components/icons/common' 13import { 14 Lock_Stroke2_Corner0_Rounded as LockIcon, 15 Unlock_Stroke2_Corner2_Rounded as UnlockIcon, 16} from '#/components/icons/Lock' 17import {PencilLine_Stroke2_Corner0_Rounded as PencilIcon} from '#/components/icons/Pencil' 18 19export type SystemMessageInfo = { 20 message: MessageDescriptor 21 Icon: React.ComponentType<SVGIconProps> 22} 23 24function getReferredDisplayName( 25 user: ChatBskyConvoDefs.SystemMessageReferredUser, 26 relatedProfiles: ChatBskyActorDefs.ProfileViewBasic[], 27): string | null { 28 const profile = relatedProfiles.find(p => p.did === user.did) 29 return profile ? createSanitizedDisplayName(profile) : null 30} 31 32export function getSystemMessageInfo( 33 data: ChatBskyConvoDefs.SystemMessageView['data'], 34 relatedProfiles: ChatBskyActorDefs.ProfileViewBasic[], 35): SystemMessageInfo | null { 36 if (ChatBskyConvoDefs.isSystemMessageDataAddMember(data)) { 37 const name = getReferredDisplayName(data.member, relatedProfiles) 38 return { 39 Icon: JoinIcon, 40 message: name 41 ? msg`${name} was added to the group` 42 : msg`Someone was added to the group`, 43 } 44 } else if (ChatBskyConvoDefs.isSystemMessageDataRemoveMember(data)) { 45 const name = getReferredDisplayName(data.member, relatedProfiles) 46 return { 47 Icon: LeaveIcon, 48 message: name 49 ? msg`${name} was removed from the group` 50 : msg`Someone was removed from the group`, 51 } 52 } else if (ChatBskyConvoDefs.isSystemMessageDataMemberJoin(data)) { 53 const name = getReferredDisplayName(data.member, relatedProfiles) 54 return { 55 Icon: JoinIcon, 56 message: name 57 ? msg`${name} joined the group` 58 : msg`Someone joined the group`, 59 } 60 } else if (ChatBskyConvoDefs.isSystemMessageDataMemberLeave(data)) { 61 const name = getReferredDisplayName(data.member, relatedProfiles) 62 return { 63 Icon: LeaveIcon, 64 message: name ? msg`${name} left the group` : msg`Someone left the group`, 65 } 66 } else if (ChatBskyConvoDefs.isSystemMessageDataLockConvo(data)) { 67 return {Icon: LockIcon, message: msg`Chat locked`} 68 } else if (ChatBskyConvoDefs.isSystemMessageDataUnlockConvo(data)) { 69 return {Icon: UnlockIcon, message: msg`Chat unlocked`} 70 } else if (ChatBskyConvoDefs.isSystemMessageDataLockConvoPermanently(data)) { 71 return {Icon: LockIcon, message: msg`Chat locked permanently`} 72 } else if (ChatBskyConvoDefs.isSystemMessageDataEditGroup(data)) { 73 return { 74 Icon: PencilIcon, 75 message: data.newName 76 ? msg`Chat title changed to ${data.newName}` 77 : msg`Chat title changed`, 78 } 79 } else if (ChatBskyConvoDefs.isSystemMessageDataCreateJoinLink(data)) { 80 return {Icon: ChainLinkIcon, message: msg`Invite link created`} 81 } else if (ChatBskyConvoDefs.isSystemMessageDataEditJoinLink(data)) { 82 return {Icon: ChainLinkIcon, message: msg`Invite link edited`} 83 } else if (ChatBskyConvoDefs.isSystemMessageDataEnableJoinLink(data)) { 84 return {Icon: ChainLinkIcon, message: msg`Invite link enabled`} 85 } else if (ChatBskyConvoDefs.isSystemMessageDataDisableJoinLink(data)) { 86 return {Icon: ChainLinkBrokenIcon, message: msg`Invite link disabled`} 87 } 88 return null 89}