From de86c144b5d0f45a357d36462e6692ace8cfa865 Mon Sep 17 00:00:00 2001 From: Nachtalb Date: Mon, 12 Apr 2021 23:09:55 +0200 Subject: [PATCH] Disable search if we have no message provider If we have no message provider: - Search input field not renderd - Search endpoint retuns empty resultset Also removed redundancy by setting a main message provider. --- client/components/Chat.vue | 5 ++++- client/js/settings.js | 3 +++ client/js/store.js | 1 + src/client.js | 13 ++++++++++--- src/models/chan.js | 10 ++-------- src/models/network.js | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/client/components/Chat.vue b/client/components/Chat.vue index 9a789ad3..9c761ac0 100644 --- a/client/components/Chat.vue +++ b/client/components/Chat.vue @@ -40,7 +40,10 @@ :text="channel.topic" /> diff --git a/client/js/settings.js b/client/js/settings.js index 43bf2cfe..3e3e5581 100644 --- a/client/js/settings.js +++ b/client/js/settings.js @@ -109,6 +109,9 @@ export const config = normalizeConfig({ } }, }, + searchEnabled: { + default: false, + }, }); export function createState() { diff --git a/client/js/store.js b/client/js/store.js index af289965..b1f24d48 100644 --- a/client/js/store.js +++ b/client/js/store.js @@ -56,6 +56,7 @@ store = new Vuex.Store({ serverHasSettings: false, messageSearchResults: null, messageSearchInProgress: false, + searchEnabled: false, }, mutations: { appLoaded(state) { diff --git a/src/client.js b/src/client.js index 8e4fcd2c..4a2d54e9 100644 --- a/src/client.js +++ b/src/client.js @@ -63,6 +63,7 @@ function Client(manager, name, config = {}) { messageStorage: [], highlightRegex: null, highlightExceptionRegex: null, + messageProvider: undefined, }); const client = this; @@ -72,7 +73,8 @@ function Client(manager, name, config = {}) { if (!Helper.config.public && client.config.log) { if (Helper.config.messageStorage.includes("sqlite")) { - client.messageStorage.push(new MessageStorage(client)); + client.messageProvider = new MessageStorage(client); + client.messageStorage.push(client.messageProvider); } if (Helper.config.messageStorage.includes("text")) { @@ -106,6 +108,8 @@ function Client(manager, name, config = {}) { client.awayMessage = client.config.clientSettings.awayMessage; } + client.config.clientSettings.searchEnabled = client.messageProvider !== undefined; + client.compileCustomHighlights(); _.forOwn(client.config.sessions, (session) => { @@ -535,8 +539,11 @@ Client.prototype.clearHistory = function (data) { }; Client.prototype.search = function (query) { - const messageStorage = this.messageStorage.find((s) => s.canProvideMessages()); - return messageStorage.search(query); + if (this.messageProvider === undefined) { + return Promise.resolve([]); + } + + return this.messageProvider.search(query); }; Client.prototype.open = function (socketId, target) { diff --git a/src/models/chan.js b/src/models/chan.js index b0a4fffd..fe9494fb 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -236,17 +236,11 @@ Chan.prototype.writeUserLog = function (client, msg) { }; Chan.prototype.loadMessages = function (client, network) { - if (!this.isLoggable()) { + if (!this.isLoggable() || !client.messageProvider) { return; } - const messageStorage = client.messageStorage.find((s) => s.canProvideMessages()); - - if (!messageStorage) { - return; - } - - messageStorage + client.messageProvider .getMessages(network, this) .then((messages) => { if (messages.length === 0) { diff --git a/src/models/network.js b/src/models/network.js index bc2dbce1..621f7e1d 100644 --- a/src/models/network.js +++ b/src/models/network.js @@ -189,7 +189,7 @@ Network.prototype.createIrcFramework = function (client) { // Request only new messages from ZNC if we have sqlite logging enabled // See http://wiki.znc.in/Playback - if (client.config.log && client.messageStorage.find((s) => s.canProvideMessages())) { + if (client.messageProvider) { this.irc.requestCap("znc.in/playback"); } };