session-desktop/js/keychange_listener.js
lilia aed5735620 Improve keychange notice reliability/perf
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
2017-05-09 15:41:41 -07:00

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);
});
});
});
}
};
}());