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.
This commit is contained in:
Nachtalb 2021-04-12 23:09:55 +02:00
parent fe0178c0d2
commit de86c144b5
No known key found for this signature in database
GPG key ID: E48DF13C07055D92
6 changed files with 21 additions and 13 deletions

View file

@ -40,7 +40,10 @@
:text="channel.topic" :text="channel.topic"
/></span> /></span>
<MessageSearchForm <MessageSearchForm
v-if="['channel', 'query'].includes(channel.type)" v-if="
$store.state.settings.searchEnabled &&
['channel', 'query'].includes(channel.type)
"
:network="network" :network="network"
:channel="channel" :channel="channel"
/> />

View file

@ -109,6 +109,9 @@ export const config = normalizeConfig({
} }
}, },
}, },
searchEnabled: {
default: false,
},
}); });
export function createState() { export function createState() {

View file

@ -56,6 +56,7 @@ store = new Vuex.Store({
serverHasSettings: false, serverHasSettings: false,
messageSearchResults: null, messageSearchResults: null,
messageSearchInProgress: false, messageSearchInProgress: false,
searchEnabled: false,
}, },
mutations: { mutations: {
appLoaded(state) { appLoaded(state) {

View file

@ -63,6 +63,7 @@ function Client(manager, name, config = {}) {
messageStorage: [], messageStorage: [],
highlightRegex: null, highlightRegex: null,
highlightExceptionRegex: null, highlightExceptionRegex: null,
messageProvider: undefined,
}); });
const client = this; const client = this;
@ -72,7 +73,8 @@ function Client(manager, name, config = {}) {
if (!Helper.config.public && client.config.log) { if (!Helper.config.public && client.config.log) {
if (Helper.config.messageStorage.includes("sqlite")) { 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")) { if (Helper.config.messageStorage.includes("text")) {
@ -106,6 +108,8 @@ function Client(manager, name, config = {}) {
client.awayMessage = client.config.clientSettings.awayMessage; client.awayMessage = client.config.clientSettings.awayMessage;
} }
client.config.clientSettings.searchEnabled = client.messageProvider !== undefined;
client.compileCustomHighlights(); client.compileCustomHighlights();
_.forOwn(client.config.sessions, (session) => { _.forOwn(client.config.sessions, (session) => {
@ -535,8 +539,11 @@ Client.prototype.clearHistory = function (data) {
}; };
Client.prototype.search = function (query) { Client.prototype.search = function (query) {
const messageStorage = this.messageStorage.find((s) => s.canProvideMessages()); if (this.messageProvider === undefined) {
return messageStorage.search(query); return Promise.resolve([]);
}
return this.messageProvider.search(query);
}; };
Client.prototype.open = function (socketId, target) { Client.prototype.open = function (socketId, target) {

View file

@ -236,17 +236,11 @@ Chan.prototype.writeUserLog = function (client, msg) {
}; };
Chan.prototype.loadMessages = function (client, network) { Chan.prototype.loadMessages = function (client, network) {
if (!this.isLoggable()) { if (!this.isLoggable() || !client.messageProvider) {
return; return;
} }
const messageStorage = client.messageStorage.find((s) => s.canProvideMessages()); client.messageProvider
if (!messageStorage) {
return;
}
messageStorage
.getMessages(network, this) .getMessages(network, this)
.then((messages) => { .then((messages) => {
if (messages.length === 0) { if (messages.length === 0) {

View file

@ -189,7 +189,7 @@ Network.prototype.createIrcFramework = function (client) {
// Request only new messages from ZNC if we have sqlite logging enabled // Request only new messages from ZNC if we have sqlite logging enabled
// See http://wiki.znc.in/Playback // 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"); this.irc.requestCap("znc.in/playback");
} }
}; };