Merge branch 'search'
This commit is contained in:
commit
d34b58811a
@ -129,13 +129,14 @@ export default defineComponent({
|
|||||||
const oldScrollTop = ref(0);
|
const oldScrollTop = ref(0);
|
||||||
const oldChatHeight = ref(0);
|
const oldChatHeight = ref(0);
|
||||||
|
|
||||||
const search = computed(() => store.state.messageSearchResults);
|
|
||||||
const messages = computed(() => {
|
const messages = computed(() => {
|
||||||
if (!search.value) {
|
const results = store.state.messageSearchResults?.results;
|
||||||
|
|
||||||
|
if (!results) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return search.value.results;
|
return results;
|
||||||
});
|
});
|
||||||
|
|
||||||
const chan = computed(() => {
|
const chan = computed(() => {
|
||||||
@ -185,14 +186,14 @@ export default defineComponent({
|
|||||||
return new Date(previousMessage.time).getDay() !== new Date(message.time).getDay();
|
return new Date(previousMessage.time).getDay() !== new Date(message.time).getDay();
|
||||||
};
|
};
|
||||||
|
|
||||||
const doSearch = () => {
|
const clearSearchState = () => {
|
||||||
offset.value = 0;
|
offset.value = 0;
|
||||||
store.commit("messageSearchInProgress", true);
|
store.commit("messageSearchInProgress", false);
|
||||||
|
store.commit("messageSearchResults", null);
|
||||||
if (!offset.value) {
|
};
|
||||||
store.commit("messageSearchInProgress", undefined); // Only reset if not getting offset
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const doSearch = () => {
|
||||||
|
clearSearchState(); // this is a new search, so we need to clear anything before that
|
||||||
socket.emit("search", {
|
socket.emit("search", {
|
||||||
networkUuid: network.value?.uuid,
|
networkUuid: network.value?.uuid,
|
||||||
channelName: channel.value?.name,
|
channelName: channel.value?.name,
|
||||||
@ -216,7 +217,7 @@ export default defineComponent({
|
|||||||
networkUuid: network.value?.uuid,
|
networkUuid: network.value?.uuid,
|
||||||
channelName: channel.value?.name,
|
channelName: channel.value?.name,
|
||||||
searchTerm: String(route.query.q || ""),
|
searchTerm: String(route.query.q || ""),
|
||||||
offset: offset.value + 1,
|
offset: offset.value,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -286,6 +287,7 @@ export default defineComponent({
|
|||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
eventbus.off("escapekey", closeSearch);
|
eventbus.off("escapekey", closeSearch);
|
||||||
eventbus.off("re-search", doSearch);
|
eventbus.off("re-search", doSearch);
|
||||||
|
clearSearchState();
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -293,7 +295,6 @@ export default defineComponent({
|
|||||||
loadMoreButton,
|
loadMoreButton,
|
||||||
messages,
|
messages,
|
||||||
moreResultsAvailable,
|
moreResultsAvailable,
|
||||||
search,
|
|
||||||
network,
|
network,
|
||||||
channel,
|
channel,
|
||||||
route,
|
route,
|
||||||
|
@ -224,7 +224,7 @@ class SqliteMessageStorage implements ISqliteMessageStorage {
|
|||||||
|
|
||||||
let select =
|
let select =
|
||||||
'SELECT msg, type, time, network, channel FROM messages WHERE type = "message" AND json_extract(msg, "$.text") LIKE ? ESCAPE \'@\'';
|
'SELECT msg, type, time, network, channel FROM messages WHERE type = "message" AND json_extract(msg, "$.text") LIKE ? ESCAPE \'@\'';
|
||||||
const params = [`%${escapedSearchTerm}%`];
|
const params: any[] = [`%${escapedSearchTerm}%`];
|
||||||
|
|
||||||
if (query.networkUuid) {
|
if (query.networkUuid) {
|
||||||
select += " AND network = ? ";
|
select += " AND network = ? ";
|
||||||
@ -239,9 +239,8 @@ class SqliteMessageStorage implements ISqliteMessageStorage {
|
|||||||
const maxResults = 100;
|
const maxResults = 100;
|
||||||
|
|
||||||
select += " ORDER BY time DESC LIMIT ? OFFSET ? ";
|
select += " ORDER BY time DESC LIMIT ? OFFSET ? ";
|
||||||
params.push(maxResults.toString());
|
params.push(maxResults);
|
||||||
query.offset = parseInt(query.offset as string, 10) || 0;
|
params.push(query.offset);
|
||||||
params.push(String(query.offset));
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.database.all(select, params, (err, rows) => {
|
this.database.all(select, params, (err, rows) => {
|
||||||
@ -252,8 +251,8 @@ class SqliteMessageStorage implements ISqliteMessageStorage {
|
|||||||
searchTerm: query.searchTerm,
|
searchTerm: query.searchTerm,
|
||||||
target: query.channelName,
|
target: query.channelName,
|
||||||
networkUuid: query.networkUuid,
|
networkUuid: query.networkUuid,
|
||||||
offset: query.offset as number,
|
offset: query.offset,
|
||||||
results: parseSearchRowsToMessages(query.offset as number, rows).reverse(),
|
results: parseSearchRowsToMessages(query.offset, rows).reverse(),
|
||||||
};
|
};
|
||||||
resolve(response);
|
resolve(response);
|
||||||
}
|
}
|
||||||
|
2
server/plugins/messageStorage/types.d.ts
vendored
2
server/plugins/messageStorage/types.d.ts
vendored
@ -26,7 +26,7 @@ export type SearchQuery = {
|
|||||||
searchTerm: string;
|
searchTerm: string;
|
||||||
networkUuid: string;
|
networkUuid: string;
|
||||||
channelName: string;
|
channelName: string;
|
||||||
offset: number | string;
|
offset: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SearchResponse =
|
export type SearchResponse =
|
||||||
|
@ -167,7 +167,9 @@ describe("SQLite Message Storage", function () {
|
|||||||
.search({
|
.search({
|
||||||
searchTerm: "msg",
|
searchTerm: "msg",
|
||||||
networkUuid: "retrieval-order-test-network",
|
networkUuid: "retrieval-order-test-network",
|
||||||
} as any)
|
channelName: "",
|
||||||
|
offset: 0,
|
||||||
|
})
|
||||||
.then((messages) => {
|
.then((messages) => {
|
||||||
// @ts-expect-error Property 'results' does not exist on type '[]'.
|
// @ts-expect-error Property 'results' does not exist on type '[]'.
|
||||||
expect(messages.results).to.have.lengthOf(100);
|
expect(messages.results).to.have.lengthOf(100);
|
||||||
@ -192,7 +194,9 @@ describe("SQLite Message Storage", function () {
|
|||||||
.search({
|
.search({
|
||||||
searchTerm: query,
|
searchTerm: query,
|
||||||
networkUuid: "this-is-a-network-guid2",
|
networkUuid: "this-is-a-network-guid2",
|
||||||
} as any)
|
channelName: "",
|
||||||
|
offset: 0,
|
||||||
|
})
|
||||||
.then((messages) => {
|
.then((messages) => {
|
||||||
// @ts-expect-error Property 'results' does not exist on type '[]'.
|
// @ts-expect-error Property 'results' does not exist on type '[]'.
|
||||||
expect(messages.results.map((i) => i.text)).to.deep.equal(expected);
|
expect(messages.results.map((i) => i.text)).to.deep.equal(expected);
|
||||||
|
Loading…
Reference in New Issue
Block a user