refactor: move fetching logic to onScrollToMessage

This commit is contained in:
Shivam Mishra
2023-11-30 13:08:49 +05:30
parent 9cc6275c82
commit baf1323ebd
2 changed files with 9 additions and 10 deletions
@@ -521,17 +521,9 @@ export default {
}, HIGHLIGHT_TIMER);
},
async navigateToMessage() {
// TODO: check if the message is already loaded
await this.$store.dispatch('setActiveChat', {
data: this.currentChat,
after: this.inReplyToMessageId,
force: true,
});
this.$nextTick(() => {
bus.$emit(BUS_EVENTS.SCROLL_TO_MESSAGE, {
messageId: this.inReplyToMessageId,
behavior: 'instant',
});
});
},
@@ -377,12 +377,19 @@ export default {
removeBusListeners() {
bus.$off(BUS_EVENTS.SCROLL_TO_MESSAGE, this.onScrollToMessage);
},
onScrollToMessage({ messageId = '', behavior = 'smooth' } = {}) {
async onScrollToMessage({ messageId }) {
// TODO: check if the message is already loaded
await this.$store.dispatch('setActiveChat', {
data: this.currentChat,
after: messageId,
force: true,
});
this.$nextTick(() => {
const messageElement = document.getElementById('message' + messageId);
if (messageElement) {
this.isProgrammaticScroll = true;
messageElement.scrollIntoView({ behavior });
messageElement.scrollIntoView();
this.fetchPreviousMessages();
} else {
this.scrollToBottom();