diff --git a/ts/components/conversation/SessionMessagesList.tsx b/ts/components/conversation/SessionMessagesList.tsx index 1f6470edd..4b1c79bf4 100644 --- a/ts/components/conversation/SessionMessagesList.tsx +++ b/ts/components/conversation/SessionMessagesList.tsx @@ -2,7 +2,6 @@ import { useLayoutEffect, useState } from 'react'; import { useSelector } from 'react-redux'; import useKey from 'react-use/lib/useKey'; -import { PropsForDataExtractionNotification } from '../../models/messageType'; import { PropsForExpirationTimer, PropsForGroupUpdate } from '../../state/ducks/conversations'; import { getOldBottomMessageId, @@ -132,10 +131,8 @@ export const SessionMessagesList = (props: { } if (messageProps.message?.messageType === 'data-extraction') { - const msgProps = messageProps.message.props as PropsForDataExtractionNotification; - return [ - , + , ...componentToMerge, ]; } diff --git a/ts/components/conversation/message/message-item/DataExtractionNotification.tsx b/ts/components/conversation/message/message-item/DataExtractionNotification.tsx index bf58bed5f..405577814 100644 --- a/ts/components/conversation/message/message-item/DataExtractionNotification.tsx +++ b/ts/components/conversation/message/message-item/DataExtractionNotification.tsx @@ -1,12 +1,21 @@ -import { PropsForDataExtractionNotification } from '../../../../models/messageType'; -import { SignalService } from '../../../../protobuf'; import { ExpirableReadableMessage } from './ExpirableReadableMessage'; import { NotificationBubble } from './notification-bubble/NotificationBubble'; import { Localizer } from '../../../basic/Localizer'; +import { useMessageAuthor } from '../../../../state/selectors'; +import { useNicknameOrProfileNameOrShortenedPubkey } from '../../../../hooks/useParamSelector'; +import type { WithMessageId } from '../../../../session/types/with'; -export const DataExtractionNotification = (props: PropsForDataExtractionNotification) => { - const { name, type, source, messageId } = props; +export const DataExtractionNotification = (props: WithMessageId) => { + const { messageId } = props; + const author = useMessageAuthor(messageId); + const authorName = useNicknameOrProfileNameOrShortenedPubkey(author); + if (!author) { + return null; + } + + // Note: we only support one type of data extraction notification now (media saved). + // the screenshot support is entirely removed. return ( - + ); diff --git a/ts/models/message.ts b/ts/models/message.ts index c01f992e9..f34d28ca2 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -19,12 +19,10 @@ import { uploadQuoteThumbnailsToFileServer, } from '../session/utils'; import { - DataExtractionNotificationMsg, MessageAttributes, MessageAttributesOptionals, MessageGroupUpdate, MessageModelType, - PropsForDataExtractionNotification, fillMessageAttributesWithDefaults, } from './messageType'; @@ -222,7 +220,7 @@ export class MessageModel extends Backbone.Model { this.set(attributes); } - public isCommunityInvitation() { + private isCommunityInvitation() { return !!this.getCommunityInvitation(); } public getCommunityInvitation() { @@ -233,21 +231,16 @@ export class MessageModel extends Backbone.Model { return !!this.get('messageRequestResponse'); } - public isDataExtractionNotification() { - return !!this.getDataExtractionNotification(); - } - public getDataExtractionNotification() { - return this.get('dataExtractionNotification'); + private isDataExtractionNotification() { + // if set to {} this returns true + return !!this.get('dataExtractionNotification'); } - public isCallNotification() { - return !!this.getCallNotification(); - } - public getCallNotification() { - return this.get('callNotificationType'); + private isCallNotification() { + return !!this.get('callNotificationType'); } - public isInteractionNotification() { + private isInteractionNotification() { return !!this.getInteractionNotification(); } public getInteractionNotification() { @@ -306,17 +299,8 @@ export class MessageModel extends Backbone.Model { } if (this.isDataExtractionNotification()) { - const dataExtraction = this.get( - 'dataExtractionNotification' - ) as DataExtractionNotificationMsg; - if (dataExtraction.type === SignalService.DataExtractionNotification.Type.SCREENSHOT) { - return window.i18n.stripped('screenshotTaken', { - name: ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(dataExtraction.source), - }); - } - return window.i18n.stripped('attachmentsMediaSaved', { - name: ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(dataExtraction.source), + name: ConvoHub.use().getNicknameOrRealUsernameOrPlaceholder(this.get('source')), }); } if (this.isCallNotification()) { @@ -519,26 +503,8 @@ export class MessageModel extends Backbone.Model { }; } - private getPropsForDataExtractionNotification(): PropsForDataExtractionNotification | null { - if (!this.isDataExtractionNotification()) { - return null; - } - const dataExtractionNotification = this.getDataExtractionNotification(); - - if (!dataExtractionNotification) { - window.log.warn('dataExtractionNotification should not happen'); - return null; - } - - const contact = findAndFormatContact(dataExtractionNotification.source); - - return { - ...dataExtractionNotification, - name: contact.profileName || contact.name || dataExtractionNotification.source, - receivedAt: this.get('received_at'), - isUnread: this.isUnread(), - ...this.getPropsForExpiringMessage(), - }; + private getPropsForDataExtractionNotification(): boolean { + return !!this.isDataExtractionNotification(); } private getPropsForGroupUpdateMessage(): PropsForGroupUpdate | null { diff --git a/ts/models/messageType.ts b/ts/models/messageType.ts index e08aa9a01..2097560cf 100644 --- a/ts/models/messageType.ts +++ b/ts/models/messageType.ts @@ -127,12 +127,6 @@ export interface MessageAttributes { interactionNotification?: InteractionNotificationType; } -export interface DataExtractionNotificationMsg { - type: number; // screenshot or saving event, based on SignalService.DataExtractionNotification.Type - source: string; // the guy who made a screenshot - referencedAttachmentTimestamp: number; // the attachment timestamp he screenshot -} - export interface MessageRequestResponseMsg { source: string; isApproved: boolean; @@ -144,11 +138,13 @@ export enum MessageDirection { any = '%', } -export type PropsForDataExtractionNotification = DataExtractionNotificationMsg & { - name: string; - messageId: string; +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 PropsForDataExtractionNotification = DataExtractionNotificationMsg; + export type PropsForMessageRequestResponse = MessageRequestResponseMsg & { conversationId?: string; name?: string; @@ -196,11 +192,7 @@ export interface MessageAttributesOptionals { hasAttachments?: boolean; hasFileAttachments?: boolean; hasVisualMediaAttachments?: boolean; - dataExtractionNotification?: { - type: number; - source: string; - referencedAttachmentTimestamp: number; - }; + dataExtractionNotification?: DataExtractionNotificationMsg; messageRequestResponse?: { /** 1 means approved, 0 means unapproved. */ isApproved?: number; diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index 8e227327b..e5f10a8ed 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -913,15 +913,14 @@ export async function handleDataExtractionNotification({ envelope, expireUpdate, messageHash, - dataExtractionNotification, }: { envelope: EnvelopePlus; dataExtractionNotification: SignalService.DataExtractionNotification; expireUpdate: ReadyToDisappearMsgUpdate | undefined; messageHash: string; }): Promise { - // we currently don't care about the timestamp included in the field itself, just the timestamp of the envelope - const { type, timestamp: referencedAttachment } = dataExtractionNotification; + // 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); @@ -933,23 +932,20 @@ export async function handleDataExtractionNotification({ return; } - if (!type || !source || !timestamp) { + if (!source || !timestamp) { window?.log?.info('DataNotification pre check failed'); return; } const sentAtTimestamp = toNumber(timestamp); - const referencedAttachmentTimestamp = toNumber(referencedAttachment); let created = await convo.addSingleIncomingMessage({ source, messageHash, sent_at: sentAtTimestamp, dataExtractionNotification: { - type, - referencedAttachmentTimestamp, // currently unused - source, + // just set it to non empty object. We don't need anything else than this for now }, }); diff --git a/ts/session/messages/outgoing/controlMessage/DataExtractionNotificationMessage.ts b/ts/session/messages/outgoing/controlMessage/DataExtractionNotificationMessage.ts index c2cc384e4..600406ab7 100644 --- a/ts/session/messages/outgoing/controlMessage/DataExtractionNotificationMessage.ts +++ b/ts/session/messages/outgoing/controlMessage/DataExtractionNotificationMessage.ts @@ -20,7 +20,7 @@ export class DataExtractionNotificationMessage extends ExpirableMessage { constructor(params: DataExtractionNotificationMessageParams) { super(params); this.referencedAttachmentTimestamp = params.referencedAttachmentTimestamp; - // this does not make any sense + // this is unused. Probably on all platforms, but well. if (!this.referencedAttachmentTimestamp) { throw new Error('referencedAttachmentTimestamp must be set'); } diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 69a9f779b..751f4e164 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -151,7 +151,6 @@ export const getSortedMessagesTypesOfSelectedConversation = createSelector( ...common, message: { messageType: 'data-extraction', - props: { ...msg.propsForDataExtractionNotification }, }, }; } diff --git a/ts/state/selectors/messages.ts b/ts/state/selectors/messages.ts index 3add3e256..1fe44b3ce 100644 --- a/ts/state/selectors/messages.ts +++ b/ts/state/selectors/messages.ts @@ -203,3 +203,4 @@ export function useMessageCommunityInvitationFullUrl(messageId: string) { export function useMessageCommunityInvitationCommunityName(messageId: string) { return useMessagePropsByMessageId(messageId)?.propsForGroupInvitation?.serverName; } +