2019-12-31 16:21:34 +00:00
|
|
|
import socket from "../socket";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {store} from "../store";
|
2019-12-31 16:21:34 +00:00
|
|
|
|
|
|
|
socket.on("search:results", (response) => {
|
2022-11-26 16:14:09 +00:00
|
|
|
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);
|
2020-04-23 16:50:45 +00:00
|
|
|
|
|
|
|
if (store.state.messageSearchResults) {
|
|
|
|
store.commit("addMessageSearchResults", response);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-26 16:14:09 +00:00
|
|
|
store.commit("messageSearchResults", {results: response.results});
|
2019-12-31 16:21:34 +00:00
|
|
|
});
|