mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
aed5735620
Bind a single listener to keychange events from the storage interface, which then looks up relevant conversations and adds notices to them, with tests. Previously we would need to instantiate a conversation model in order to start listening to its key change events. In practice this usually happens at startup but we shouldn't rely on it, and it incurs higher overhead since it creates a different listener for each conversation. // FREEBIE
30 lines
923 B
JavaScript
30 lines
923 B
JavaScript
/*
|
|
* vim: ts=4:sw=4:expandtab
|
|
*/
|
|
|
|
;(function () {
|
|
'use strict';
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
Whisper.KeyChangeListener = {
|
|
init: function(signalProtocolStore) {
|
|
if (!(signalProtocolStore instanceof SignalProtocolStore)) {
|
|
throw new Error('KeyChangeListener requires a SignalProtocolStore');
|
|
}
|
|
|
|
signalProtocolStore.on('keychange', function(id) {
|
|
var conversation = ConversationController.add({id: id});
|
|
conversation.fetch().then(function() {
|
|
conversation.addKeyChange(id);
|
|
});
|
|
var groups = new Whisper.GroupCollection();
|
|
return groups.fetchGroups(id).then(function() {
|
|
groups.each(function(conversation) {
|
|
conversation = ConversationController.add(conversation);
|
|
conversation.addKeyChange(id);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
};
|
|
}());
|