handle sync of blocked contact/groups as sync events

pull/1250/head
Audric Ackermann 5 years ago
parent 66697bc235
commit 45cdbcbb2f
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -253,6 +253,11 @@
this.trigger('change', this); this.trigger('change', this);
this.messageCollection.forEach(m => m.trigger('change')); this.messageCollection.forEach(m => m.trigger('change'));
this.updateTextInputState(); this.updateTextInputState();
if (this.isPrivate()) {
await textsecure.messaging.sendContactSyncMessage([this]);
} else {
await textsecure.messaging.sendGroupSyncMessage([this]);
}
}, },
async unblock() { async unblock() {
if (!this.id || this.isPublic() || this.isRss()) { if (!this.id || this.isPublic() || this.isRss()) {
@ -265,6 +270,11 @@
this.trigger('change', this); this.trigger('change', this);
this.messageCollection.forEach(m => m.trigger('change')); this.messageCollection.forEach(m => m.trigger('change'));
this.updateTextInputState(); this.updateTextInputState();
if (this.isPrivate()) {
await textsecure.messaging.sendContactSyncMessage([this]);
} else {
await textsecure.messaging.sendGroupSyncMessage([this]);
}
}, },
setMessageSelectionBackdrop() { setMessageSelectionBackdrop() {
const messageSelected = this.selectedMessages.size > 0; const messageSelected = this.selectedMessages.size > 0;

@ -653,7 +653,7 @@
const conversations = window.getConversations().models; const conversations = window.getConversations().models;
await textsecure.messaging.sendGroupSyncMessage(conversations); await textsecure.messaging.sendGroupSyncMessage(conversations);
await textsecure.messaging.sendOpenGroupsSyncMessage(conversations); await textsecure.messaging.sendOpenGroupsSyncMessage(conversations);
await textsecure.messaging.sendContactSyncMessage(conversations); await textsecure.messaging.sendContactSyncMessage();
}, 5000); }, 5000);
}, },
validatePubKeyHex(pubKey) { validatePubKeyHex(pubKey) {

@ -360,8 +360,13 @@ MessageSender.prototype = {
}); });
}, },
async sendContactSyncMessage() { async sendContactSyncMessage(convos) {
const convosToSync = await libsession.Utils.SyncMessageUtils.getSyncContacts(); let convosToSync;
if (!convos) {
convosToSync = await libsession.Utils.SyncMessageUtils.getSyncContacts();
} else {
convosToSync = convos;
}
if (convosToSync.size === 0) { if (convosToSync.size === 0) {
window.console.info('No contacts to sync.'); window.console.info('No contacts to sync.');
@ -397,11 +402,7 @@ MessageSender.prototype = {
} }
// We only want to sync across closed groups that we haven't left // We only want to sync across closed groups that we haven't left
const sessionGroups = conversations.filter( const sessionGroups = conversations.filter(
c => c => c.isClosedGroup() && !c.get('left') && !c.isMediumGroup()
c.isClosedGroup() &&
!c.get('left') &&
!c.isBlocked() &&
!c.isMediumGroup()
); );
if (sessionGroups.length === 0) { if (sessionGroups.length === 0) {
window.console.info('No closed group to sync.'); window.console.info('No closed group to sync.');

@ -146,13 +146,7 @@ interface GroupInfo {
} }
export async function onGroupReceived(details: GroupInfo) { export async function onGroupReceived(details: GroupInfo) {
const { const { ConversationController, libloki, textsecure, Whisper } = window;
ConversationController,
libloki,
storage,
textsecure,
Whisper,
} = window;
const { id } = details; const { id } = details;
@ -204,6 +198,13 @@ export async function onGroupReceived(details: GroupInfo) {
); );
conversation.set(newAttributes); conversation.set(newAttributes);
} }
const isBlocked = details.blocked || false;
if (conversation.isClosedGroup()) {
await BlockedNumberController.setGroupBlocked(conversation.id, isBlocked);
}
conversation.trigger('change', conversation);
conversation.updateTextInputState();
await window.Signal.Data.updateConversation(id, conversation.attributes, { await window.Signal.Data.updateConversation(id, conversation.attributes, {
Conversation: Whisper.Conversation, Conversation: Whisper.Conversation,

@ -12,6 +12,7 @@ import { MultiDeviceProtocol, SessionProtocol } from '../session/protocols';
import { PubKey } from '../session/types'; import { PubKey } from '../session/types';
import ByteBuffer from 'bytebuffer'; import ByteBuffer from 'bytebuffer';
import { BlockedNumberController } from '../util';
async function unpairingRequestIsLegit(source: string, ourPubKey: string) { async function unpairingRequestIsLegit(source: string, ourPubKey: string) {
const { textsecure, storage, lokiFileServerAPI } = window; const { textsecure, storage, lokiFileServerAPI } = window;
@ -287,6 +288,7 @@ export async function handleContacts(
await removeFromCache(envelope); await removeFromCache(envelope);
} }
// tslint:disable-next-line: max-func-body-length
async function onContactReceived(details: any) { async function onContactReceived(details: any) {
const { const {
ConversationController, ConversationController,
@ -427,7 +429,15 @@ async function onContactReceived(details: any) {
verifiedEvent.viaContactSync = true; verifiedEvent.viaContactSync = true;
await onVerified(verifiedEvent); await onVerified(verifiedEvent);
} }
await conversation.trigger('change');
const isBlocked = details.blocked || false;
if (conversation.isPrivate()) {
await BlockedNumberController.setBlocked(conversation.id, isBlocked);
}
conversation.updateTextInputState();
await conversation.trigger('change', conversation);
} catch (error) { } catch (error) {
window.log.error('onContactReceived error:', Errors.toLogFormat(error)); window.log.error('onContactReceived error:', Errors.toLogFormat(error));
} }

@ -89,6 +89,26 @@ export class BlockedNumberController {
} }
} }
public static async setBlocked(
user: string | PubKey,
blocked: boolean
): Promise<void> {
if (blocked) {
return BlockedNumberController.block(user);
}
return BlockedNumberController.unblock(user);
}
public static async setGroupBlocked(
groupId: string | PubKey,
blocked: boolean
): Promise<void> {
if (blocked) {
return BlockedNumberController.blockGroup(groupId);
}
return BlockedNumberController.unblockGroup(groupId);
}
public static async blockGroup(groupId: string | PubKey): Promise<void> { public static async blockGroup(groupId: string | PubKey): Promise<void> {
await this.load(); await this.load();
const id = PubKey.cast(groupId); const id = PubKey.cast(groupId);

Loading…
Cancel
Save