From 273eedc6a95af6fdbaf59b5c62f77551c7fce3be Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 27 Jan 2021 15:33:51 +1100 Subject: [PATCH] remove hasSignalAccount and Sealed Sender unused --- js/models/conversations.js | 17 +---------- js/models/messages.d.ts | 1 - js/models/messages.js | 6 ---- js/modules/loki_app_dot_net_api.js | 29 +++++++++++-------- libtextsecure/message_receiver.js | 8 ----- test/backup_test.js | 1 - ts/components/conversation/ContactDetail.tsx | 7 ++--- .../conversation/EmbeddedContact.tsx | 1 - ts/components/conversation/Message.tsx | 1 - ts/receiver/dataMessage.ts | 8 +++-- ts/receiver/errors.ts | 2 +- ts/test/types/Contact_test.ts | 7 ----- ts/types/Contact.tsx | 3 -- 13 files changed, 26 insertions(+), 65 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index a125ffe53..03b009bfe 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -22,14 +22,7 @@ window.Whisper = window.Whisper || {}; - const SEALED_SENDER = { - UNKNOWN: 0, - ENABLED: 1, - DISABLED: 2, - UNRESTRICTED: 3, - }; - - const { Conversation, Contact, Message, PhoneNumber } = window.Signal.Types; + const { Contact, Message, PhoneNumber } = window.Signal.Types; const { upgradeMessageSchema, loadAttachmentData, @@ -109,10 +102,6 @@ this.set('profileSharing', true); } - const sealedSender = this.get('sealedSender'); - if (sealedSender === undefined) { - this.set({ sealedSender: SEALED_SENDER.UNKNOWN }); - } this.unset('unidentifiedDelivery'); this.unset('unidentifiedDeliveryUnrestricted'); this.unset('hasFetchedProfile'); @@ -1355,13 +1344,9 @@ async setProfileKey(profileKey) { // profileKey is a string so we can compare it directly if (this.get('profileKey') !== profileKey) { - window.log.info( - `Setting sealedSender to UNKNOWN for conversation ${this.idForLogging()}` - ); this.set({ profileKey, accessKey: null, - sealedSender: SEALED_SENDER.UNKNOWN, }); await this.deriveAccessKeyIfNeeded(); diff --git a/js/models/messages.d.ts b/js/models/messages.d.ts index 2a5ef4a98..e4b83ffd3 100644 --- a/js/models/messages.d.ts +++ b/js/models/messages.d.ts @@ -59,7 +59,6 @@ export interface MessageRegularProps { status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error' | 'pow'; // What if changed this over to a single contact like quote, and put the events on it? contact?: Contact & { - hasSignalAccount: boolean; onSendMessage?: () => void; onClick?: () => void; }; diff --git a/js/models/messages.js b/js/models/messages.js index c209a0df1..799e1d05c 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -37,10 +37,6 @@ window.doesAcountCheckJobExist = number => Boolean(window.AccountJobs[number]); - window.isSignalAccountCheckComplete = number => - window.AccountCache[number] !== undefined; - window.hasSignalAccount = () => true; - window.Whisper.Message = Backbone.Model.extend({ initialize(attributes) { if (_.isObject(attributes)) { @@ -600,7 +596,6 @@ this.trigger('show-contact-detail', { contact, - hasSignalAccount: window.hasSignalAccount(firstNumber), }); }; @@ -609,7 +604,6 @@ getAbsoluteAttachmentPath, onSendMessage, onClick, - hasSignalAccount: window.hasSignalAccount(firstNumber), }); }, processQuoteAttachment(attachment) { diff --git a/js/modules/loki_app_dot_net_api.js b/js/modules/loki_app_dot_net_api.js index 2ccf399c6..8b2c5f312 100644 --- a/js/modules/loki_app_dot_net_api.js +++ b/js/modules/loki_app_dot_net_api.js @@ -1049,9 +1049,8 @@ class LokiAppDotNetServerAPI { // functions to a specific ADN channel on an ADN server class LokiPublicChannelAPI { - constructor(chatAPI, serverAPI, channelId, conversationId) { + constructor(_, serverAPI, channelId, conversationId) { // properties - this.chatAPI = chatAPI; this.serverAPI = serverAPI; this.channelId = channelId; this.baseChannelUrl = `channels/${this.channelId}`; @@ -1679,7 +1678,7 @@ class LokiPublicChannelAPI { // If lastMessageServerID is not set, it's the first pull of messages for this open group. // We just pull 100 messages (server sends the most recent ones) if (!this.lastMessageServerID || this.lastMessageServerID === 0) { - params.count = 100; // 64 on android + params.count = 100; } else { // if lastMessageServerID is set, we pull 200 messages per 200 messages, giving the since_id parameter set to our last received message id. params.count = 200; @@ -1740,6 +1739,7 @@ class LokiPublicChannelAPI { const pubKey = adnMessage.user.username; try { const messengerData = await this.getMessengerData(adnMessage); + if (messengerData === false) { return false; } @@ -1769,9 +1769,12 @@ class LokiPublicChannelAPI { testedMessage, testedMessage.user.username ); + const isThisMessageDuplicate = this.lastMessagesCache.some(m => + isDuplicate(m, adnMessage) + ); // Filter out any messages that we got previously - if (this.lastMessagesCache.some(m => isDuplicate(m, adnMessage))) { + if (isThisMessageDuplicate) { return false; // Duplicate message } @@ -1860,7 +1863,6 @@ class LokiPublicChannelAPI { } }) ); - // return early if we should stop processing if (!pendingMessages.length || !this.running) { this.conversation.setLastRetrievedMessage(this.lastMessageServerID); @@ -1872,21 +1874,24 @@ class LokiPublicChannelAPI { pendingMessages = pendingMessages.filter(messageData => !!messageData); // process all messages in the order received - pendingMessages.forEach(message => { + + // trigger the handling of those messages sequentially + + // eslint-disable-next-line no-plusplus + for (let index = 0; index < pendingMessages.length; index++) { if (this.running) { log.info( - 'emitting pending message', - message.serverId, + 'emitting pending public message', + pendingMessages[index].serverId, 'on', this.channelId, 'at', this.serverAPI.baseServerUrl ); - this.chatAPI.emit('publicMessage', { - message, - }); + // eslint-disable-next-line no-await-in-loop + window.NewReceiver.handlePublicMessage(pendingMessages[index]); } - }); + } /* eslint-enable no-param-reassign */ diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 4721cecc8..d339603c8 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -17,14 +17,6 @@ function MessageReceiver() { if (lokiPublicChatAPI) { window.log.info('Binding open group events handler', openGroupBound); if (!openGroupBound) { - // clear any previous binding - lokiPublicChatAPI.removeAllListeners('publicMessage'); - // we only need one MR in the system handling these - // bind events - lokiPublicChatAPI.on( - 'publicMessage', - window.NewReceiver.handlePublicMessage - ); openGroupBound = true; } } else { diff --git a/test/backup_test.js b/test/backup_test.js index a375b7a2d..6bd25b0c5 100644 --- a/test/backup_test.js +++ b/test/backup_test.js @@ -509,7 +509,6 @@ describe('Backup', () => { timestamp: 1524185933350, type: 'private', unreadCount: 0, - sealedSender: 0, version: 2, }; console.log({ conversation }); diff --git a/ts/components/conversation/ContactDetail.tsx b/ts/components/conversation/ContactDetail.tsx index 5a16ddbfe..5d029cad2 100644 --- a/ts/components/conversation/ContactDetail.tsx +++ b/ts/components/conversation/ContactDetail.tsx @@ -20,7 +20,6 @@ import { LocalizerType } from '../../types/Util'; interface Props { contact: Contact; - hasSignalAccount: boolean; i18n: LocalizerType; onSendMessage: () => void; } @@ -73,11 +72,9 @@ function getLabelForAddress( export class ContactDetail extends React.Component { public renderSendMessage({ - hasSignalAccount, i18n, onSendMessage, }: { - hasSignalAccount: boolean; i18n: (key: string, values?: Array) => string; onSendMessage: () => void; }) { @@ -161,7 +158,7 @@ export class ContactDetail extends React.Component { } public render() { - const { contact, hasSignalAccount, i18n, onSendMessage } = this.props; + const { contact, i18n, onSendMessage } = this.props; const isIncoming = false; const module = 'contact-detail'; @@ -172,7 +169,7 @@ export class ContactDetail extends React.Component { {renderName({ contact, isIncoming, module })} {renderContactShorthand({ contact, isIncoming, module })} - {this.renderSendMessage({ hasSignalAccount, i18n, onSendMessage })} + {this.renderSendMessage({ i18n, onSendMessage })} {this.renderPhone(contact.number, i18n)} {this.renderAddresses(contact.address, i18n)} diff --git a/ts/components/conversation/EmbeddedContact.tsx b/ts/components/conversation/EmbeddedContact.tsx index 5db8b717d..4537930b4 100644 --- a/ts/components/conversation/EmbeddedContact.tsx +++ b/ts/components/conversation/EmbeddedContact.tsx @@ -12,7 +12,6 @@ import { interface Props { contact: Contact; - hasSignalAccount: boolean; i18n: LocalizerType; isIncoming: boolean; withContentAbove: boolean; diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index 55a6e77ca..32f2a8e78 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -487,7 +487,6 @@ class MessageInner extends React.PureComponent { return ( { } // TODO: this shouldn't be called when source is not a pubkey!!! + const isOurDevice = await UserUtils.isUs(source); const shouldSendReceipt = @@ -624,18 +625,19 @@ export async function handleMessageEvent(event: MessageEvent): Promise { } // the conversation with the primary device of that source (can be the same as conversationOrigin) + const conversation = ConversationController.getInstance().getOrThrow( conversationId ); - conversation.queueJob(() => { - handleMessageJob( + conversation.queueJob(async () => { + await handleMessageJob( msg, conversation, message, ourNumber, confirm, source - ).ignore(); + ); }); } diff --git a/ts/receiver/errors.ts b/ts/receiver/errors.ts index e9ab1b9df..287717998 100644 --- a/ts/receiver/errors.ts +++ b/ts/receiver/errors.ts @@ -40,7 +40,7 @@ export async function onError(ev: any) { conversation.set({ timestamp: message.get('sent_at') }); } - conversation.trigger('newmessage', message); + conversation.updateLastMessage(); conversation.notify(message); if (ev.confirm) { diff --git a/ts/test/types/Contact_test.ts b/ts/test/types/Contact_test.ts index c35eeee4d..08f395761 100644 --- a/ts/test/types/Contact_test.ts +++ b/ts/test/types/Contact_test.ts @@ -63,7 +63,6 @@ describe('Contact', () => { }); describe('contactSelector', () => { const regionCode = '1'; - const hasSignalAccount = true; const getAbsoluteAttachmentPath = (path: string) => `absolute:${path}`; const onSendMessage = () => null; const onClick = () => null; @@ -91,14 +90,12 @@ describe('Contact', () => { }, organization: 'Somewhere, Inc.', avatar: undefined, - hasSignalAccount, onSendMessage, onClick, number: undefined, }; const actual = contactSelector(contact, { regionCode, - hasSignalAccount, getAbsoluteAttachmentPath, onSendMessage, onClick, @@ -135,14 +132,12 @@ describe('Contact', () => { path: undefined, }, }, - hasSignalAccount, onSendMessage, onClick, number: undefined, }; const actual = contactSelector(contact, { regionCode, - hasSignalAccount, getAbsoluteAttachmentPath, onSendMessage, onClick, @@ -178,14 +173,12 @@ describe('Contact', () => { path: 'absolute:somewhere', }, }, - hasSignalAccount, onSendMessage, onClick, number: undefined, }; const actual = contactSelector(contact, { regionCode, - hasSignalAccount, getAbsoluteAttachmentPath, onSendMessage, onClick, diff --git a/ts/types/Contact.tsx b/ts/types/Contact.tsx index 1307a0054..b87a91dfe 100644 --- a/ts/types/Contact.tsx +++ b/ts/types/Contact.tsx @@ -72,7 +72,6 @@ export function contactSelector( contact: Contact, options: { regionCode: string; - hasSignalAccount: boolean; getAbsoluteAttachmentPath: (path: string) => string; onSendMessage: () => void; onClick: () => void; @@ -80,7 +79,6 @@ export function contactSelector( ) { const { getAbsoluteAttachmentPath, - hasSignalAccount, onClick, onSendMessage, regionCode, @@ -105,7 +103,6 @@ export function contactSelector( return { ...contact, - hasSignalAccount, onSendMessage, onClick, avatar,