From aa797f6670ce036ed3c21001f003c845d2336c15 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 23 Jun 2020 13:55:47 +1000 Subject: [PATCH] various changes to be reverted. kind of working session chats only. --- js/models/conversations.js | 51 ++-- js/modules/loki_snode_api.js | 2 +- libtextsecure/sendmessage.js | 235 +++++++++--------- .../conversation/GroupNotification.tsx | 8 +- ts/receiver/receiver.ts | 12 +- .../outgoing/content/data/ChatMessage.ts | 2 + 6 files changed, 156 insertions(+), 154 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index b94ae5060..65a7b4af8 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -723,13 +723,15 @@ if (!this.contactCollection.length) { return false; } - - return this.contactCollection.every(contact => { - if (contact.isMe()) { - return true; - } - return contact.isVerified(); - }); + console.log('this.contactCollection', this.contactCollection) + //FIXME AUDRIC + return true; + // return this.contactCollection.every(contact => { + // if (contact.isMe()) { + // return true; + // } + // return contact.isVerified(); + // }); }, async getPrimaryConversation() { if (!this.isSecondaryDevice()) { @@ -2097,24 +2099,25 @@ textsecure.messaging.syncReadMessages(read, sendOptions) ); - if (storage.get('read-receipt-setting')) { - await Promise.all( - _.map(_.groupBy(read, 'sender'), async (receipts, sender) => { - const timestamps = _.map(receipts, 'timestamp'); - const receiptMessage = new libsession.Messages.Outgoing.ReadReceiptMessage( - { - timestamp: Date.now(), - timestamps, - } - ); + // FIXME AUDRIC + // if (storage.get('read-receipt-setting')) { + // await Promise.all( + // _.map(_.groupBy(read, 'sender'), async (receipts, sender) => { + // const timestamps = _.map(receipts, 'timestamp'); + // const receiptMessage = new libsession.Messages.Outgoing.ReadReceiptMessage( + // { + // timestamp: Date.now(), + // timestamps, + // } + // ); - const device = new libsession.Types.PubKey(sender); - await libsession - .getMessageQueue() - .sendUsingMultiDevice(device, receiptMessage); - }) - ); - } + // const device = new libsession.Types.PubKey(sender); + // await libsession + // .getMessageQueue() + // .sendUsingMultiDevice(device, receiptMessage); + // }) + // ); + // } } }, diff --git a/js/modules/loki_snode_api.js b/js/modules/loki_snode_api.js index 626aff7e7..a644f1038 100644 --- a/js/modules/loki_snode_api.js +++ b/js/modules/loki_snode_api.js @@ -490,7 +490,7 @@ class LokiSnodeAPI { // this function may be called concurrently make sure we only have one inflight return primitives.allowOnlyOneAtATime( 'buildNewOnionPaths', - this.buildNewOnionPathsWorker + () => this.buildNewOnionPathsWorker() ); } diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index e98ce8fa8..d1aa81d55 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -389,14 +389,6 @@ MessageSender.prototype = { silent, options = {} ) { - const rejections = textsecure.storage.get('signedKeyRotationRejected', 0); - if (rejections > 5) { - throw new textsecure.SignedPreKeyRotationError( - numbers, - message.toArrayBuffer(), - timestamp - ); - } // Note: Since we're just doing independant tasks, // using `async` in the `forEach` loop should be fine. @@ -529,135 +521,138 @@ MessageSender.prototype = { }, async sendContactSyncMessage(conversations) { - // If we havn't got a primaryDeviceKey then we are in the middle of pairing - // primaryDevicePubKey is set to our own number if we are the master device - const primaryDeviceKey = window.storage.get('primaryDevicePubKey'); - if (!primaryDeviceKey) { - return Promise.resolve(); - } - // first get all friends with primary devices - const sessionContactsPrimary = - conversations.filter( - c => - c.isPrivate() && - !c.isOurLocalDevice() && - !c.isBlocked() && - !c.get('secondaryStatus') - ) || []; + return Promise.resolve(); - // then get all friends with secondary devices - let sessionContactsSecondary = conversations.filter( - c => - c.isPrivate() && - !c.isOurLocalDevice() && - !c.isBlocked() && - c.get('secondaryStatus') - ); + // // If we havn't got a primaryDeviceKey then we are in the middle of pairing + // // primaryDevicePubKey is set to our own number if we are the master device + // const primaryDeviceKey = window.storage.get('primaryDevicePubKey'); + // if (!primaryDeviceKey) { + // return Promise.resolve(); + // } + // // first get all friends with primary devices + // const sessionContactsPrimary = + // conversations.filter( + // c => + // c.isPrivate() && + // !c.isOurLocalDevice() && + // !c.isBlocked() && + // !c.get('secondaryStatus') + // ) || []; - // then morph all secondary conversation to their primary - sessionContactsSecondary = - (await Promise.all( - // eslint-disable-next-line arrow-body-style - sessionContactsSecondary.map(async c => { - return window.ConversationController.getOrCreateAndWait( - c.getPrimaryDevicePubKey(), - 'private' - ); - }) - )) || []; - // filter out our primary pubkey if it was added. - sessionContactsSecondary = sessionContactsSecondary.filter( - c => c.id !== primaryDeviceKey - ); + // // then get all friends with secondary devices + // let sessionContactsSecondary = conversations.filter( + // c => + // c.isPrivate() && + // !c.isOurLocalDevice() && + // !c.isBlocked() && + // c.get('secondaryStatus') + // ); - const contactsSet = new Set([ - ...sessionContactsPrimary, - ...sessionContactsSecondary, - ]); + // // then morph all secondary conversation to their primary + // sessionContactsSecondary = + // (await Promise.all( + // // eslint-disable-next-line arrow-body-style + // sessionContactsSecondary.map(async c => { + // return window.ConversationController.getOrCreateAndWait( + // c.getPrimaryDevicePubKey(), + // 'private' + // ); + // }) + // )) || []; + // // filter out our primary pubkey if it was added. + // sessionContactsSecondary = sessionContactsSecondary.filter( + // c => c.id !== primaryDeviceKey + // ); - if (contactsSet.size === 0) { - window.console.info('No contacts to sync.'); + // const contactsSet = new Set([ + // ...sessionContactsPrimary, + // ...sessionContactsSecondary, + // ]); - return Promise.resolve(); - } - libloki.api.debug.logContactSync('Triggering contact sync message with:', [ - ...contactsSet, - ]); + // if (contactsSet.size === 0) { + // window.console.info('No contacts to sync.'); - // We need to sync across 3 contacts at a time - // This is to avoid hitting storage server limit - const chunked = _.chunk([...contactsSet], 3); - const syncMessages = await Promise.all( - chunked.map(c => libloki.api.createContactSyncProtoMessage(c)) - ); - const syncPromises = syncMessages - .filter(message => message != null) - .map(syncMessage => { - const contentMessage = new textsecure.protobuf.Content(); - contentMessage.syncMessage = syncMessage; + // return Promise.resolve(); + // } + // libloki.api.debug.logContactSync('Triggering contact sync message with:', [ + // ...contactsSet, + // ]); - const silent = true; + // // We need to sync across 3 contacts at a time + // // This is to avoid hitting storage server limit + // const chunked = _.chunk([...contactsSet], 3); + // const syncMessages = await Promise.all( + // chunked.map(c => libloki.api.createContactSyncProtoMessage(c)) + // ); + // const syncPromises = syncMessages + // .filter(message => message != null) + // .map(syncMessage => { + // const contentMessage = new textsecure.protobuf.Content(); + // contentMessage.syncMessage = syncMessage; - const debugMessageType = - window.textsecure.OutgoingMessage.DebugMessageType.CONTACT_SYNC_SEND; + // const silent = true; - return this.sendIndividualProto( - primaryDeviceKey, - contentMessage, - Date.now(), - silent, - { debugMessageType } // options - ); - }); + // const debugMessageType = + // window.textsecure.OutgoingMessage.DebugMessageType.CONTACT_SYNC_SEND; - return Promise.all(syncPromises); + // return this.sendIndividualProto( + // primaryDeviceKey, + // contentMessage, + // Date.now(), + // silent, + // { debugMessageType } // options + // ); + // }); + + // return Promise.all(syncPromises); }, sendGroupSyncMessage(conversations) { - // If we havn't got a primaryDeviceKey then we are in the middle of pairing - // primaryDevicePubKey is set to our own number if we are the master device - const primaryDeviceKey = window.storage.get('primaryDevicePubKey'); - if (!primaryDeviceKey) { - window.console.debug('sendGroupSyncMessage: no primary device pubkey'); - return Promise.resolve(); - } - // We only want to sync across closed groups that we haven't left - const sessionGroups = conversations.filter( - c => - c.isClosedGroup() && - !c.get('left') && - !c.isBlocked() && - !c.isMediumGroup() - ); - if (sessionGroups.length === 0) { - window.console.info('No closed group to sync.'); - return Promise.resolve(); - } + return Promise.resolve(); + // // If we havn't got a primaryDeviceKey then we are in the middle of pairing + // // primaryDevicePubKey is set to our own number if we are the master device + // const primaryDeviceKey = window.storage.get('primaryDevicePubKey'); + // if (!primaryDeviceKey) { + // window.console.debug('sendGroupSyncMessage: no primary device pubkey'); + // return Promise.resolve(); + // } + // // We only want to sync across closed groups that we haven't left + // const sessionGroups = conversations.filter( + // c => + // c.isClosedGroup() && + // !c.get('left') && + // !c.isBlocked() && + // !c.isMediumGroup() + // ); + // if (sessionGroups.length === 0) { + // window.console.info('No closed group to sync.'); + // return Promise.resolve(); + // } - // We need to sync across 1 group at a time - // This is because we could hit the storage server limit with one group - const syncPromises = sessionGroups - .map(c => libloki.api.createGroupSyncProtoMessage(c)) - .filter(message => message != null) - .map(syncMessage => { - const contentMessage = new textsecure.protobuf.Content(); - contentMessage.syncMessage = syncMessage; + // // We need to sync across 1 group at a time + // // This is because we could hit the storage server limit with one group + // const syncPromises = sessionGroups + // .map(c => libloki.api.createGroupSyncProtoMessage(c)) + // .filter(message => message != null) + // .map(syncMessage => { + // const contentMessage = new textsecure.protobuf.Content(); + // contentMessage.syncMessage = syncMessage; - const silent = true; - const debugMessageType = - window.textsecure.OutgoingMessage.DebugMessageType - .CLOSED_GROUP_SYNC_SEND; + // const silent = true; + // const debugMessageType = + // window.textsecure.OutgoingMessage.DebugMessageType + // .CLOSED_GROUP_SYNC_SEND; - return this.sendIndividualProto( - primaryDeviceKey, - contentMessage, - Date.now(), - silent, - { debugMessageType } // options - ); - }); + // return this.sendIndividualProto( + // primaryDeviceKey, + // contentMessage, + // Date.now(), + // silent, + // { debugMessageType } // options + // ); + // }); - return Promise.all(syncPromises); + // return Promise.all(syncPromises); }, sendOpenGroupsSyncMessage(conversations) { diff --git a/ts/components/conversation/GroupNotification.tsx b/ts/components/conversation/GroupNotification.tsx index 0da0a50b4..6cac19e26 100644 --- a/ts/components/conversation/GroupNotification.tsx +++ b/ts/components/conversation/GroupNotification.tsx @@ -53,7 +53,7 @@ export class GroupNotification extends React.Component { return `${i18n('titleIsNow', [newName || ''])}.`; case 'add': if (!contacts || !contacts.length) { - throw new Error('Group update is missing contacts'); + throw new Error('Group update add is missing contacts'); } const joinKey = @@ -66,7 +66,7 @@ export class GroupNotification extends React.Component { } if (!contacts || !contacts.length) { - throw new Error('Group update is missing contacts'); + throw new Error('Group update remove is missing contacts'); } const leftKey = @@ -79,7 +79,9 @@ export class GroupNotification extends React.Component { } if (!contacts || !contacts.length) { - throw new Error('Group update is missing contacts'); + // FIXME audric + return 'FIXME audric'; + // throw new Error('Group update kicked is missing contacts'); } const kickedKey = diff --git a/ts/receiver/receiver.ts b/ts/receiver/receiver.ts index 5169ce269..c7b94bc36 100644 --- a/ts/receiver/receiver.ts +++ b/ts/receiver/receiver.ts @@ -176,13 +176,13 @@ enum ConversationType { } async function sendDeliveryReceipt(source: string, timestamp: any) { - const receiptMessage = new DeliveryReceiptMessage({ - timestamp: Date.now(), - timestamps: [timestamp], - }); + // const receiptMessage = new DeliveryReceiptMessage({ + // timestamp: Date.now(), + // timestamps: [timestamp], + // }); - const device = new PubKey(source); - await getMessageQueue().sendUsingMultiDevice(device, receiptMessage); + // const device = new PubKey(source); + // await getMessageQueue().sendUsingMultiDevice(device, receiptMessage); } interface MessageId { diff --git a/ts/session/messages/outgoing/content/data/ChatMessage.ts b/ts/session/messages/outgoing/content/data/ChatMessage.ts index 6c8bf4720..a82cdb37a 100644 --- a/ts/session/messages/outgoing/content/data/ChatMessage.ts +++ b/ts/session/messages/outgoing/content/data/ChatMessage.ts @@ -150,6 +150,8 @@ export class ChatMessage extends DataMessage { }); } + dataMessage.timestamp = this.timestamp; + return dataMessage; }