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

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

@ -360,8 +360,13 @@ MessageSender.prototype = {
});
},
async sendContactSyncMessage() {
const convosToSync = await libsession.Utils.SyncMessageUtils.getSyncContacts();
async sendContactSyncMessage(convos) {
let convosToSync;
if (!convos) {
convosToSync = await libsession.Utils.SyncMessageUtils.getSyncContacts();
} else {
convosToSync = convos;
}
if (convosToSync.size === 0) {
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
const sessionGroups = conversations.filter(
c =>
c.isClosedGroup() &&
!c.get('left') &&
!c.isBlocked() &&
!c.isMediumGroup()
c => c.isClosedGroup() && !c.get('left') && !c.isMediumGroup()
);
if (sessionGroups.length === 0) {
window.console.info('No closed group to sync.');

@ -146,13 +146,7 @@ interface GroupInfo {
}
export async function onGroupReceived(details: GroupInfo) {
const {
ConversationController,
libloki,
storage,
textsecure,
Whisper,
} = window;
const { ConversationController, libloki, textsecure, Whisper } = window;
const { id } = details;
@ -204,6 +198,13 @@ export async function onGroupReceived(details: GroupInfo) {
);
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, {
Conversation: Whisper.Conversation,

@ -12,6 +12,7 @@ import { MultiDeviceProtocol, SessionProtocol } from '../session/protocols';
import { PubKey } from '../session/types';
import ByteBuffer from 'bytebuffer';
import { BlockedNumberController } from '../util';
async function unpairingRequestIsLegit(source: string, ourPubKey: string) {
const { textsecure, storage, lokiFileServerAPI } = window;
@ -287,6 +288,7 @@ export async function handleContacts(
await removeFromCache(envelope);
}
// tslint:disable-next-line: max-func-body-length
async function onContactReceived(details: any) {
const {
ConversationController,
@ -427,7 +429,15 @@ async function onContactReceived(details: any) {
verifiedEvent.viaContactSync = true;
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) {
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> {
await this.load();
const id = PubKey.cast(groupId);

Loading…
Cancel
Save