Improve safety number logic in group conversations

This commit is contained in:
Scott Nonnenberg 2020-06-09 09:50:36 -07:00
parent 06333aef10
commit 55f4cd591c
4 changed files with 38 additions and 18 deletions

View File

@ -198,10 +198,13 @@
return { wrap, sendOptions };
},
async getAllGroupsInvolvingId(id) {
const groups = await window.Signal.Data.getAllGroupsInvolvingId(id, {
ConversationCollection: Whisper.ConversationCollection,
});
async getAllGroupsInvolvingId(conversationId) {
const groups = await window.Signal.Data.getAllGroupsInvolvingId(
conversationId,
{
ConversationCollection: Whisper.ConversationCollection,
}
);
return groups.map(group => conversations.add(group));
},
loadPromise() {

View File

@ -14,16 +14,18 @@
throw new Error('KeyChangeListener requires a SignalProtocolStore');
}
signalProtocolStore.on('keychange', async id => {
signalProtocolStore.on('keychange', async identifier => {
const conversation = await ConversationController.getOrCreateAndWait(
id,
identifier,
'private'
);
conversation.addKeyChange(id);
conversation.addKeyChange(identifier);
const groups = await ConversationController.getAllGroupsInvolvingId(id);
const groups = await ConversationController.getAllGroupsInvolvingId(
conversation.id
);
_.forEach(groups, group => {
group.addKeyChange(id);
group.addKeyChange(identifier);
});
});
},

View File

@ -37,7 +37,9 @@ describe('KeyChangeListener', () => {
await window.Signal.Data.removeAllMessagesInConversation(convo.id, {
MessageCollection: Whisper.MessageCollection,
});
await window.Signal.Data.saveConversation(convo.id);
await window.Signal.Data.removeConversation(convo.id, {
Conversation: Whisper.Conversation,
});
});
it('generates a key change notice in the private conversation with this contact', done => {
@ -52,29 +54,42 @@ describe('KeyChangeListener', () => {
});
describe('When we have a group with this contact', () => {
let groupConvo;
let convo;
before(async () => {
convo = ConversationController.dangerouslyCreateAndAdd({
id: phoneNumberWithKeyChange,
type: 'private',
});
groupConvo = ConversationController.dangerouslyCreateAndAdd({
id: 'groupId',
type: 'group',
members: [phoneNumberWithKeyChange],
members: [convo.id],
});
await window.Signal.Data.saveConversation(convo.attributes, {
Conversation: Whisper.Conversation,
});
await window.Signal.Data.saveConversation(groupConvo.attributes, {
Conversation: Whisper.Conversation,
});
});
after(async () => {
await window.Signal.Data.removeAllMessagesInConversation(convo.id, {
await window.Signal.Data.removeAllMessagesInConversation(groupConvo.id, {
MessageCollection: Whisper.MessageCollection,
});
await window.Signal.Data.saveConversation(convo.id);
await window.Signal.Data.removeConversation(groupConvo.id, {
Conversation: Whisper.Conversation,
});
await window.Signal.Data.removeConversation(convo.id, {
Conversation: Whisper.Conversation,
});
});
it('generates a key change notice in the group conversation with this contact', done => {
const original = convo.addKeyChange;
convo.addKeyChange = keyChangedId => {
const original = groupConvo.addKeyChange;
groupConvo.addKeyChange = keyChangedId => {
assert.equal(address.getName(), keyChangedId);
convo.addKeyChange = original;
groupConvo.addKeyChange = original;
done();
};

View File

@ -164,7 +164,7 @@
"rule": "jQuery-load(",
"path": "js/conversation_controller.js",
"line": " async load() {",
"lineNumber": 215,
"lineNumber": 218,
"reasonCategory": "falseMatch",
"updated": "2020-03-24T20:06:31.391Z"
},
@ -172,7 +172,7 @@
"rule": "jQuery-load(",
"path": "js/conversation_controller.js",
"line": " this._initialPromise = load();",
"lineNumber": 257,
"lineNumber": 260,
"reasonCategory": "falseMatch",
"updated": "2020-03-24T20:06:31.391Z"
},