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/dataMessage.ts b/ts/receiver/dataMessage.ts index c371e6778..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, @@ -251,7 +251,8 @@ 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 + isBodyEmpty(body) && _.isEmpty(attachments) && _.isEmpty(group) && _.isEmpty(quote) && @@ -262,6 +263,16 @@ function isMessageEmpty(message: SignalService.DataMessage) { ); } +function isBodyEmpty(body: string) { + return _.isEmpty(body) || isBodyAutoFRContent(body); +} + +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/multidevice.ts b/ts/receiver/multidevice.ts index 9633c3247..6dd9142b6 100644 --- a/ts/receiver/multidevice.ts +++ b/ts/receiver/multidevice.ts @@ -338,22 +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 secondaryDevices = await MultiDeviceProtocol.getSecondaryDevices( - ourPrimaryKey - ); - if (secondaryDevices.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); + 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, 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 => { @@ -366,23 +373,17 @@ 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({ // 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); } diff --git a/ts/receiver/syncMessages.ts b/ts/receiver/syncMessages.ts index d4d574bc7..94b56e432 100644 --- a/ts/receiver/syncMessages.ts +++ b/ts/receiver/syncMessages.ts @@ -7,11 +7,16 @@ import ByteBuffer from 'bytebuffer'; import { handleEndSession } from './sessionHandling'; import { handleMediumGroupUpdate } from './mediumGroups'; -import { handleMessageEvent, processDecrypted } from './dataMessage'; +import { + handleMessageEvent, + 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, @@ -88,6 +93,12 @@ async function handleSentMessage( return; } + if (isMessageEmpty(msg as SignalService.DataMessage)) { + window.console.log('dropping empty message synced'); + await removeFromCache(envelope); + return; + } + const { ConversationController } = window; // tslint:disable-next-line no-bitwise