chore: cleanup data extraction notification

pull/3281/head
Audric Ackermann 4 months ago
parent 3c0f9fe14e
commit 7570bc6ba7
No known key found for this signature in database

@ -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 [
<DataExtractionNotification key={messageId} {...msgProps} />,
<DataExtractionNotification key={messageId} messageId={messageId} />,
...componentToMerge,
];
}

@ -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 (
<ExpirableReadableMessage
messageId={messageId}
@ -15,14 +24,7 @@ export const DataExtractionNotification = (props: PropsForDataExtractionNotifica
isControlMessage={true}
>
<NotificationBubble iconType="save">
<Localizer
token={
type === SignalService.DataExtractionNotification.Type.MEDIA_SAVED
? 'attachmentsMediaSaved'
: 'screenshotTaken'
}
args={{ name: name || source }}
/>
<Localizer token={'attachmentsMediaSaved'} args={{ name: authorName }} />
</NotificationBubble>
</ExpirableReadableMessage>
);

@ -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<MessageAttributes> {
this.set(attributes);
}
public isCommunityInvitation() {
private isCommunityInvitation() {
return !!this.getCommunityInvitation();
}
public getCommunityInvitation() {
@ -233,21 +231,16 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
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<MessageAttributes> {
}
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<MessageAttributes> {
};
}
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 {

@ -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;

@ -913,15 +913,14 @@ export async function handleDataExtractionNotification({
envelope,
expireUpdate,
messageHash,
dataExtractionNotification,
}: {
envelope: EnvelopePlus;
dataExtractionNotification: SignalService.DataExtractionNotification;
expireUpdate: ReadyToDisappearMsgUpdate | undefined;
messageHash: string;
}): Promise<void> {
// 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
},
});

@ -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');
}

@ -151,7 +151,6 @@ export const getSortedMessagesTypesOfSelectedConversation = createSelector(
...common,
message: {
messageType: 'data-extraction',
props: { ...msg.propsForDataExtractionNotification },
},
};
}

@ -203,3 +203,4 @@ export function useMessageCommunityInvitationFullUrl(messageId: string) {
export function useMessageCommunityInvitationCommunityName(messageId: string) {
return useMessagePropsByMessageId(messageId)?.propsForGroupInvitation?.serverName;
}

Loading…
Cancel
Save