2019-12-31 16:21:34 +00:00
|
|
|
<template>
|
|
|
|
<div id="chat-container" class="window">
|
|
|
|
<div
|
|
|
|
id="chat"
|
|
|
|
:class="{
|
|
|
|
'colored-nicks': $store.state.settings.coloredNicks,
|
2021-04-12 21:46:44 +00:00
|
|
|
'time-seconds': $store.state.settings.showSeconds,
|
|
|
|
'time-12h': $store.state.settings.use12hClock,
|
2019-12-31 16:21:34 +00:00
|
|
|
}"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
class="chat-view"
|
|
|
|
data-type="search-results"
|
|
|
|
aria-label="Search results"
|
|
|
|
role="tabpanel"
|
|
|
|
>
|
|
|
|
<div class="header">
|
|
|
|
<SidebarToggle />
|
|
|
|
<span class="title"
|
2021-04-29 23:07:31 +00:00
|
|
|
>Searching in <span class="channel-name">{{ channel.name }}</span> for</span
|
2019-12-31 16:21:34 +00:00
|
|
|
>
|
2021-04-12 23:06:30 +00:00
|
|
|
<span class="topic">{{ $route.query.q }}</span>
|
2019-12-31 16:21:34 +00:00
|
|
|
<MessageSearchForm :network="network" :channel="channel" />
|
2021-04-29 23:49:49 +00:00
|
|
|
<button
|
|
|
|
class="close"
|
|
|
|
aria-label="Close search window"
|
|
|
|
title="Close search window"
|
|
|
|
@click="closeSearch"
|
|
|
|
/>
|
2019-12-31 16:21:34 +00:00
|
|
|
</div>
|
|
|
|
<div class="chat-content">
|
|
|
|
<div ref="chat" class="chat" tabindex="-1">
|
|
|
|
<div v-show="moreResultsAvailable" class="show-more">
|
|
|
|
<button
|
|
|
|
ref="loadMoreButton"
|
|
|
|
:disabled="
|
|
|
|
$store.state.messageSearchInProgress ||
|
2020-03-07 12:56:50 +00:00
|
|
|
!$store.state.isConnected
|
2019-12-31 16:21:34 +00:00
|
|
|
"
|
|
|
|
class="btn"
|
|
|
|
@click="onShowMoreClick"
|
|
|
|
>
|
|
|
|
<span v-if="$store.state.messageSearchInProgress">Loading…</span>
|
|
|
|
<span v-else>Show older messages</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
2020-04-23 16:50:45 +00:00
|
|
|
<div
|
|
|
|
v-if="$store.state.messageSearchInProgress && !offset"
|
|
|
|
class="search-status"
|
|
|
|
>
|
2020-03-07 11:01:22 +00:00
|
|
|
Searching…
|
2019-12-31 16:21:34 +00:00
|
|
|
</div>
|
2020-04-23 16:50:45 +00:00
|
|
|
<div v-else-if="!messages.length && !offset" class="search-status">
|
2019-12-31 16:21:34 +00:00
|
|
|
No results found.
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-else
|
|
|
|
class="messages"
|
|
|
|
role="log"
|
|
|
|
aria-live="polite"
|
|
|
|
aria-relevant="additions"
|
|
|
|
>
|
|
|
|
<template v-for="(message, id) in messages">
|
2021-01-26 23:56:53 +00:00
|
|
|
<div :key="message.id" class="result" @:click="jump(message, id)">
|
2021-01-26 22:51:22 +00:00
|
|
|
<DateMarker
|
|
|
|
v-if="shouldDisplayDateMarker(message, id)"
|
|
|
|
:key="message.date"
|
|
|
|
:message="message"
|
|
|
|
/>
|
|
|
|
<Message
|
|
|
|
:key="message.id"
|
|
|
|
:channel="channel"
|
|
|
|
:network="network"
|
|
|
|
:message="message"
|
|
|
|
:data-id="message.id"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-12-31 16:21:34 +00:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-04-12 23:06:30 +00:00
|
|
|
<style>
|
|
|
|
.channel-name {
|
|
|
|
font-weight: 700;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2019-12-31 16:21:34 +00:00
|
|
|
<script>
|
|
|
|
import socket from "../../js/socket";
|
2021-11-18 21:31:20 +00:00
|
|
|
import eventbus from "../../js/eventbus";
|
2019-12-31 16:21:34 +00:00
|
|
|
|
|
|
|
import SidebarToggle from "../SidebarToggle.vue";
|
|
|
|
import Message from "../Message.vue";
|
|
|
|
import MessageSearchForm from "../MessageSearchForm.vue";
|
|
|
|
import DateMarker from "../DateMarker.vue";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "SearchResults",
|
|
|
|
components: {
|
|
|
|
SidebarToggle,
|
|
|
|
Message,
|
|
|
|
DateMarker,
|
|
|
|
MessageSearchForm,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
offset: 0,
|
|
|
|
moreResultsAvailable: false,
|
2020-04-23 16:50:45 +00:00
|
|
|
oldScrollTop: 0,
|
|
|
|
oldChatHeight: 0,
|
2019-12-31 16:21:34 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
search() {
|
|
|
|
return this.$store.state.messageSearchResults;
|
|
|
|
},
|
|
|
|
messages() {
|
|
|
|
if (!this.search) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2021-10-28 07:48:11 +00:00
|
|
|
return this.search.results;
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
|
|
|
chan() {
|
2021-04-29 23:07:31 +00:00
|
|
|
const chanId = parseInt(this.$route.params.id, 10);
|
|
|
|
return this.$store.getters.findChannel(chanId);
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
|
|
|
network() {
|
|
|
|
if (!this.chan) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.chan.network;
|
|
|
|
},
|
|
|
|
channel() {
|
|
|
|
if (!this.chan) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.chan.channel;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
2021-04-29 23:07:31 +00:00
|
|
|
"$route.params.id"() {
|
2019-12-31 16:21:34 +00:00
|
|
|
this.doSearch();
|
2021-04-29 23:07:31 +00:00
|
|
|
this.setActiveChannel();
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
2021-04-12 22:01:00 +00:00
|
|
|
"$route.query.q"() {
|
2019-12-31 16:21:34 +00:00
|
|
|
this.doSearch();
|
2021-04-29 23:07:31 +00:00
|
|
|
this.setActiveChannel();
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
|
|
|
messages() {
|
|
|
|
this.moreResultsAvailable = this.messages.length && !(this.messages.length % 100);
|
2020-04-23 16:50:45 +00:00
|
|
|
|
|
|
|
if (!this.offset) {
|
|
|
|
this.jumpToBottom();
|
|
|
|
} else {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
const currentChatHeight = this.$refs.chat.scrollHeight;
|
|
|
|
this.$refs.chat.scrollTop =
|
|
|
|
this.oldScrollTop + currentChatHeight - this.oldChatHeight;
|
|
|
|
});
|
|
|
|
}
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-04-29 23:07:31 +00:00
|
|
|
this.setActiveChannel();
|
2019-12-31 16:21:34 +00:00
|
|
|
this.doSearch();
|
2021-11-18 21:31:20 +00:00
|
|
|
|
|
|
|
eventbus.on("escapekey", this.closeSearch);
|
2021-04-12 22:45:15 +00:00
|
|
|
this.$root.$on("re-search", this.doSearch); // Enable MessageSearchForm to search for the same query again
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$root.$off("re-search");
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
2021-11-18 21:31:20 +00:00
|
|
|
destroyed() {
|
|
|
|
eventbus.off("escapekey", this.closeSearch);
|
|
|
|
},
|
2019-12-31 16:21:34 +00:00
|
|
|
methods: {
|
2021-04-12 21:40:29 +00:00
|
|
|
setActiveChannel() {
|
|
|
|
this.$store.commit("activeChannel", this.chan);
|
|
|
|
},
|
2021-04-29 23:49:49 +00:00
|
|
|
closeSearch() {
|
|
|
|
this.$root.switchToChannel(this.channel);
|
|
|
|
},
|
2019-12-31 16:21:34 +00:00
|
|
|
shouldDisplayDateMarker(message, id) {
|
|
|
|
const previousMessage = this.messages[id - 1];
|
|
|
|
|
|
|
|
if (!previousMessage) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Date(previousMessage.time).getDay() !== new Date(message.time).getDay();
|
|
|
|
},
|
|
|
|
doSearch() {
|
|
|
|
this.offset = 0;
|
|
|
|
this.$store.commit("messageSearchInProgress", true);
|
2020-04-23 16:50:45 +00:00
|
|
|
|
|
|
|
if (!this.offset) {
|
|
|
|
this.$store.commit("messageSearchResults", null); // Only reset if not getting offset
|
|
|
|
}
|
|
|
|
|
2019-12-31 16:21:34 +00:00
|
|
|
socket.emit("search", {
|
2021-04-29 23:07:31 +00:00
|
|
|
networkUuid: this.network.uuid,
|
|
|
|
channelName: this.channel.name,
|
2021-04-12 22:01:00 +00:00
|
|
|
searchTerm: this.$route.query.q,
|
2019-12-31 16:21:34 +00:00
|
|
|
offset: this.offset,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onShowMoreClick() {
|
|
|
|
this.offset += 100;
|
|
|
|
this.$store.commit("messageSearchInProgress", true);
|
2020-04-23 16:50:45 +00:00
|
|
|
|
|
|
|
this.oldScrollTop = this.$refs.chat.scrollTop;
|
|
|
|
this.oldChatHeight = this.$refs.chat.scrollHeight;
|
|
|
|
|
2019-12-31 16:21:34 +00:00
|
|
|
socket.emit("search", {
|
2021-04-29 23:07:31 +00:00
|
|
|
networkUuid: this.network.uuid,
|
|
|
|
channelName: this.channel.name,
|
2021-04-12 22:01:00 +00:00
|
|
|
searchTerm: this.$route.query.q,
|
2020-03-07 12:56:50 +00:00
|
|
|
offset: this.offset + 1,
|
2019-12-31 16:21:34 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
jumpToBottom() {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
const el = this.$refs.chat;
|
|
|
|
el.scrollTop = el.scrollHeight;
|
|
|
|
});
|
|
|
|
},
|
2021-01-26 22:51:22 +00:00
|
|
|
jump(message, id) {
|
|
|
|
// TODO: Implement jumping to messages!
|
|
|
|
// This is difficult because it means client will need to handle a potentially nonlinear message set
|
|
|
|
// (loading IntersectionObserver both before AND after the messages)
|
2021-01-26 23:56:53 +00:00
|
|
|
this.$router.push({
|
|
|
|
name: "MessageList",
|
|
|
|
params: {
|
|
|
|
id: this.chan.id,
|
|
|
|
},
|
|
|
|
query: {
|
|
|
|
focused: id,
|
|
|
|
},
|
|
|
|
});
|
2021-01-26 22:51:22 +00:00
|
|
|
},
|
2019-12-31 16:21:34 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|