Bring back conversation.leaveGroup for GV1 scenarios

This commit is contained in:
Chris Svenningsen 2020-09-30 16:49:41 -07:00 committed by Josh Perez
parent 04eb7bc995
commit 7b15bddfc9
2 changed files with 55 additions and 7 deletions

View File

@ -2793,6 +2793,43 @@ export class ConversationModel extends window.Backbone.Model<
}
}
async leaveGroup(): Promise<void> {
const now = Date.now();
if (this.get('type') === 'group') {
const groupIdentifiers = this.getRecipients();
this.set({ left: true });
window.Signal.Data.updateConversation(this.attributes);
const model = new Whisper.Message(({
group_update: { left: 'You' },
conversationId: this.id,
type: 'outgoing',
sent_at: now,
received_at: now,
// TODO: DESKTOP-722
} as unknown) as MessageAttributesType);
const id = await window.Signal.Data.saveMessage(model.attributes, {
Message: Whisper.Message,
});
model.set({ id });
const message = window.MessageController.register(model.id, model);
this.addSingleMessage(message);
const options = this.getSendOptions();
message.send(
this.wrapSend(
window.textsecure.messaging.leaveGroup(
this.id,
groupIdentifiers,
options
)
)
);
}
}
async markRead(
newestUnreadDate: number,
providedOptions: { readAt?: number; sendReadReceipts: boolean }

View File

@ -1372,9 +1372,7 @@ export default class MessageSender {
proto: DataMessageClass,
timestamp = Date.now(),
options = {}
): Promise<
CallbackResultType | Omit<CallbackResultType, 'discoveredIdentifierPairs'>
> {
): Promise<CallbackResultType> {
const myE164 = window.textsecure.storage.user.getNumber();
const myUuid = window.textsecure.storage.user.getUuid();
const identifiers = providedIdentifiers.filter(
@ -1383,11 +1381,12 @@ export default class MessageSender {
if (identifiers.length === 0) {
return Promise.resolve({
successfulIdentifiers: [],
failoverIdentifiers: [],
errors: [],
unidentifiedDeliveries: [],
dataMessage: proto.toArrayBuffer(),
discoveredIdentifierPairs: [],
errors: [],
failoverIdentifiers: [],
successfulIdentifiers: [],
unidentifiedDeliveries: [],
});
}
@ -1686,6 +1685,18 @@ export default class MessageSender {
return this.server.modifyGroup(changes, options);
}
async leaveGroup(
groupId: string,
groupIdentifiers: Array<string>,
options?: SendOptionsType
): Promise<CallbackResultType> {
const proto = new window.textsecure.protobuf.DataMessage();
proto.group = new window.textsecure.protobuf.GroupContext();
proto.group.id = stringToArrayBuffer(groupId);
proto.group.type = window.textsecure.protobuf.GroupContext.Type.QUIT;
return this.sendGroupProto(groupIdentifiers, proto, Date.now(), options);
}
async sendExpirationTimerUpdateToGroup(
groupId: string,
groupIdentifiers: Array<string>,