thelounge/server/plugins/messageStorage/types.d.ts
Reto Brunner 0ebc3a574c search: ignore searchResults if it isn't the active query
Prior to this, the search is still racy but one tends to notice
this only when the DB is large or network is involved.
The user can initiate a search, get bored, navigate to another chan
issue a different search.

Now however, the results of the first search come back in and
hilarity ensues as we are now confused with the state.

To avoid this, keep track of the last search done and any result
that comes in that isn't equal to the active query is garbage and
can be dropped.
2023-01-08 11:41:09 +01:00

42 lines
953 B
TypeScript

import type {Database} from "sqlite3";
import {Channel} from "../../models/channel";
import {Message} from "../../models/message";
import {Network} from "../../models/network";
import Client from "../../client";
interface MessageStorage {
client: Client;
isEnabled: boolean;
enable(): Promise<void>;
close(): Promise<void>;
index(network: Network, channel: Channel, msg: Message): Promise<void>;
deleteChannel(network: Network, channel: Channel): Promise<void>;
getMessages(network: Network, channel: Channel): Promise<Message[]>;
canProvideMessages(): boolean;
}
export type SearchQuery = {
searchTerm: string;
networkUuid: string;
channelName: string;
offset: number;
};
export type SearchResponse = SearchQuery & {
results: Message[];
};
type SearchFunction = (query: SearchQuery) => Promise<SearchResponse>;
export interface SqliteMessageStorage extends MessageStorage {
database: Database;
search: SearchFunction | [];
}