diff --git a/lib/DataStore.js b/lib/DataStore.js index e85733ac5..63d070769 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, allowUnset) { log.debug( "getMatrixRoomsForChannelByOrigin " + channel + ", origin: " + JSON.stringify(origin) ); @@ -256,12 +256,17 @@ 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 + if (!e.remote || e.remote.getId() !== remoteId) { + return false; + } + if (allowUnset) { + if (!e.data || !e.data.origin) { + return true; + } + } + return e.data && 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(