From 91dfb0bc8ea656d384cce1321039251b4e999b7d Mon Sep 17 00:00:00 2001 From: N-Pex Date: Mon, 10 May 2021 16:11:03 +0200 Subject: [PATCH] Add option to start private chat By clicking on avatar. Issue #101. --- src/assets/css/chat.scss | 12 +++- src/components/Chat.vue | 73 ++++++++++++++++++- src/components/messages/AvatarOperations.vue | 37 ++++++++++ src/components/messages/MessageIncoming.vue | 2 +- src/components/messages/messageMixin.js | 4 ++ src/services/matrix.service.js | 75 +++++++++++++++++++- 6 files changed, 196 insertions(+), 7 deletions(-) create mode 100644 src/components/messages/AvatarOperations.vue diff --git a/src/assets/css/chat.scss b/src/assets/css/chat.scss index 156440c..404e157 100644 --- a/src/assets/css/chat.scss +++ b/src/assets/css/chat.scss @@ -420,7 +420,7 @@ $admin-fg: white; } } -.message-operations-strut { +.message-operations-strut, .avatar-operations-strut { position: relative; height: 0px; z-index: 1; @@ -442,6 +442,16 @@ $admin-fg: white; // } } +.avatar-operations { + position: absolute; + width: fit-content; + background-color: white; + height: 40px; + border-radius: 20px; + padding: 0px 20px; + box-shadow: 4px 4px 8px #888888; +} + .message-operations-picker { background-color: white; text-align: center; diff --git a/src/components/Chat.vue b/src/components/Chat.vue index 8f76047..9f7e5a3 100644 --- a/src/components/Chat.vue +++ b/src/components/Chat.vue @@ -9,14 +9,14 @@ ref="chatContainer" style="overflow-x: hidden; overflow-y: auto" v-on:scroll="onScroll" - @click="closeContextMenuIfOpen" + @click="closeContextMenusIfOpen" >
+
+ +
+ @@ -355,6 +368,7 @@ import DebugEvent from "./messages/DebugEvent.vue"; import util from "../plugins/utils"; import MessageOperations from "./messages/MessageOperations.vue"; import MessageOperationsPicker from "./messages/MessageOperationsPicker.vue"; +import AvatarOperations from "./messages/AvatarOperations.vue"; import ChatHeader from "./ChatHeader"; import VoiceRecorder from "./VoiceRecorder"; import RoomInfoBottomSheet from "./RoomInfoBottomSheet"; @@ -430,6 +444,7 @@ export default { MessageOperationsBottomSheet, StickerPickerBottomSheet, BottomSheet, + AvatarOperations, }, data() { @@ -456,6 +471,8 @@ export default { replyToEvent: null, showContextMenu: false, showContextMenuAnchor: null, + showAvatarMenu: false, + showAvatarMenuAnchor: null, initialLoadDone: false, loading: false, // Set this to true during long operations to show a "spinner" overlay showRecorder: false, @@ -586,6 +603,25 @@ export default { } return "top:" + top + "px;left:" + left + "px"; }, + avatarOpStyle() { + // Calculate where to show the context menu. + // + const ref = this.selectedEvent && this.$refs[this.selectedEvent.getId()]; + var top = 0; + var left = 0; + if (ref && ref[0]) { + if (this.showAvatarMenuAnchor) { + var rectAnchor = this.showAvatarMenuAnchor.getBoundingClientRect(); + var rectChat = this.$refs.avatarOperationsStrut.getBoundingClientRect(); + top = rectAnchor.top - rectChat.top; + left = rectAnchor.left - rectChat.left; + // if (left + 250 > rectChat.right) { + // left = rectChat.right - 250; // Pretty ugly, but we want to make sure it does not escape the screen, and we don't have the exakt width of it (yet)! + // } + } + } + return "top:" + top + "px;left:" + left + "px"; + }, canRecordAudio() { return util.browserCanRecordAudio(); }, @@ -1258,13 +1294,44 @@ export default { this.showContextMenuAnchor = e.anchor; }, + showAvatarMenuForEvent(e) { + const event = e.event; + this.selectedEvent = event; + this.showAvatarMenu = true; + this.showAvatarMenuAnchor = e.anchor; + }, + viewProfile() { this.$navigation.push({ name: "Profile" }, 1); }, - closeContextMenuIfOpen(e) { + startPrivateChat(e) { + this.$matrix.getOrCreatePrivateChat(e.event.getSender()) + .then(room => { + this.$nextTick(() => { + this.$navigation.push( + { + name: "Chat", + params: { roomId: util.sanitizeRoomId(room.getCanonicalAlias() || room.roomId) }, + }, + -1 + ); + }); + }) + .catch(err => { + console.error(err); + }) + }, + + closeContextMenusIfOpen(e) { if (this.showContextMenu) { this.showContextMenu = false; + this.showContextMenuAnchor = null; + e.preventDefault(); + } + if (this.showAvatarMenu) { + this.showAvatarMenu = false; + this.showAvatarMenuAnchor = null; e.preventDefault(); } }, diff --git a/src/components/messages/AvatarOperations.vue b/src/components/messages/AvatarOperations.vue new file mode 100644 index 0000000..93b48dc --- /dev/null +++ b/src/components/messages/AvatarOperations.vue @@ -0,0 +1,37 @@ + + + + + \ No newline at end of file diff --git a/src/components/messages/MessageIncoming.vue b/src/components/messages/MessageIncoming.vue index 55a3c4b..14ab8e9 100644 --- a/src/components/messages/MessageIncoming.vue +++ b/src/components/messages/MessageIncoming.vue @@ -1,7 +1,7 @@