chore: bring back the screenshot notification handling

as it is not removed from all platforms yet
pull/3281/head
Audric Ackermann 1 year ago
parent 7cf3bcbcf1
commit 5fd5db5a2d
No known key found for this signature in database

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

@ -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<MessageAttributes> {
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<MessageAttributes> {
}
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<MessageAttributes> {
};
}
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 {

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

@ -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<void> {
// 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,
},
});

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

Loading…
Cancel
Save