From bb21476f6861689eddfe7c4076badcd89afd7878 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Thu, 1 Jun 2023 15:55:59 +0400 Subject: [PATCH] FIX: Do not add mentioned groups as mentioned users (#21867) When a user type a message with mentions, the autocomplete popup may suggest users or groups. We were adding all these object to the `currentMessage.mentionedUsers` collection, while we should have been adding only users. A group added to that collection led to the error later when trying to update user status on mentions. --- .../discourse/components/chat-composer.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js index 8ac3f9609e9..9d09fdd7cfe 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js @@ -415,6 +415,11 @@ export default class ChatComposer extends Component { } } + #addMentionedUser(userData) { + const user = User.create(userData); + this.currentMessage.mentionedUsers.set(user.id, user); + } + #applyUserAutocomplete($textarea) { if (!this.siteSettings.enable_mentions) { return; @@ -426,10 +431,12 @@ export default class ChatComposer extends Component { width: "100%", treatAsTextarea: true, autoSelectFirstSuggestion: true, - transformComplete: (userData) => { - const user = User.create(userData); - this.currentMessage.mentionedUsers.set(user.id, user); - return user.username || user.name; + transformComplete: (obj) => { + if (obj.isUser) { + this.#addMentionedUser(obj); + } + + return obj.username || obj.name; }, dataSource: (term) => { return userSearch({ term, includeGroups: true }).then((result) => {