Signal-Desktop/js/keychange_listener.js

35 lines
982 B
JavaScript
Raw Normal View History

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