diff --git a/js/models/conversations.js b/js/models/conversations.js index bdbc2c760..7f0cd973e 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1780,7 +1780,7 @@ const sessionEstablished = new window.libsession.Messages.Outgoing.SessionEstablishedMessage( { timestamp: Date.now() } ); - await libsession.getMessageQueue().send(user, sessionEstablished); + await libsession.getMessageQueue().send(user, sessionEstablished); }, isSessionResetReceived() { diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 11cf5ccc5..031b676fa 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -539,87 +539,46 @@ MessageSender.prototype = { return libsession.getMessageQueue().sendSyncMessage(openGroupsSyncMessage); }, - syncReadMessages(reads, options) { - const myNumber = textsecure.storage.user.getNumber(); + syncReadMessages(reads) { const myDevice = textsecure.storage.user.getDeviceId(); + // FIXME audric currently not in used if (myDevice !== 1 && myDevice !== '1') { - const syncMessage = this.createSyncMessage(); - syncMessage.read = []; - for (let i = 0; i < reads.length; i += 1) { - const read = new textsecure.protobuf.SyncMessage.Read(); - read.timestamp = reads[i].timestamp; - read.sender = reads[i].sender; - syncMessage.read.push(read); - } - const contentMessage = new textsecure.protobuf.Content(); - contentMessage.syncMessage = syncMessage; - - const silent = true; - return this.sendIndividualProto( - myNumber, - contentMessage, - Date.now(), - silent, - options + const syncReadMessages = new libsession.Messages.Outgoing.OpenGroupSyncMessage( + { + readMessages: reads, + } ); + + return libsession.getMessageQueue().sendSyncMessage(syncReadMessages); } return Promise.resolve(); }, - syncVerification(destination, state, identityKey, options) { - const myNumber = textsecure.storage.user.getNumber(); + async syncVerification(destination, state, identityKey) { const myDevice = textsecure.storage.user.getDeviceId(); - const now = Date.now(); if (myDevice === 1 || myDevice === '1') { return Promise.resolve(); } + // send a session established message (used as a nullMessage) + const destinationPubKey = new libsession.Types.PubKey(destination); - // First send a null message to mask the sync message. - const nullMessage = new textsecure.protobuf.NullMessage(); - - // Generate a random int from 1 and 512 - const buffer = libsignal.crypto.getRandomBytes(1); - const paddingLength = (new Uint8Array(buffer)[0] & 0x1ff) + 1; - - // Generate a random padding buffer of the chosen size - nullMessage.padding = libsignal.crypto.getRandomBytes(paddingLength); - - const contentMessage = new textsecure.protobuf.Content(); - contentMessage.nullMessage = nullMessage; - - // We want the NullMessage to look like a normal outgoing message; not silent - const silent = false; - const promise = this.sendIndividualProto( - destination, - contentMessage, - now, - silent, - options + const sessionEstablished = new window.libsession.Messages.Outgoing.SessionEstablishedMessage( + { timestamp: Date.now() } ); + const { padding } = sessionEstablished; + await libsession.getMessageQueue().send(destinationPubKey, sessionEstablished); - return promise.then(() => { - const verified = new textsecure.protobuf.Verified(); - verified.state = state; - verified.destination = destination; - verified.identityKey = identityKey; - verified.nullMessage = nullMessage.padding; - - const syncMessage = this.createSyncMessage(); - syncMessage.verified = verified; - - const secondMessage = new textsecure.protobuf.Content(); - secondMessage.syncMessage = syncMessage; - - const innerSilent = true; - return this.sendIndividualProto( - myNumber, - secondMessage, - now, - innerSilent, - options - ); - }); + + const verifiedSyncParams = { + state, + destination: destinationPubKey, + identityKey, + padding, + timestamp: Date.now(), + } + const verifiedSyncMessage = new window.libsession.Messages.Outgoing.VerifiedSyncMessage(verifiedSyncParams); + return libsession.getMessageQueue().sendSyncMessage(verifiedSyncMessage); }, async sendGroupProto( diff --git a/ts/session/messages/outgoing/content/sync/SyncReadMessage.ts b/ts/session/messages/outgoing/content/sync/SyncReadMessage.ts new file mode 100644 index 000000000..7d8fd3cca --- /dev/null +++ b/ts/session/messages/outgoing/content/sync/SyncReadMessage.ts @@ -0,0 +1,30 @@ +import { SyncMessage } from './SyncMessage'; +import { SignalService } from '../../../../../protobuf'; +import { MessageParams } from '../../Message'; + +interface SyncReadMessageParams extends MessageParams { + readMessages: any; +} + +export abstract class SyncReadMessage extends SyncMessage { + public readonly readMessages: any; + + + constructor(params: SyncReadMessageParams) { + super({ timestamp: params.timestamp, identifier: params.identifier }); + this.readMessages = params.readMessages; + } + + protected syncProto(): SignalService.SyncMessage { + const syncMessage = super.syncProto(); + syncMessage.read = []; + for (const read of this.readMessages) { + const readMessage = new SignalService.SyncMessage.Read(); + read.timestamp = readMessage.timestamp; + read.sender = readMessage.sender; + syncMessage.read.push(readMessage); + } + + return syncMessage; + } +} diff --git a/ts/session/messages/outgoing/content/sync/VerifiedSyncMessage.ts b/ts/session/messages/outgoing/content/sync/VerifiedSyncMessage.ts new file mode 100644 index 000000000..ee9fd0c69 --- /dev/null +++ b/ts/session/messages/outgoing/content/sync/VerifiedSyncMessage.ts @@ -0,0 +1,37 @@ +import { SyncMessage } from './SyncMessage'; +import { SignalService } from '../../../../../protobuf'; +import { MessageParams } from '../../Message'; +import { PubKey } from '../../../../types'; + +interface VerifiedSyncMessageParams extends MessageParams { + padding: Buffer; + identityKey: Uint8Array; + destination: PubKey; + state: SignalService.Verified.State; +} + +export abstract class VerifiedSyncMessage extends SyncMessage { + public readonly state: SignalService.Verified.State; + public readonly destination: PubKey; + public readonly identityKey: Uint8Array; + public readonly padding: Buffer; + + constructor(params: VerifiedSyncMessageParams) { + super({ timestamp: params.timestamp, identifier: params.identifier }); + this.state = params.state; + this.destination = params.destination; + this.identityKey = params.identityKey; + this.padding = params.padding; + } + + protected syncProto(): SignalService.SyncMessage { + const syncMessage = super.syncProto(); + syncMessage.verified = new SignalService.Verified(); + syncMessage.verified.state = this.state; + syncMessage.verified.destination = this.destination.key; + syncMessage.verified.identityKey = this.identityKey; + syncMessage.verified.nullMessage = this.padding; + + return syncMessage; + } +} diff --git a/ts/session/messages/outgoing/content/sync/index.ts b/ts/session/messages/outgoing/content/sync/index.ts index 23b32fdc5..a2aea70b9 100644 --- a/ts/session/messages/outgoing/content/sync/index.ts +++ b/ts/session/messages/outgoing/content/sync/index.ts @@ -4,3 +4,5 @@ export * from './ClosedGroupSyncMessage'; export * from './OpenGroupSyncMessage'; export * from './SyncMessage'; export * from './SentSyncMessage'; +export * from './SyncReadMessage'; +export * from './VerifiedSyncMessage';