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"
/></span>
<MessageSearchForm
v-if="['channel', 'query'].includes(channel.type)"
v-if="
$store.state.settings.searchEnabled &&
['channel', 'query'].includes(channel.type)
"
:network="network"
:channel="channel"
/>

View file

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

View file

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

View file

@ -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) {

View file

@ -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) {

View file

@ -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");
}
};