From 598d6d1010de41885e45cccb1a265b712983e80c Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 15 Jul 2020 14:32:05 +1000 Subject: [PATCH 1/8] drop auto fr messages 'Please Accept... ' --- ts/receiver/dataMessage.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index c371e6778..12e12419b 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -251,7 +251,10 @@ function isMessageEmpty(message: SignalService.DataMessage) { return ( !flags && - _.isEmpty(body) && + // FIXME remove this hack to drop auto friend requests messages in a few weeks 15/07/2020 + (_.isEmpty(body) || + body === + 'Please accept to enable messages to be synced across devices') && _.isEmpty(attachments) && _.isEmpty(group) && _.isEmpty(quote) && From 17cae3937dc885459084224f3cee0e6b86ddc30b Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 15 Jul 2020 16:30:47 +1000 Subject: [PATCH 2/8] drop synced message with the autoFR content --- ts/receiver/dataMessage.ts | 14 +++++++++++--- ts/receiver/syncMessages.ts | 11 ++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 12e12419b..7651951f4 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -252,9 +252,7 @@ function isMessageEmpty(message: SignalService.DataMessage) { return ( !flags && // FIXME remove this hack to drop auto friend requests messages in a few weeks 15/07/2020 - (_.isEmpty(body) || - body === - 'Please accept to enable messages to be synced across devices') && + isBodyEmpty(body) && _.isEmpty(attachments) && _.isEmpty(group) && _.isEmpty(quote) && @@ -265,6 +263,16 @@ function isMessageEmpty(message: SignalService.DataMessage) { ); } +function isBodyEmpty(body: string) { + return _.isEmpty(body) || isBodyAutoFRContent(body); +} + +export function isBodyAutoFRContent(body: string) { + return ( + body === 'Please accept to enable messages to be synced across devices' + ); +} + export async function handleDataMessage( envelope: EnvelopePlus, dataMessage: SignalService.IDataMessage diff --git a/ts/receiver/syncMessages.ts b/ts/receiver/syncMessages.ts index d4d574bc7..61bb16c41 100644 --- a/ts/receiver/syncMessages.ts +++ b/ts/receiver/syncMessages.ts @@ -7,7 +7,11 @@ import ByteBuffer from 'bytebuffer'; import { handleEndSession } from './sessionHandling'; import { handleMediumGroupUpdate } from './mediumGroups'; -import { handleMessageEvent, processDecrypted } from './dataMessage'; +import { + handleMessageEvent, + isBodyAutoFRContent, + processDecrypted, +} from './dataMessage'; import { updateProfile } from './receiver'; import { handleContacts } from './multidevice'; import { onGroupReceived } from './groups'; @@ -84,6 +88,11 @@ async function handleSentMessage( if (!msg) { window.log('Inner message is missing in a sync message'); + return; + } + + if (msg.body && isBodyAutoFRContent(msg.body)) { + window.console.log('dropping autoFR message synced'); await removeFromCache(envelope); return; } From 0c8e34a78e2de7536c891eb9bf4cca6531ea8467 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 16 Jul 2020 09:41:16 +1000 Subject: [PATCH 3/8] remove envelope from cache if sentMessage is empty --- ts/receiver/syncMessages.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ts/receiver/syncMessages.ts b/ts/receiver/syncMessages.ts index 61bb16c41..c4cf355f1 100644 --- a/ts/receiver/syncMessages.ts +++ b/ts/receiver/syncMessages.ts @@ -88,6 +88,7 @@ async function handleSentMessage( if (!msg) { window.log('Inner message is missing in a sync message'); + await removeFromCache(envelope); return; } From 9df0a79fb9832c6835177c78719bdf3a2b8fc6f8 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 16 Jul 2020 10:24:13 +1000 Subject: [PATCH 4/8] remove blockedNumber.js --- js/models/blockedNumbers.js | 83 ------------------------------------- ts/receiver/multidevice.ts | 7 ---- 2 files changed, 90 deletions(-) delete mode 100644 js/models/blockedNumbers.js diff --git a/js/models/blockedNumbers.js b/js/models/blockedNumbers.js deleted file mode 100644 index cb24c6466..000000000 --- a/js/models/blockedNumbers.js +++ /dev/null @@ -1,83 +0,0 @@ -/* global storage, _ */ -/* global _: false */ -/* global Backbone: false */ - -/* global BlockedNumberController: false */ -/* global storage: false */ -/* global Whisper: false */ - -/* eslint-disable more/no-then */ - -// eslint-disable-next-line func-names -(function() { - 'use strict'; - - window.Whisper = window.Whisper || {}; - - const BLOCKED_NUMBERS_ID = 'blocked'; - const BLOCKED_GROUPS_ID = 'blocked-groups'; - - storage.isBlocked = number => { - const numbers = storage.get(BLOCKED_NUMBERS_ID, []); - - return _.include(numbers, number); - }; - storage.getBlockedNumbers = () => storage.get(BLOCKED_NUMBERS_ID, []); - storage.addBlockedNumber = number => { - const numbers = storage.get(BLOCKED_NUMBERS_ID, []); - if (_.include(numbers, number)) { - return; - } - - window.log.info('adding', number, 'to blocked list'); - storage.put(BLOCKED_NUMBERS_ID, numbers.concat(number)); - }; - storage.removeBlockedNumber = number => { - const numbers = storage.get(BLOCKED_NUMBERS_ID, []); - if (!_.include(numbers, number)) { - return; - } - - window.log.info('removing', number, 'from blocked list'); - storage.put(BLOCKED_NUMBERS_ID, _.without(numbers, number)); - }; - - storage.isGroupBlocked = groupId => { - const groupIds = storage.get(BLOCKED_GROUPS_ID, []); - - return _.include(groupIds, groupId); - }; - storage.removeBlockedGroup = groupId => { - const groupIds = storage.get(BLOCKED_GROUPS_ID, []); - if (!_.include(groupIds, groupId)) { - return; - } - - window.log.info(`removing group(${groupId} from blocked list`); - storage.put(BLOCKED_GROUPS_ID, _.without(groupIds, groupId)); - }; - - Whisper.BlockedNumber = Backbone.Model.extend({ - defaults() { - return { - number: '', - }; - }, - block() { - return BlockedNumberController.block(this.number); - }, - unblock() { - return BlockedNumberController.unblock(this.number); - }, - }); - - Whisper.BlockedNumberCollection = Backbone.Collection.extend({ - model: Whisper.BlockedNumber, - comparator(m) { - return m.get('number'); - }, - getModel(number) { - return this.models.find(m => m.get('number') === number); - }, - }); -})(); diff --git a/ts/receiver/multidevice.ts b/ts/receiver/multidevice.ts index 9633c3247..eda7c3cba 100644 --- a/ts/receiver/multidevice.ts +++ b/ts/receiver/multidevice.ts @@ -366,13 +366,6 @@ async function onContactReceived(details: any) { conversation.setProfileKey(profileKey); } - if (details.blocked !== 'undefined') { - if (details.blocked) { - storage.addBlockedNumber(id); - } else { - storage.removeBlockedNumber(id); - } - } // Do not set name to allow working with lokiProfile and nicknames conversation.set({ From 3775a9ef050437d3ac98363337c834f273630889 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 16 Jul 2020 11:41:09 +1000 Subject: [PATCH 5/8] drop empty synced message (or autoFR) --- ts/receiver/dataMessage.ts | 4 ++-- ts/receiver/syncMessages.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 7651951f4..24de0c604 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -236,7 +236,7 @@ export async function processDecrypted(envelope: EnvelopePlus, decrypted: any) { /* tslint:disable:no-bitwise */ } -function isMessageEmpty(message: SignalService.DataMessage) { +export function isMessageEmpty(message: SignalService.DataMessage) { const { flags, body, @@ -267,7 +267,7 @@ function isBodyEmpty(body: string) { return _.isEmpty(body) || isBodyAutoFRContent(body); } -export function isBodyAutoFRContent(body: string) { +function isBodyAutoFRContent(body: string) { return ( body === 'Please accept to enable messages to be synced across devices' ); diff --git a/ts/receiver/syncMessages.ts b/ts/receiver/syncMessages.ts index c4cf355f1..94b56e432 100644 --- a/ts/receiver/syncMessages.ts +++ b/ts/receiver/syncMessages.ts @@ -9,13 +9,14 @@ import { handleEndSession } from './sessionHandling'; import { handleMediumGroupUpdate } from './mediumGroups'; import { handleMessageEvent, - isBodyAutoFRContent, + isMessageEmpty, processDecrypted, } from './dataMessage'; import { updateProfile } from './receiver'; import { handleContacts } from './multidevice'; import { onGroupReceived } from './groups'; import { MultiDeviceProtocol } from '../session/protocols'; +import { DataMessage } from '../session/messages/outgoing'; export async function handleSyncMessage( envelope: EnvelopePlus, @@ -92,8 +93,8 @@ async function handleSentMessage( return; } - if (msg.body && isBodyAutoFRContent(msg.body)) { - window.console.log('dropping autoFR message synced'); + if (isMessageEmpty(msg as SignalService.DataMessage)) { + window.console.log('dropping empty message synced'); await removeFromCache(envelope); return; } From ba7241b2cb8fd5e9836ea775b8f2b8281a968447 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 16 Jul 2020 11:41:38 +1000 Subject: [PATCH 6/8] contactSync: mark conversation as secondary when they are --- ts/receiver/multidevice.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ts/receiver/multidevice.ts b/ts/receiver/multidevice.ts index eda7c3cba..e9e1187c3 100644 --- a/ts/receiver/multidevice.ts +++ b/ts/receiver/multidevice.ts @@ -340,10 +340,10 @@ async function onContactReceived(details: any) { } const ourPrimaryKey = window.storage.get('primaryDevicePubKey'); if (ourPrimaryKey) { - const secondaryDevices = await MultiDeviceProtocol.getSecondaryDevices( + const ourSecondaryDevices = await MultiDeviceProtocol.getSecondaryDevices( ourPrimaryKey ); - if (secondaryDevices.some(device => device.key === id)) { + if (ourSecondaryDevices.some(device => device.key === id)) { await conversation.setSecondaryStatus(true, ourPrimaryKey); } } @@ -354,6 +354,17 @@ async function onContactReceived(details: any) { ConversationController.getOrCreateAndWait(d.key, 'private') ) ); + const secondaryDevices = await MultiDeviceProtocol.getSecondaryDevices(id); + await Promise.all( + secondaryDevices.map(async d => { + const secondaryConv = await ConversationController.getOrCreateAndWait( + d.key, + 'private' + ); + await secondaryConv.setSecondaryStatus(true, id); + }) + ); + // triger session request with every devices of that user // when we do not have a session with it already deviceConversations.forEach(device => { From 9a5c73af3cc471e32f2486dbf4c4e4b314d09f2e Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 16 Jul 2020 11:41:59 +1000 Subject: [PATCH 7/8] do not update loki display name is given string is '' onContactSync --- ts/receiver/multidevice.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ts/receiver/multidevice.ts b/ts/receiver/multidevice.ts index e9e1187c3..7824882b4 100644 --- a/ts/receiver/multidevice.ts +++ b/ts/receiver/multidevice.ts @@ -377,16 +377,17 @@ async function onContactReceived(details: any) { conversation.setProfileKey(profileKey); } - // Do not set name to allow working with lokiProfile and nicknames conversation.set({ // name: details.name, color: details.color, }); - await conversation.setLokiProfile({ displayName: details.name }); + if (details.name && details.name.length) { + await conversation.setLokiProfile({ displayName: details.name }); + } - if (details.nickname) { + if (details.nickname && details.nickname.length) { await conversation.setNickname(details.nickname); } From b04a64da8ce67fc8bc849f3dcc1d81f991c28cc8 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 16 Jul 2020 14:08:53 +1000 Subject: [PATCH 8/8] mark secondary devices as secondary from the right primary key --- ts/receiver/multidevice.ts | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/ts/receiver/multidevice.ts b/ts/receiver/multidevice.ts index 7824882b4..6dd9142b6 100644 --- a/ts/receiver/multidevice.ts +++ b/ts/receiver/multidevice.ts @@ -338,33 +338,29 @@ async function onContactReceived(details: any) { activeAt = activeAt || Date.now(); conversation.set('active_at', activeAt); } - const ourPrimaryKey = window.storage.get('primaryDevicePubKey'); - if (ourPrimaryKey) { - const ourSecondaryDevices = await MultiDeviceProtocol.getSecondaryDevices( - ourPrimaryKey - ); - if (ourSecondaryDevices.some(device => device.key === id)) { - await conversation.setSecondaryStatus(true, ourPrimaryKey); - } - } - const devices = await MultiDeviceProtocol.getAllDevices(id); - const deviceConversations = await Promise.all( - devices.map(d => - ConversationController.getOrCreateAndWait(d.key, 'private') - ) - ); + const primaryDevice = await MultiDeviceProtocol.getPrimaryDevice(id); const secondaryDevices = await MultiDeviceProtocol.getSecondaryDevices(id); - await Promise.all( + const primaryConversation = await ConversationController.getOrCreateAndWait( + primaryDevice.key, + 'private' + ); + const secondaryConversations = await Promise.all( secondaryDevices.map(async d => { const secondaryConv = await ConversationController.getOrCreateAndWait( d.key, 'private' ); - await secondaryConv.setSecondaryStatus(true, id); + await secondaryConv.setSecondaryStatus(true, primaryDevice.key); + return conversation; }) ); + const deviceConversations = [ + primaryConversation, + ...secondaryConversations, + ]; + // triger session request with every devices of that user // when we do not have a session with it already deviceConversations.forEach(device => {