2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2017-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-07-07 00:48:14 +00:00
|
|
|
/* global Whisper, SignalProtocolStore, ConversationController, _ */
|
|
|
|
|
|
|
|
/* eslint-disable more/no-then */
|
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2020-11-18 15:15:42 +00:00
|
|
|
(function () {
|
2018-04-27 21:25:04 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
2017-05-07 21:18:22 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
Whisper.KeyChangeListener = {
|
2018-07-07 00:48:14 +00:00
|
|
|
init(signalProtocolStore) {
|
2018-04-27 21:25:04 +00:00
|
|
|
if (!(signalProtocolStore instanceof SignalProtocolStore)) {
|
|
|
|
throw new Error('KeyChangeListener requires a SignalProtocolStore');
|
|
|
|
}
|
2017-05-07 21:18:22 +00:00
|
|
|
|
2020-06-09 16:50:36 +00:00
|
|
|
signalProtocolStore.on('keychange', async identifier => {
|
2018-09-21 01:47:19 +00:00
|
|
|
const conversation = await ConversationController.getOrCreateAndWait(
|
2020-06-09 16:50:36 +00:00
|
|
|
identifier,
|
2018-09-21 01:47:19 +00:00
|
|
|
'private'
|
2018-07-07 00:48:14 +00:00
|
|
|
);
|
2020-06-09 16:50:36 +00:00
|
|
|
conversation.addKeyChange(identifier);
|
2018-09-21 01:47:19 +00:00
|
|
|
|
2020-06-09 16:50:36 +00:00
|
|
|
const groups = await ConversationController.getAllGroupsInvolvingId(
|
|
|
|
conversation.id
|
|
|
|
);
|
2018-09-21 01:47:19 +00:00
|
|
|
_.forEach(groups, group => {
|
2020-06-09 16:50:36 +00:00
|
|
|
group.addKeyChange(identifier);
|
2018-09-21 01:47:19 +00:00
|
|
|
});
|
2018-04-27 21:25:04 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
})();
|