Singleton models need an id attribute via its getter

Setting it on the model itself is not sufficient and then causes
changes which should be type `update` become type `create`, causing
multiple versions of the model... resulting in chaos.
This commit is contained in:
JC Brand 2018-08-22 20:03:04 +02:00
parent f01b6c29c8
commit 76a2192afa
2 changed files with 79 additions and 79 deletions

142
dist/converse.js vendored
View File

@ -36,34 +36,19 @@
/******/ // define getter function for harmony exports /******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) { /******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) { /******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ } /******/ }
/******/ }; /******/ };
/******/ /******/
/******/ // define __esModule on exports /******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) { /******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ }; /******/ };
/******/ /******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules /******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) { /******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ? /******/ var getter = module && module.__esModule ?
@ -2575,7 +2560,13 @@ backbone.nativeview = __webpack_require__(/*! backbone.nativeview */ "./node_mod
if (_.isFunction(this.beforeRender)) { if (_.isFunction(this.beforeRender)) {
this.beforeRender(); this.beforeRender();
} }
const new_vnode = tovnode.toVNode(parseHTMLToDOM(this.toHTML())); let new_vnode;
if (!_.isNil(this.toHTML)) {
new_vnode = tovnode.toVNode(parseHTMLToDOM(this.toHTML()));
} else {
new_vnode = tovnode.toVNode(this.toDOM());
}
new_vnode.data.hook = _.extend({ new_vnode.data.hook = _.extend({
create: this.updateEventListeners.bind(this), create: this.updateEventListeners.bind(this),
update: this.updateEventListeners.bind(this) update: this.updateEventListeners.bind(this)
@ -27154,12 +27145,13 @@ var map = {
function webpackContext(req) { function webpackContext(req) {
var id = webpackContextResolve(req); var id = webpackContextResolve(req);
return __webpack_require__(id); var module = __webpack_require__(id);
return module;
} }
function webpackContextResolve(req) { function webpackContextResolve(req) {
var id = map[req]; var id = map[req];
if(!(id + 1)) { // check for number or string if(!(id + 1)) { // check for number or string
var e = new Error("Cannot find module '" + req + "'"); var e = new Error('Cannot find module "' + req + '".');
e.code = 'MODULE_NOT_FOUND'; e.code = 'MODULE_NOT_FOUND';
throw e; throw e;
} }
@ -59655,26 +59647,26 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
/*! no static exports found */ /*! no static exports found */
/***/ (function(module, exports) { /***/ (function(module, exports) {
var g; var g;
// This works in non-strict mode // This works in non-strict mode
g = (function() { g = (function() {
return this; return this;
})(); })();
try { try {
// This works if eval is allowed (see CSP) // This works if eval is allowed (see CSP)
g = g || Function("return this")() || (1, eval)("this"); g = g || Function("return this")() || (1, eval)("this");
} catch (e) { } catch (e) {
// This works if the window reference is available // This works if the window reference is available
if (typeof window === "object") g = window; if (typeof window === "object") g = window;
} }
// g can still be undefined, but nothing to do about it... // g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's // We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...} // easier to handle this case. if(!global) { ...}
module.exports = g; module.exports = g;
/***/ }), /***/ }),
@ -59686,28 +59678,28 @@ module.exports = g;
/*! no static exports found */ /*! no static exports found */
/***/ (function(module, exports) { /***/ (function(module, exports) {
module.exports = function(module) { module.exports = function(module) {
if (!module.webpackPolyfill) { if (!module.webpackPolyfill) {
module.deprecate = function() {}; module.deprecate = function() {};
module.paths = []; module.paths = [];
// module.parent = undefined by default // module.parent = undefined by default
if (!module.children) module.children = []; if (!module.children) module.children = [];
Object.defineProperty(module, "loaded", { Object.defineProperty(module, "loaded", {
enumerable: true, enumerable: true,
get: function() { get: function() {
return module.l; return module.l;
} }
}); });
Object.defineProperty(module, "id", { Object.defineProperty(module, "id", {
enumerable: true, enumerable: true,
get: function() { get: function() {
return module.i; return module.i;
} }
}); });
module.webpackPolyfill = 1; module.webpackPolyfill = 1;
} }
return module; return module;
}; };
/***/ }), /***/ }),
@ -74085,7 +74077,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
beforeRender() { beforeRender() {
const _converse = this.__super__._converse, const _converse = this.__super__._converse,
device_id = _converse.omemo_store.get('device_id').toString(); device_id = _converse.omemo_store.get('device_id');
this.current_device = this.devicelist.devices.get(device_id); this.current_device = this.devicelist.devices.get(device_id);
this.other_devices = this.devicelist.devices.filter(d => d.get('id') !== device_id); this.other_devices = this.devicelist.devices.filter(d => d.get('id') !== device_id);
@ -74983,10 +74975,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
function restoreOMEMOSession() { function restoreOMEMOSession() {
if (_.isUndefined(_converse.omemo_store)) { if (_.isUndefined(_converse.omemo_store)) {
_converse.omemo_store = new _converse.OMEMOStore(); const storage = _converse.session.get('storage'),
const id = b64_sha1(`converse.omemosession-${_converse.bare_jid}`); id = `converse.omemosession-${_converse.bare_jid}`;
_converse.omemo_store.id = id;
_converse.omemo_store.browserStorage = new Backbone.BrowserStorage[_converse.storage](id); _converse.omemo_store = new _converse.OMEMOStore({
'id': id
});
_converse.omemo_store.browserStorage = new Backbone.BrowserStorage[storage](id);
} }
return _converse.omemo_store.fetchSession(); return _converse.omemo_store.fetchSession();
@ -74994,8 +74989,11 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
function initOMEMO() { function initOMEMO() {
_converse.devicelists = new _converse.DeviceLists(); _converse.devicelists = new _converse.DeviceLists();
const id = `converse.devicelists-${_converse.bare_jid}`;
_converse.devicelists.browserStorage = new Backbone.BrowserStorage[_converse.storage](id); const storage = _converse.session.get('storage'),
id = `converse.devicelists-${_converse.bare_jid}`;
_converse.devicelists.browserStorage = new Backbone.BrowserStorage[storage](id);
fetchOwnDevices().then(() => restoreOMEMOSession()).then(() => _converse.omemo.publishBundle()).then(() => _converse.emit('OMEMOInitialized')).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR)); fetchOwnDevices().then(() => restoreOMEMOSession()).then(() => _converse.omemo.publishBundle()).then(() => _converse.emit('OMEMOInitialized')).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
} }

View File

@ -88,7 +88,7 @@
beforeRender () { beforeRender () {
const { _converse } = this.__super__, const { _converse } = this.__super__,
device_id = _converse.omemo_store.get('device_id').toString(); device_id = _converse.omemo_store.get('device_id');
this.current_device = this.devicelist.devices.get(device_id); this.current_device = this.devicelist.devices.get(device_id);
this.other_devices = this.devicelist.devices.filter(d => (d.get('id') !== device_id)); this.other_devices = this.devicelist.devices.filter(d => (d.get('id') !== device_id));
if (this.__super__.beforeRender) { if (this.__super__.beforeRender) {
@ -640,6 +640,7 @@
}).then(keys => { }).then(keys => {
_.forEach(keys, k => _converse.omemo_store.storePreKey(k.keyId, k.keyPair)); _.forEach(keys, k => _converse.omemo_store.storePreKey(k.keyId, k.keyPair));
data['prekeys'] = keys; data['prekeys'] = keys;
this.save(data) this.save(data)
// Save the bundle to the device // Save the bundle to the device
const devicelist = _converse.devicelists.get(_converse.bare_jid), const devicelist = _converse.devicelists.get(_converse.bare_jid),
@ -913,18 +914,19 @@
function restoreOMEMOSession () { function restoreOMEMOSession () {
if (_.isUndefined(_converse.omemo_store)) { if (_.isUndefined(_converse.omemo_store)) {
_converse.omemo_store = new _converse.OMEMOStore(); const storage = _converse.session.get('storage'),
const id = b64_sha1(`converse.omemosession-${_converse.bare_jid}`); id = `converse.omemosession-${_converse.bare_jid}`;
_converse.omemo_store.id = id; _converse.omemo_store = new _converse.OMEMOStore({'id': id});
_converse.omemo_store.browserStorage = new Backbone.BrowserStorage[_converse.storage](id); _converse.omemo_store.browserStorage = new Backbone.BrowserStorage[storage](id);
} }
return _converse.omemo_store.fetchSession(); return _converse.omemo_store.fetchSession();
} }
function initOMEMO() { function initOMEMO() {
_converse.devicelists = new _converse.DeviceLists(); _converse.devicelists = new _converse.DeviceLists();
const id = `converse.devicelists-${_converse.bare_jid}`; const storage = _converse.session.get('storage'),
_converse.devicelists.browserStorage = new Backbone.BrowserStorage[_converse.storage](id); id = `converse.devicelists-${_converse.bare_jid}`;
_converse.devicelists.browserStorage = new Backbone.BrowserStorage[storage](id);
fetchOwnDevices() fetchOwnDevices()
.then(() => restoreOMEMOSession()) .then(() => restoreOMEMOSession())