From b35701f4c687934a09a01f2ae324b4e9481aa94f Mon Sep 17 00:00:00 2001 From: silver-it Date: Thu, 14 Mar 2024 16:29:18 +0800 Subject: [PATCH] fix: display username instead of userid in edit text area --- frontend/views/containers/chatroom/MessageBase.vue | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/views/containers/chatroom/MessageBase.vue b/frontend/views/containers/chatroom/MessageBase.vue index 6df2c73b73..96bfb33868 100644 --- a/frontend/views/containers/chatroom/MessageBase.vue +++ b/frontend/views/containers/chatroom/MessageBase.vue @@ -34,7 +34,7 @@ ) {{ objReplyMessage.text }} send-area( v-if='isEditing' - :defaultText='text' + :defaultText='swapUserIDForUsername(text)' :isEditing='true' @send='onMessageEdited' @cancelEdit='cancelEdit' @@ -189,6 +189,13 @@ export default ({ isMention (o) { return o.type === TextObjectType.Mention }, + swapUserIDForUsername (text) { + const possibleMentions = Object.keys(this.ourContactProfilesById).map(u => makeMentionFromUserID(u).me).filter(v => !!v) + return text + .split(new RegExp(`(?<=\\s|^)(${possibleMentions.join('|')})(?=[^\\w\\d]|$)`)) + .map(t => !possibleMentions.includes(t) ? t : t[0] + this.usernameFromID(t.slice(1))) + .join('') + }, generateTextObjectsFromText (text) { if (!text) { return []