mirror of
https://github.com/thelounge/thelounge
synced 2024-11-26 05:50:22 +00:00
0ebc3a574c
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.
28 lines
842 B
TypeScript
28 lines
842 B
TypeScript
import socket from "../socket";
|
|
import {store} from "../store";
|
|
|
|
socket.on("search:results", (response) => {
|
|
const pendingQuery = store.state.messageSearchPendingQuery;
|
|
|
|
if (
|
|
!pendingQuery ||
|
|
pendingQuery.channelName !== response.channelName ||
|
|
pendingQuery.networkUuid !== response.networkUuid ||
|
|
pendingQuery.offset !== response.offset ||
|
|
pendingQuery.searchTerm !== response.searchTerm
|
|
) {
|
|
// This is a response from a search that we are not interested in.
|
|
// The user may have entered a different search while one was still in flight.
|
|
// We can simply drop it on the floor.
|
|
return;
|
|
}
|
|
|
|
store.commit("messageSearchPendingQuery", null);
|
|
|
|
if (store.state.messageSearchResults) {
|
|
store.commit("addMessageSearchResults", response);
|
|
return;
|
|
}
|
|
|
|
store.commit("messageSearchResults", {results: response.results});
|
|
});
|