From 5fd5db5a2d7c9e780c59461ac79769df0248875d Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 17 Jan 2025 09:41:13 +1100 Subject: [PATCH] chore: bring back the screenshot notification handling as it is not removed from all platforms yet --- .../DataExtractionNotification.tsx | 18 +++++++++++----- ts/models/message.ts | 21 ++++++++++++++----- ts/models/messageType.ts | 6 +++--- ts/receiver/contentMessage.ts | 4 ++-- ts/state/selectors/messages.ts | 13 ++++++++++++ 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/ts/components/conversation/message/message-item/DataExtractionNotification.tsx b/ts/components/conversation/message/message-item/DataExtractionNotification.tsx index 405577814..90cbef2b2 100644 --- a/ts/components/conversation/message/message-item/DataExtractionNotification.tsx +++ b/ts/components/conversation/message/message-item/DataExtractionNotification.tsx @@ -1,21 +1,22 @@ import { ExpirableReadableMessage } from './ExpirableReadableMessage'; import { NotificationBubble } from './notification-bubble/NotificationBubble'; import { Localizer } from '../../../basic/Localizer'; -import { useMessageAuthor } from '../../../../state/selectors'; +import { useMessageAuthor, useMessageDataExtractionType } from '../../../../state/selectors'; import { useNicknameOrProfileNameOrShortenedPubkey } from '../../../../hooks/useParamSelector'; import type { WithMessageId } from '../../../../session/types/with'; +import { SignalService } from '../../../../protobuf'; export const DataExtractionNotification = (props: WithMessageId) => { const { messageId } = props; const author = useMessageAuthor(messageId); const authorName = useNicknameOrProfileNameOrShortenedPubkey(author); - if (!author) { + const dataExtractionType = useMessageDataExtractionType(messageId); + + if (!author || !dataExtractionType) { return null; } - // Note: we only support one type of data extraction notification now (media saved). - // the screenshot support is entirely removed. return ( { isControlMessage={true} > - + ); diff --git a/ts/models/message.ts b/ts/models/message.ts index d8504492c..a396acf02 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -24,6 +24,7 @@ import { MessageGroupUpdate, MessageModelType, fillMessageAttributesWithDefaults, + type DataExtractionNotificationMsg, } from './messageType'; import { Data } from '../data/data'; @@ -229,7 +230,7 @@ export class MessageModel extends Backbone.Model { private isDataExtractionNotification() { // if set to {} this returns true - return !!this.get('dataExtractionNotification'); + return !isEmpty(this.get('dataExtractionNotification')); } private isCallNotification() { @@ -295,8 +296,14 @@ export class MessageModel extends Backbone.Model { } if (this.isDataExtractionNotification()) { - return window.i18n.stripped('attachmentsMediaSaved', { - name: ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(this.get('source')), + const dataExtraction = this.get( + 'dataExtractionNotification' + ) as DataExtractionNotificationMsg; + const authorName = ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(this.get('source')); + const isScreenshot = + dataExtraction.type === SignalService.DataExtractionNotification.Type.SCREENSHOT; + return window.i18n.stripped(isScreenshot ? 'screenshotTaken' : 'attachmentsMediaSaved', { + name: authorName, }); } if (this.isCallNotification()) { @@ -492,8 +499,12 @@ export class MessageModel extends Backbone.Model { }; } - private getPropsForDataExtractionNotification(): boolean { - return !!this.isDataExtractionNotification(); + private getPropsForDataExtractionNotification(): DataExtractionNotificationMsg | null { + const dataExtraction = this.get('dataExtractionNotification'); + if (!dataExtraction || !dataExtraction.type) { + return null; + } + return { type: dataExtraction.type }; } private getPropsForGroupUpdateMessage(): PropsForGroupUpdate | null { diff --git a/ts/models/messageType.ts b/ts/models/messageType.ts index 31bf981e1..eb562d89f 100644 --- a/ts/models/messageType.ts +++ b/ts/models/messageType.ts @@ -14,6 +14,7 @@ import { CallNotificationType, InteractionNotificationType, } from '../state/ducks/types'; +import type { SignalService } from '../protobuf'; export type MessageModelType = 'incoming' | 'outgoing'; @@ -138,9 +139,8 @@ export enum MessageDirection { any = '%', } -type DataExtractionNotificationMsg = { - // Note: we only support one type (media saved, screenshot is not supported at all anymore) - // Note: just keeping this an object in case we need to add details to it. +export type DataExtractionNotificationMsg = { + type: SignalService.DataExtractionNotification.Type; }; export type PropsForDataExtractionNotification = DataExtractionNotificationMsg; diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index 0a063f217..c84f40898 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -914,6 +914,7 @@ export async function handleDataExtractionNotification({ envelope, expireUpdate, messageHash, + dataExtractionNotification, }: { envelope: EnvelopePlus; dataExtractionNotification: SignalService.DataExtractionNotification; @@ -921,7 +922,6 @@ export async function handleDataExtractionNotification({ messageHash: string; }): Promise { // Note: we currently don't care about the timestamp included in the field itself, just the timestamp of the envelope - // Note: we only support one type of data extraction notification const { source, timestamp } = envelope; await IncomingMessageCache.removeFromCache(envelope); @@ -946,7 +946,7 @@ export async function handleDataExtractionNotification({ messageHash, sent_at: sentAtTimestamp, dataExtractionNotification: { - // just set it to non empty object. We don't need anything else than this for now + type: dataExtractionNotification.type, }, }); diff --git a/ts/state/selectors/messages.ts b/ts/state/selectors/messages.ts index 22778ee3d..4660220e3 100644 --- a/ts/state/selectors/messages.ts +++ b/ts/state/selectors/messages.ts @@ -217,6 +217,19 @@ export function useMessageCallNotificationType(messageId: string) { return useMessagePropsByMessageId(messageId)?.propsForCallNotification?.notificationType; } +/** + * ==================================================== + * Below are selectors for data extraction notification + * ==================================================== + */ + +/** + * Return the call notification type linked to the specified message + */ +export function useMessageDataExtractionType(messageId: string) { + return useMessagePropsByMessageId(messageId)?.propsForDataExtractionNotification?.type; +} + /** * ================================================ * Below are selectors for interaction notification