feat: Allow agents/admins to copy the link to a message (#5912)

This commit is contained in:
Pranav Raj S
2023-03-26 22:58:42 -07:00
committed by GitHub
parent 1e8881577a
commit 6000028f64
9 changed files with 107 additions and 33 deletions

View File

@@ -1,5 +1,5 @@
<template>
<li v-if="shouldRenderMessage" :class="alignBubble">
<li v-if="shouldRenderMessage" :id="`message${data.id}`" :class="alignBubble">
<div :class="wrapClass">
<div
v-tooltip.top-start="messageToolTip"
@@ -190,6 +190,7 @@ export default {
showContextMenu: false,
hasImageError: false,
contextMenuPosition: {},
showBackgroundHighlight: false,
};
},
computed: {
@@ -290,13 +291,13 @@ export default {
const isRightAligned =
messageType === MESSAGE_TYPE.OUTGOING ||
messageType === MESSAGE_TYPE.TEMPLATE;
return {
center: isCentered,
left: isLeftAligned,
right: isRightAligned,
'has-context-menu': this.showContextMenu,
'has-tweet-menu': this.isATweet,
'has-bg': this.showBackgroundHighlight,
};
},
createdAt() {
@@ -414,9 +415,11 @@ export default {
mounted() {
this.hasImageError = false;
bus.$on(BUS_EVENTS.ON_MESSAGE_LIST_SCROLL, this.closeContextMenu);
this.setupHighlightTimer();
},
beforeDestroy() {
bus.$off(BUS_EVENTS.ON_MESSAGE_LIST_SCROLL, this.closeContextMenu);
clearTimeout(this.higlightTimeout);
},
methods: {
hasMediaAttachment(type) {
@@ -458,6 +461,17 @@ export default {
this.showContextMenu = false;
this.contextMenuPosition = { x: null, y: null };
},
setupHighlightTimer() {
if (Number(this.$route.query.messageId) !== Number(this.data.id)) {
return;
}
this.showBackgroundHighlight = true;
const HIGHLIGHT_TIMER = 1000;
this.higlightTimeout = setTimeout(() => {
this.showBackgroundHighlight = false;
}, HIGHLIGHT_TIMER);
},
},
};
</script>
@@ -589,6 +603,10 @@ li.left.has-tweet-menu .context-menu {
margin-bottom: var(--space-medium);
}
li.has-bg {
background: var(--w-75);
}
li.right .context-menu-wrap {
margin-left: auto;
}

View File

@@ -192,11 +192,6 @@ export default {
(!this.listLoadingStatus && this.isLoadingPrevious)
);
},
shouldLoadMoreChats() {
return !this.listLoadingStatus && !this.isLoadingPrevious;
},
conversationType() {
const { additional_attributes: additionalAttributes } = this.currentChat;
const type = additionalAttributes ? additionalAttributes.type : '';
@@ -302,8 +297,16 @@ export default {
setSelectedTweet(tweetId) {
this.selectedTweetId = tweetId;
},
onScrollToMessage() {
this.$nextTick(() => this.scrollToBottom());
onScrollToMessage({ messageId = '' } = {}) {
this.$nextTick(() => {
const messageElement = document.getElementById('message' + messageId);
if (messageElement) {
messageElement.scrollIntoView({ behavior: 'smooth' });
this.fetchPreviousMessages();
} else {
this.scrollToBottom();
}
});
this.makeMessagesRead();
},
showPopoutReplyBox() {
@@ -354,34 +357,42 @@ export default {
this.scrollTopBeforeLoad = this.conversationPanel.scrollTop;
},
handleScroll(e) {
bus.$emit(BUS_EVENTS.ON_MESSAGE_LIST_SCROLL);
async fetchPreviousMessages(scrollTop = 0) {
this.setScrollParams();
const shouldLoadMoreMessages =
this.getMessages.dataFetched === true &&
!this.listLoadingStatus &&
!this.isLoadingPrevious;
const dataFetchCheck =
this.getMessages.dataFetched === true && this.shouldLoadMoreChats;
if (
e.target.scrollTop < 100 &&
scrollTop < 100 &&
!this.isLoadingPrevious &&
dataFetchCheck
shouldLoadMoreMessages
) {
this.isLoadingPrevious = true;
this.$store
.dispatch('fetchPreviousMessages', {
try {
await this.$store.dispatch('fetchPreviousMessages', {
conversationId: this.currentChat.id,
before: this.getMessages.messages[0].id,
})
.then(() => {
const heightDifference =
this.conversationPanel.scrollHeight - this.heightBeforeLoad;
this.conversationPanel.scrollTop =
this.scrollTopBeforeLoad + heightDifference;
this.isLoadingPrevious = false;
this.setScrollParams();
});
const heightDifference =
this.conversationPanel.scrollHeight - this.heightBeforeLoad;
this.conversationPanel.scrollTop =
this.scrollTopBeforeLoad + heightDifference;
this.setScrollParams();
} catch (error) {
// Ignore Error
} finally {
this.isLoadingPrevious = false;
}
}
},
handleScroll(e) {
bus.$emit(BUS_EVENTS.ON_MESSAGE_LIST_SCROLL);
this.fetchPreviousMessages(e.target.scrollTop);
},
makeMessagesRead() {
this.$store.dispatch('markMessagesRead', { id: this.currentChat.id });
},

View File

@@ -67,6 +67,7 @@ export default {
&:hover {
background-color: var(--w-75);
.submenu {
display: block;
}