Merge pull request #1672 from Bilb/data-extraction-notification
Data extraction notificationpull/1682/head
commit
5fc0849395
@ -0,0 +1,39 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useTheme } from 'styled-components';
|
||||||
|
import { DataExtractionNotificationProps } from '../../models/messageType';
|
||||||
|
import { SignalService } from '../../protobuf';
|
||||||
|
import { Flex } from '../basic/Flex';
|
||||||
|
import { SessionIcon, SessionIconSize, SessionIconType } from '../session/icon';
|
||||||
|
import { SpacerXS, Text } from '../basic/Text';
|
||||||
|
|
||||||
|
type Props = DataExtractionNotificationProps;
|
||||||
|
|
||||||
|
export const DataExtractionNotification = (props: Props) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { name, type, source } = props;
|
||||||
|
|
||||||
|
let contentText: string;
|
||||||
|
if (type === SignalService.DataExtractionNotification.Type.MEDIA_SAVED) {
|
||||||
|
contentText = window.i18n('savedTheFile', name || source);
|
||||||
|
} else {
|
||||||
|
contentText = window.i18n('tookAScreenshot', name || source);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex
|
||||||
|
container={true}
|
||||||
|
flexDirection="column"
|
||||||
|
alignItems="center"
|
||||||
|
margin={theme.common.margins.sm}
|
||||||
|
>
|
||||||
|
<SessionIcon
|
||||||
|
iconType={SessionIconType.Upload}
|
||||||
|
theme={theme}
|
||||||
|
iconSize={SessionIconSize.Small}
|
||||||
|
iconRotation={180}
|
||||||
|
/>
|
||||||
|
<SpacerXS />
|
||||||
|
<Text text={contentText} subtle={true} />
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
};
|
@ -0,0 +1,78 @@
|
|||||||
|
import { SignalService } from '../../../../protobuf';
|
||||||
|
import { MessageParams } from '../Message';
|
||||||
|
import { ContentMessage } from '..';
|
||||||
|
import { v4 as uuid } from 'uuid';
|
||||||
|
import { PubKey } from '../../../types';
|
||||||
|
import { getMessageQueue } from '../../..';
|
||||||
|
import { ConversationController } from '../../../conversations';
|
||||||
|
import { UserUtils } from '../../../utils';
|
||||||
|
interface DataExtractionNotificationMessageParams extends MessageParams {
|
||||||
|
referencedAttachmentTimestamp: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DataExtractionNotificationMessage extends ContentMessage {
|
||||||
|
public readonly referencedAttachmentTimestamp: number;
|
||||||
|
|
||||||
|
constructor(params: DataExtractionNotificationMessageParams) {
|
||||||
|
super({ timestamp: params.timestamp, identifier: params.identifier });
|
||||||
|
this.referencedAttachmentTimestamp = params.referencedAttachmentTimestamp;
|
||||||
|
// this does not make any sense
|
||||||
|
if (!this.referencedAttachmentTimestamp) {
|
||||||
|
throw new Error('referencedAttachmentTimestamp must be set');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public contentProto(): SignalService.Content {
|
||||||
|
return new SignalService.Content({
|
||||||
|
dataExtractionNotification: this.dataExtractionProto(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected dataExtractionProto(): SignalService.DataExtractionNotification {
|
||||||
|
const ACTION_ENUM = SignalService.DataExtractionNotification.Type;
|
||||||
|
|
||||||
|
const action = ACTION_ENUM.MEDIA_SAVED; // we cannot know when user screenshots, so it can only be a media saved
|
||||||
|
|
||||||
|
return new SignalService.DataExtractionNotification({
|
||||||
|
type: action,
|
||||||
|
timestamp: this.referencedAttachmentTimestamp,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Currently only enabled for private chats
|
||||||
|
*/
|
||||||
|
export const sendDataExtractionNotification = async (
|
||||||
|
conversationId: string,
|
||||||
|
attachmentSender: string,
|
||||||
|
referencedAttachmentTimestamp?: number
|
||||||
|
) => {
|
||||||
|
const convo = ConversationController.getInstance().get(conversationId);
|
||||||
|
if (
|
||||||
|
!convo ||
|
||||||
|
!convo.isPrivate() ||
|
||||||
|
convo.isMe() ||
|
||||||
|
UserUtils.isUsFromCache(PubKey.cast(attachmentSender)) ||
|
||||||
|
!referencedAttachmentTimestamp
|
||||||
|
) {
|
||||||
|
window.log.warn('Not sending saving attachment notification for', attachmentSender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataExtractionNotificationMessage = new DataExtractionNotificationMessage({
|
||||||
|
referencedAttachmentTimestamp,
|
||||||
|
identifier: uuid(),
|
||||||
|
timestamp: Date.now(),
|
||||||
|
});
|
||||||
|
const pubkey = PubKey.cast(conversationId);
|
||||||
|
window.log.info(
|
||||||
|
`Sending DataExtractionNotification to ${conversationId} about attachment: ${referencedAttachmentTimestamp}`
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await getMessageQueue().sendToPubKey(pubkey, dataExtractionNotificationMessage);
|
||||||
|
} catch (e) {
|
||||||
|
window.log.warn('failed to send data extraction notification', e);
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue