Skip to content

Commit

Permalink
Closed group fixes. (#816)
Browse files Browse the repository at this point in the history
* Fix group updates not syning

* Fix leaving closed groups

* Fix incorrect members being shown on create group dialog

* Linting

* Fix create closed group showing our own conversation
  • Loading branch information
Mikunj authored Feb 10, 2020
1 parent e4a48f8 commit beb4cdb
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 37 deletions.
5 changes: 5 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,11 @@
"message": "Leave Closed Group",
"description": "Button action that the user can click to leave the group"
},
"leaveClosedGroupConfirmation": {
"message": "Leave this Closed Group?",
"description":
"Confirmation dialog text that tells the user what will happen if they leave the closed group."
},
"leaveGroupDialogTitle": {
"message": "Are you sure you want to leave this group?",
"description":
Expand Down
30 changes: 18 additions & 12 deletions js/conversation_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,32 @@
if (!conversation) {
return;
}
if (conversation.isPublic()) {

// Close group leaving
if (conversation.isClosedGroup()) {
await conversation.leaveGroup();
} else if (conversation.isPublic()) {
const channelAPI = await conversation.getPublicSendData();
if (channelAPI === null) {
log.warn(`Could not get API for public conversation ${id}`);
} else {
channelAPI.serverAPI.partChannel(channelAPI.channelId);
}
} else if (conversation.isPrivate()) {
const deviceIds = await textsecure.storage.protocol.getDeviceIds(id);
await Promise.all(
deviceIds.map(deviceId => {
const address = new libsignal.SignalProtocolAddress(id, deviceId);
const sessionCipher = new libsignal.SessionCipher(
textsecure.storage.protocol,
address
);
return sessionCipher.deleteAllSessionsForDevice();
})
);
}

await conversation.destroyMessages();
const deviceIds = await textsecure.storage.protocol.getDeviceIds(id);
await Promise.all(
deviceIds.map(deviceId => {
const address = new libsignal.SignalProtocolAddress(id, deviceId);
const sessionCipher = new libsignal.SessionCipher(
textsecure.storage.protocol,
address
);
return sessionCipher.deleteAllSessionsForDevice();
})
);
await window.Signal.Data.removeConversation(id, {
Conversation: Whisper.Conversation,
});
Expand Down
23 changes: 17 additions & 6 deletions js/models/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@
isPublic() {
return !!(this.id && this.id.match(/^publicChat:/));
},
isClosedGroup() {
return (
this.get('type') === Message.GROUP && !this.isPublic() && !this.isRss()
);
},
isClosable() {
return !this.isRss() || this.get('closable');
},
Expand Down Expand Up @@ -881,6 +886,9 @@
throw new Error('Invalid friend request state');
}
},
isOurConversation() {
return this.id === this.ourNumber;
},
isSecondaryDevice() {
return !!this.get('secondaryStatus');
},
Expand Down Expand Up @@ -2712,13 +2720,16 @@
},

deleteContact() {
const title = this.isPublic()
? i18n('deletePublicChannel')
: i18n('deleteContact');
let title = i18n('deleteContact');
let message = i18n('deleteContactConfirmation');

const message = this.isPublic()
? i18n('deletePublicChannelConfirmation')
: i18n('deleteContactConfirmation');
if (this.isPublic()) {
title = i18n('deletePublicChannel');
message = i18n('deletePublicChannelConfirmation');
} else if (this.isClosedGroup()) {
title = i18n('leaveClosedGroup');
message = i18n('leaveClosedGroupConfirmation');
}

window.confirmationDialog({
title,
Expand Down
15 changes: 9 additions & 6 deletions js/views/app_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,16 @@
this.el.append(dialog.el);
},
showLeaveGroupDialog(groupConvo) {
const title = groupConvo.isPublic()
? i18n('deletePublicChannel')
: i18n('deleteContact');
let title = i18n('deleteContact');
let message = i18n('deleteContactConfirmation');

const message = groupConvo.isPublic()
? i18n('deletePublicChannelConfirmation')
: i18n('deleteContactConfirmation');
if (groupConvo.isPublic()) {
title = i18n('deletePublicChannel');
message = i18n('deletePublicChannelConfirmation');
} else if (groupConvo.isClosedGroup()) {
title = i18n('leaveClosedGroup');
message = i18n('leaveClosedGroupConfirmation');
}

window.confirmationDialog({
title,
Expand Down
10 changes: 6 additions & 4 deletions libtextsecure/sendmessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,10 @@ MessageSender.prototype = {
},

async sendContactSyncMessage(contactConversation) {
if (!contactConversation.isPrivate()) {
return Promise.resolve();
}

const primaryDeviceKey = window.storage.get('primaryDevicePubKey');
const allOurDevices = (await libloki.storage.getAllDevicePubKeysForPrimaryPubKey(
primaryDeviceKey
Expand Down Expand Up @@ -869,9 +873,7 @@ MessageSender.prototype = {
},

sendGroupProto(providedNumbers, proto, timestamp = Date.now(), options = {}) {
const me = textsecure.storage.user.getNumber();
const numbers = providedNumbers.filter(number => number !== me);
if (numbers.length === 0) {
if (providedNumbers.length === 0) {
return Promise.resolve({
successfulNumbers: [],
failoverNumbers: [],
Expand All @@ -894,7 +896,7 @@ MessageSender.prototype = {

this.sendMessageProto(
timestamp,
numbers,
providedNumbers,
proto,
callback,
silent,
Expand Down
3 changes: 2 additions & 1 deletion ts/components/session/LeftPaneMessageSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
this.state = {
showComposeView: false,
pubKeyPasted: '',
shouldRenderMessageOnboarding: length === 0 && renderOnboardingSetting && false,
shouldRenderMessageOnboarding:
length === 0 && renderOnboardingSetting && false,
connectSuccess: false,
loading: false,
};
Expand Down
18 changes: 10 additions & 8 deletions ts/components/session/SessionClosableOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ export class SessionClosableOverlay extends React.Component<Props, State> {
}

public getContacts() {
const conversations = window.getConversations();

let conversationList = conversations;
if (conversationList !== undefined) {
conversationList = conversationList.filter((conv: any) => {
return !conv.isRss() && !conv.isPublic() && conv.attributes.lastMessage;
});
}
const conversations = window.getConversations() || [];

const conversationList = conversations.filter((conversation: any) => {
return (
!conversation.isOurConversation() &&
conversation.isPrivate() &&
!conversation.isSecondaryDevice() &&
conversation.isFriend()
);
});

return conversationList.map((d: any) => {
const lokiProfile = d.getLokiProfile();
Expand Down

0 comments on commit beb4cdb

Please sign in to comment.