diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 7a6d6fdcf9..b88780278a 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -3408,6 +3408,14 @@ "messageformat": "You donated for {recipient}", "description": "Shown to label a donation badge you've sent in notifications and the left pane" }, + "icu:message--pinned--preview--received": { + "messageformat": "{sender} pinned a message", + "description": "Shown to label pinned message notification in notifications and the left pane." + }, + "icu:message--pinned--preview--sent": { + "messageformat": "You pinned a message", + "description": "Shown to label pinned message notification in notifications and the left pane." + }, "icu:message--donation": { "messageformat": "Donation", "description": "Shown to label the donation badge you've redeemed on another device." diff --git a/ts/components/conversation/pinned-messages/PinnedMessagesBar.dom.tsx b/ts/components/conversation/pinned-messages/PinnedMessagesBar.dom.tsx index 0b4e4dd0d5..c5d4c18290 100644 --- a/ts/components/conversation/pinned-messages/PinnedMessagesBar.dom.tsx +++ b/ts/components/conversation/pinned-messages/PinnedMessagesBar.dom.tsx @@ -232,26 +232,27 @@ function TabTrigger(props: { ); } +type ContentProps = Readonly<{ + i18n: LocalizerType; + pin: Pin; + onPinGoTo: (messageId: string) => void; + onPinRemove: (messageId: string) => void; + onPinsShowAll: () => void; + canPinMessages: boolean; +}>; + const Content = forwardRef(function Content( - props: { - i18n: LocalizerType; - pin: Pin; - onPinGoTo: (messageId: string) => void; - onPinRemove: (messageId: string) => void; - onPinsShowAll: () => void; - canPinMessages: boolean; - }, - ref: ForwardedRef -): JSX.Element { - const { + { i18n, pin, onPinGoTo, onPinRemove, onPinsShowAll, + canPinMessages, ...forwardedProps - } = props; - + }: ContentProps, + ref: ForwardedRef +): JSX.Element { const handlePinGoTo = useCallback(() => { onPinGoTo(pin.message.id); }, [onPinGoTo, pin.message.id]); @@ -277,10 +278,10 @@ const Content = forwardRef(function Content( {thumbnailUrl != null && }

- +

- +

- {props.canPinMessages && ( + {canPinMessages && ( { const target = await getPinnedMessageTarget(targetMessageId); + const targetConversation = window.ConversationController.get( + target.conversationId + ); + strictAssert(targetConversation != null, 'Missing target conversation'); + await conversationJobQueue.add({ type: conversationQueueJobEnum.enum.PinMessage, ...target, @@ -152,6 +157,11 @@ function onPinnedMessageAdd( pinnedAt, }); + await targetConversation.addNotification('pinned-message-notification', { + pinnedMessageId: targetMessageId, + sourceServiceId: itemStorage.user.getCheckedAci(), + }); + dispatch(onPinnedMessagesChanged(target.conversationId)); }; } diff --git a/ts/util/getNotificationDataForMessage.preload.ts b/ts/util/getNotificationDataForMessage.preload.ts index 647208b635..60db3c5bd1 100644 --- a/ts/util/getNotificationDataForMessage.preload.ts +++ b/ts/util/getNotificationDataForMessage.preload.ts @@ -512,7 +512,21 @@ export function getNotificationDataForMessage( } if (isPinnedMessageNotification(attributes)) { - throw new Error('unimplemented'); + const fromContact = getAuthor(attributes); + const ourAci = itemStorage.user.getCheckedAci(); + + let text: string; + if (fromContact?.getAci() === ourAci) { + text = i18n('icu:message--pinned--preview--sent'); + } else { + const sender = fromContact?.getTitle() ?? i18n('icu:unknownContact'); + text = i18n('icu:message--pinned--preview--received', { sender }); + } + + return { + emoji: '📌', + text, + }; } const { poll } = attributes;