From b6f6d1e5c0aaac92669d985183b28b24844a7660 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 28 Oct 2016 11:28:06 +0100 Subject: [PATCH 1/5] Allow topic setting /w mappings origin undefined Before 'origin' was introduced, entries were created without an origin. When setting a topic, allow them to be set on rooms with unknown origin as well as origin = 'join' | 'alias'. --- lib/DataStore.js | 12 ++++++------ lib/bridge/IrcHandler.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/DataStore.js b/lib/DataStore.js index e85733ac5..e9160ce92 100644 --- a/lib/DataStore.js +++ b/lib/DataStore.js @@ -245,7 +245,7 @@ DataStore.prototype.getMatrixRoomsForChannel = function(server, channel) { ); }; -DataStore.prototype.getMappingsForChannelByOrigin = function(server, channel, origin) { +DataStore.prototype.getMappingsForChannelByOrigin = function(server, channel, origin, allowUndefined) { log.debug( "getMatrixRoomsForChannelByOrigin " + channel + ", origin: " + JSON.stringify(origin) ); @@ -256,12 +256,12 @@ DataStore.prototype.getMappingsForChannelByOrigin = function(server, channel, or throw new Error("origin must be string or array of strings"); } let remoteId = IrcRoom.createId(server, channel); - - return this._roomStore.getEntriesByLinkData({ - origin: {$in : origin} - }).then((entries) => { + return this._roomStore.getEntriesByLinkData({}).then((entries) => { return entries.filter((e) => { - return e.remote.getId() === remoteId + return e.remote && e.remote.getId() === remoteId && ( + (typeof e.data.origin === 'undefined' && allowUndefined) || + origin.indexOf(e.data.origin) !== -1 + ); }); }); }; diff --git a/lib/bridge/IrcHandler.js b/lib/bridge/IrcHandler.js index d73f7d629..3d72f40d6 100644 --- a/lib/bridge/IrcHandler.js +++ b/lib/bridge/IrcHandler.js @@ -250,7 +250,7 @@ IrcHandler.prototype.onTopic = Promise.coroutine(function*(req, server, fromUser // Only bridge topics for rooms created by the bridge, via !join or an alias let origins = ["join", "alias"]; let entries = yield this.ircBridge.getStore().getMappingsForChannelByOrigin( - server, channel, origins + server, channel, origins, true ); if (entries.length === 0) { req.log.info( From a0ba00d025f77757a68dc44226707e1962672421 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 28 Oct 2016 11:36:18 +0100 Subject: [PATCH 2/5] allowUndefined -> allowUnset because style --- lib/DataStore.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/DataStore.js b/lib/DataStore.js index e9160ce92..9093f1b29 100644 --- a/lib/DataStore.js +++ b/lib/DataStore.js @@ -245,7 +245,7 @@ DataStore.prototype.getMatrixRoomsForChannel = function(server, channel) { ); }; -DataStore.prototype.getMappingsForChannelByOrigin = function(server, channel, origin, allowUndefined) { +DataStore.prototype.getMappingsForChannelByOrigin = function(server, channel, origin, allowUnset) { log.debug( "getMatrixRoomsForChannelByOrigin " + channel + ", origin: " + JSON.stringify(origin) ); @@ -259,7 +259,7 @@ DataStore.prototype.getMappingsForChannelByOrigin = function(server, channel, or return this._roomStore.getEntriesByLinkData({}).then((entries) => { return entries.filter((e) => { return e.remote && e.remote.getId() === remoteId && ( - (typeof e.data.origin === 'undefined' && allowUndefined) || + (typeof e.data.origin === 'undefined' && allowUnset) || origin.indexOf(e.data.origin) !== -1 ); }); From 6fdb510a04b6ab7f36f938e9247e55c2eb799a98 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 28 Oct 2016 11:54:52 +0100 Subject: [PATCH 3/5] Allow undefined data attribute, split onto multiple lines --- lib/DataStore.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/DataStore.js b/lib/DataStore.js index 9093f1b29..0e033cc83 100644 --- a/lib/DataStore.js +++ b/lib/DataStore.js @@ -258,10 +258,15 @@ DataStore.prototype.getMappingsForChannelByOrigin = function(server, channel, or let remoteId = IrcRoom.createId(server, channel); return this._roomStore.getEntriesByLinkData({}).then((entries) => { return entries.filter((e) => { - return e.remote && e.remote.getId() === remoteId && ( - (typeof e.data.origin === 'undefined' && allowUnset) || - origin.indexOf(e.data.origin) !== -1 - ); + if (!(e.remote && e.remote.getId() === remoteId)) { + return false; + } + if (allowUnset) { + if (typeof e.data === 'undefined' || typeof e.data.origin === 'undefined') { + return true; + } + } + return origin.indexOf(e.data.origin) !== -1; }); }); }; From fa4dcf35d50eaa7588b614a0850c54cf6bc94751 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 28 Oct 2016 11:58:30 +0100 Subject: [PATCH 4/5] Further simplifcation --- lib/DataStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DataStore.js b/lib/DataStore.js index 0e033cc83..ada77086f 100644 --- a/lib/DataStore.js +++ b/lib/DataStore.js @@ -258,7 +258,7 @@ DataStore.prototype.getMappingsForChannelByOrigin = function(server, channel, or let remoteId = IrcRoom.createId(server, channel); return this._roomStore.getEntriesByLinkData({}).then((entries) => { return entries.filter((e) => { - if (!(e.remote && e.remote.getId() === remoteId)) { + if (!e.remote || e.remote.getId() !== remoteId) { return false; } if (allowUnset) { From 82cccf3522f39f8ecccdeba3ec5fbb3dfd403c03 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 28 Oct 2016 12:03:47 +0100 Subject: [PATCH 5/5] More null checks --- lib/DataStore.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/DataStore.js b/lib/DataStore.js index ada77086f..63d070769 100644 --- a/lib/DataStore.js +++ b/lib/DataStore.js @@ -262,11 +262,11 @@ DataStore.prototype.getMappingsForChannelByOrigin = function(server, channel, or return false; } if (allowUnset) { - if (typeof e.data === 'undefined' || typeof e.data.origin === 'undefined') { + if (!e.data || !e.data.origin) { return true; } } - return origin.indexOf(e.data.origin) !== -1; + return e.data && origin.indexOf(e.data.origin) !== -1; }); }); };