diff --git a/ts/background.ts b/ts/background.ts index 68f496b162a..79716da7ca9 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -50,7 +50,7 @@ import { MessageEventData, ReadEvent, ConfigurationEvent, - ViewSyncEvent, + ViewOnceOpenSyncEvent, MessageRequestResponseEvent, FetchLatestEvent, KeysEvent, @@ -77,7 +77,7 @@ import { import { MessageRequests } from './messageModifiers/MessageRequests'; import { Reactions } from './messageModifiers/Reactions'; import { ReadSyncs } from './messageModifiers/ReadSyncs'; -import { ViewSyncs } from './messageModifiers/ViewSyncs'; +import { ViewOnceOpenSyncs } from './messageModifiers/ViewOnceOpenSyncs'; import { SendStateByConversationId, SendStatus, @@ -2208,8 +2208,8 @@ export async function startApp(): Promise { queuedEventListener(onStickerPack) ); messageReceiver.addEventListener( - 'viewSync', - queuedEventListener(onViewSync) + 'viewOnceOpenSync', + queuedEventListener(onViewOnceOpenSync) ); messageReceiver.addEventListener( 'messageRequestResponse', @@ -3633,19 +3633,19 @@ export async function startApp(): Promise { window.log.warn('background onError: Doing nothing with incoming error'); } - async function onViewSync(ev: ViewSyncEvent) { + async function onViewOnceOpenSync(ev: ViewOnceOpenSyncEvent) { ev.confirm(); const { source, sourceUuid, timestamp } = ev; - window.log.info(`view sync ${source} ${timestamp}`); + window.log.info(`view once open sync ${source} ${timestamp}`); - const sync = ViewSyncs.getSingleton().add({ + const sync = ViewOnceOpenSyncs.getSingleton().add({ source, sourceUuid, timestamp, }); - ViewSyncs.getSingleton().onSync(sync); + ViewOnceOpenSyncs.getSingleton().onSync(sync); } async function onFetchLatestSync(ev: FetchLatestEvent) { diff --git a/ts/messageModifiers/ViewSyncs.ts b/ts/messageModifiers/ViewOnceOpenSyncs.ts similarity index 74% rename from ts/messageModifiers/ViewSyncs.ts rename to ts/messageModifiers/ViewOnceOpenSyncs.ts index 4ca8986fd33..e6570a8df86 100644 --- a/ts/messageModifiers/ViewSyncs.ts +++ b/ts/messageModifiers/ViewOnceOpenSyncs.ts @@ -6,26 +6,26 @@ import { Collection, Model } from 'backbone'; import { MessageModel } from '../models/messages'; -type ViewSyncAttributesType = { +type ViewOnceOpenSyncAttributesType = { source?: string; sourceUuid: string; timestamp: number; }; -class ViewSyncModel extends Model {} +class ViewOnceOpenSyncModel extends Model {} -let singleton: ViewSyncs | undefined; +let singleton: ViewOnceOpenSyncs | undefined; -export class ViewSyncs extends Collection { - static getSingleton(): ViewSyncs { +export class ViewOnceOpenSyncs extends Collection { + static getSingleton(): ViewOnceOpenSyncs { if (!singleton) { - singleton = new ViewSyncs(); + singleton = new ViewOnceOpenSyncs(); } return singleton; } - forMessage(message: MessageModel): ViewSyncModel | null { + forMessage(message: MessageModel): ViewOnceOpenSyncModel | null { const syncBySourceUuid = this.find(item => { return ( item.get('sourceUuid') === message.get('sourceUuid') && @@ -33,7 +33,7 @@ export class ViewSyncs extends Collection { ); }); if (syncBySourceUuid) { - window.log.info('Found early view sync for message'); + window.log.info('Found early view once open sync for message'); this.remove(syncBySourceUuid); return syncBySourceUuid; } @@ -45,7 +45,7 @@ export class ViewSyncs extends Collection { ); }); if (syncBySource) { - window.log.info('Found early view sync for message'); + window.log.info('Found early view once open sync for message'); this.remove(syncBySource); return syncBySource; } @@ -53,7 +53,7 @@ export class ViewSyncs extends Collection { return null; } - async onSync(sync: ViewSyncModel): Promise { + async onSync(sync: ViewOnceOpenSyncModel): Promise { try { const messages = await window.Signal.Data.getMessagesBySentAt( sync.get('timestamp'), @@ -80,7 +80,7 @@ export class ViewSyncs extends Collection { const syncSourceUuid = sync.get('sourceUuid'); const syncTimestamp = sync.get('timestamp'); const wasMessageFound = Boolean(found); - window.log.info('Receive view sync:', { + window.log.info('Receive view once open sync:', { syncSource, syncSourceUuid, syncTimestamp, @@ -92,12 +92,12 @@ export class ViewSyncs extends Collection { } const message = window.MessageController.register(found.id, found); - await message.markViewed({ fromSync: true }); + await message.markViewOnceMessageViewed({ fromSync: true }); this.remove(sync); } catch (error) { window.log.error( - 'ViewSyncs.onSync error:', + 'ViewOnceOpenSyncs.onSync error:', error && error.stack ? error.stack : error ); } diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 784af8ff76c..1fc347f7d53 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -103,7 +103,7 @@ import { import { Deletes } from '../messageModifiers/Deletes'; import { Reactions } from '../messageModifiers/Reactions'; import { ReadSyncs } from '../messageModifiers/ReadSyncs'; -import { ViewSyncs } from '../messageModifiers/ViewSyncs'; +import { ViewOnceOpenSyncs } from '../messageModifiers/ViewOnceOpenSyncs'; import * as AttachmentDownloads from '../messageModifiers/AttachmentDownloads'; import * as LinkPreview from '../types/LinkPreview'; import { SignalService as Proto } from '../protobuf'; @@ -829,18 +829,20 @@ export class MessageModel extends window.Backbone.Model { return true; } - async markViewed(options?: { fromSync?: boolean }): Promise { + async markViewOnceMessageViewed(options?: { + fromSync?: boolean; + }): Promise { const { fromSync } = options || {}; if (!this.isValidTapToView()) { window.log.warn( - `markViewed: Message ${this.idForLogging()} is not a valid tap to view message!` + `markViewOnceMessageViewed: Message ${this.idForLogging()} is not a valid tap to view message!` ); return; } if (this.isErased()) { window.log.warn( - `markViewed: Message ${this.idForLogging()} is already erased!` + `markViewOnceMessageViewed: Message ${this.idForLogging()} is already erased!` ); return; } @@ -867,7 +869,7 @@ export class MessageModel extends window.Backbone.Model { if (window.ConversationController.areWePrimaryDevice()) { window.log.warn( - 'markViewed: We are primary device; not sending view sync' + 'markViewOnceMessageViewed: We are primary device; not sending view once open sync' ); return; } @@ -3282,11 +3284,13 @@ export class MessageModel extends window.Backbone.Model { } } - // Check for out-of-order view syncs + // Check for out-of-order view once open syncs if (type === 'incoming' && isTapToView(message.attributes)) { - const viewSync = ViewSyncs.getSingleton().forMessage(message); - if (viewSync) { - await message.markViewed({ fromSync: true }); + const viewOnceOpenSync = ViewOnceOpenSyncs.getSingleton().forMessage( + message + ); + if (viewOnceOpenSync) { + await message.markViewOnceMessageViewed({ fromSync: true }); changed = true; } } diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index 29168a36f3f..4bc439c914c 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -91,7 +91,7 @@ import { RetryRequestEvent, ReadEvent, ConfigurationEvent, - ViewSyncEvent, + ViewOnceOpenSyncEvent, MessageRequestResponseEvent, FetchLatestEvent, KeysEvent, @@ -2337,7 +2337,7 @@ class MessageReceiverInner extends EventTarget { ) { window.log.info('got view once open sync message'); - const ev = new ViewSyncEvent( + const ev = new ViewOnceOpenSyncEvent( { source: dropNull(sync.sender), sourceUuid: sync.senderUuid @@ -2755,8 +2755,8 @@ export default class MessageReceiver { ): void; public addEventListener( - name: 'viewSync', - handler: (ev: ViewSyncEvent) => void + name: 'viewOnceOpenSync', + handler: (ev: ViewOnceOpenSyncEvent) => void ): void; public addEventListener( diff --git a/ts/textsecure/messageReceiverEvents.ts b/ts/textsecure/messageReceiverEvents.ts index 511f8f3563b..f779e29b9ab 100644 --- a/ts/textsecure/messageReceiverEvents.ts +++ b/ts/textsecure/messageReceiverEvents.ts @@ -237,13 +237,13 @@ export class ConfigurationEvent extends ConfirmableEvent { } } -export type ViewSyncOptions = { +export type ViewOnceOpenSyncOptions = { source?: string; sourceUuid?: string; timestamp?: number; }; -export class ViewSyncEvent extends ConfirmableEvent { +export class ViewOnceOpenSyncEvent extends ConfirmableEvent { public readonly source?: string; public readonly sourceUuid?: string; @@ -251,10 +251,10 @@ export class ViewSyncEvent extends ConfirmableEvent { public readonly timestamp?: number; constructor( - { source, sourceUuid, timestamp }: ViewSyncOptions, + { source, sourceUuid, timestamp }: ViewOnceOpenSyncOptions, confirm: ConfirmCallback ) { - super('viewSync', confirm); + super('viewOnceOpenSync', confirm); this.source = source; this.sourceUuid = sourceUuid; diff --git a/ts/views/conversation_view.ts b/ts/views/conversation_view.ts index 7b3bc8606ab..13b3a8cc230 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -2907,7 +2907,7 @@ Whisper.ConversationView = Whisper.View.extend({ path: tempPath, }; - await message.markViewed(); + await message.markViewOnceMessageViewed(); const closeLightbox = async () => { if (!this.lightboxView) {