From a39ff830e83c21d4d3312912890e583db5959010 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 9 Oct 2023 21:12:50 +0200 Subject: [PATCH] UX: makes avatar non interactive in thread participants list (#23847) It was slightly surprising to have a user card show when click on a thread item list. More over this commit does: - moves chat/user-avatar to chat-user-avatar and converts it to gjs - moves chat/thread/participants to chat-thread-participants - rewrite the `toggleCheckIfPossible` modifier to only be applied when selecting messages, it prevents the click event to collide with the click of avatars in regular messages --- .../components/chat-channel-title.hbs | 2 +- .../chat-composer-message-details.hbs | 2 +- .../chat-message-actions-mobile.gjs | 2 +- .../chat-message-in-reply-to-indicator.hbs | 2 +- .../chat-message-thread-indicator.hbs | 4 +- .../discourse/components/chat-message.gjs | 45 +++++++++----- ...pants.gjs => chat-thread-participants.gjs} | 3 +- .../discourse/components/chat-user-avatar.gjs | 58 +++++++++++++++++++ .../discourse/components/chat-user-info.gjs | 2 +- .../chat/message-creator/user-row.hbs | 2 +- .../chat/message-creator/user-selection.hbs | 2 +- .../components/chat/message/avatar.hbs | 2 +- .../components/chat/thread-list/item.hbs | 5 +- .../discourse/components/chat/user-avatar.hbs | 9 --- .../discourse/components/chat/user-avatar.js | 26 --------- .../common/chat-thread-list-item.scss | 2 + .../chat/spec/fabricators/chat_fabricator.rb | 5 +- .../chat/components/thread_indicator.rb | 2 +- .../chat-thread-participants-test.js | 19 +++--- .../components/chat-user-avatar-test.js | 22 +++++-- 20 files changed, 134 insertions(+), 82 deletions(-) rename plugins/chat/assets/javascripts/discourse/components/{chat/thread/participants.gjs => chat-thread-participants.gjs} (96%) create mode 100644 plugins/chat/assets/javascripts/discourse/components/chat-user-avatar.gjs delete mode 100644 plugins/chat/assets/javascripts/discourse/components/chat/user-avatar.hbs delete mode 100644 plugins/chat/assets/javascripts/discourse/components/chat/user-avatar.js diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-title.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-title.hbs index 1e8958d0bf1..712abf29dbd 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-title.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-title.hbs @@ -7,7 +7,7 @@ {{@channel.chatable.users.length}} {{else}} - + {{/if}} {{/if}} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer-message-details.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-composer-message-details.hbs index eac795d3fc8..3415ca32d0f 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-composer-message-details.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer-message-details.hbs @@ -5,7 +5,7 @@ >
{{d-icon (if @message.editing "pencil-alt" "reply")}} - + {{@message.user.username}} {{replace-emoji (html-safe @message.excerpt)}} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-mobile.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-mobile.gjs index d5c572cd350..52c34c1f54c 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-mobile.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-mobile.gjs @@ -10,7 +10,7 @@ import didInsert from "@ember/render-modifiers/modifiers/did-insert"; import concatClass from "discourse/helpers/concat-class"; import DButton from "discourse/components/d-button"; import { on } from "@ember/modifier"; -import ChatUserAvatar from "discourse/plugins/chat/discourse/components/chat/user-avatar"; +import ChatUserAvatar from "discourse/plugins/chat/discourse/components/chat-user-avatar"; import ChatMessageReaction from "discourse/plugins/chat/discourse/components/chat-message-reaction"; import { fn } from "@ember/helper"; import or from "truth-helpers/helpers/or"; diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.hbs index 716525f3fd1..d414a05390d 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.hbs @@ -9,7 +9,7 @@ {{#if @message.inReplyTo.chatWebhookEvent.emoji}} {{else}} - + {{/if}} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-thread-indicator.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-message-thread-indicator.hbs index 2e16cc3d229..77508ae58d0 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-message-thread-indicator.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-message-thread-indicator.hbs @@ -10,7 +10,7 @@ >
- @@ -27,7 +27,7 @@
{{i18n "chat.thread.replies" count=@message.thread.preview.replyCount}}
- +
{{replace-emoji (html-safe @message.thread.preview.lastReplyExcerpt)}}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-message.gjs index 5793692218d..f8ef8cfb2b1 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-message.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-message.gjs @@ -32,6 +32,7 @@ import didInsert from "@ember/render-modifiers/modifiers/did-insert"; import didUpdate from "@ember/render-modifiers/modifiers/did-update"; import willDestroy from "@ember/render-modifiers/modifiers/will-destroy"; import ChatOnLongPress from "discourse/plugins/chat/discourse/modifiers/chat/on-long-press"; +import { modifier } from "ember-modifier"; let _chatMessageDecorators = []; @@ -84,7 +85,7 @@ export default class ChatMessage extends Component { {{on "mouseenter" this.onMouseEnter passive=true}} {{on "mouseleave" this.onMouseLeave passive=true}} {{on "mousemove" this.onMouseMove passive=true}} - {{on "click" this.toggleCheckIfPossible passive=true}} + {{this.toggleCheckIfPossible}} {{ChatOnLongPress this.onLongPressStart this.onLongPressEnd @@ -200,6 +201,34 @@ export default class ChatMessage extends Component { @optionalService adminTools; + toggleCheckIfPossible = modifier((element) => { + let addedListener = false; + + const handler = () => { + if (!this.pane.selectingMessages) { + return; + } + + if (event.shiftKey) { + this.messageInteractor.bulkSelect(!this.args.message.selected); + return; + } + + this.messageInteractor.select(!this.args.message.selected); + }; + + if (this.pane.selectingMessages) { + element.addEventListener("click", handler, { passive: true }); + addedListener = true; + } + + return () => { + if (addedListener) { + element.removeEventListener("click", handler); + } + }; + }); + constructor() { super(...arguments); this.initMentionedUsers(); @@ -280,20 +309,6 @@ export default class ChatMessage extends Component { recursiveExpand(this.args.message); } - @action - toggleCheckIfPossible(event) { - if (!this.pane.selectingMessages) { - return; - } - - if (event.shiftKey) { - this.messageInteractor.bulkSelect(!this.args.message.selected); - return; - } - - this.messageInteractor.select(!this.args.message.selected); - } - @action toggleChecked(event) { event.stopPropagation(); diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread/participants.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-thread-participants.gjs similarity index 96% rename from plugins/chat/assets/javascripts/discourse/components/chat/thread/participants.gjs rename to plugins/chat/assets/javascripts/discourse/components/chat-thread-participants.gjs index 441cba1ed42..ac49c1bd5e9 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/thread/participants.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread-participants.gjs @@ -1,5 +1,5 @@ import Component from "@glimmer/component"; -import ChatUserAvatar from "discourse/plugins/chat/discourse/components/chat/user-avatar"; +import ChatUserAvatar from "discourse/plugins/chat/discourse/components/chat-user-avatar"; import I18n from "I18n"; export default class ChatThreadParticipants extends Component { @@ -12,6 +12,7 @@ export default class ChatThreadParticipants extends Component { @user={{user}} @avatarSize="tiny" @showPresence={{false}} + @interactive={{false}} /> {{/each}}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-user-avatar.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-user-avatar.gjs new file mode 100644 index 00000000000..d1907d23b42 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat-user-avatar.gjs @@ -0,0 +1,58 @@ +import Component from "@glimmer/component"; +import { inject as service } from "@ember/service"; +import { renderAvatar } from "discourse/helpers/user-avatar"; +import { htmlSafe } from "@ember/template"; +import concatClass from "discourse/helpers/concat-class"; + +export default class ChatUserAvatar extends Component { + + + @service chat; + + get avatar() { + return htmlSafe( + renderAvatar(this.args.user, { imageSize: this.avatarSize }) + ); + } + + get interactive() { + return this.args.interactive ?? true; + } + + get avatarSize() { + return this.args.avatarSize || "tiny"; + } + + get showPresence() { + return this.args.showPresence ?? true; + } + + get isOnline() { + const users = (this.args.chat || this.chat).presenceChannel?.users; + + return ( + this.showPresence && + !!users?.find( + ({ id, username }) => + this.args.user?.id === id || this.args.user?.username === username + ) + ); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-user-info.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-user-info.gjs index d4ae7ebc428..b7640700439 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-user-info.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-user-info.gjs @@ -1,6 +1,6 @@ import Component from "@glimmer/component"; import { userPath } from "discourse/lib/url"; -import ChatUserAvatar from "discourse/plugins/chat/discourse/components/chat/user-avatar"; +import ChatUserAvatar from "discourse/plugins/chat/discourse/components/chat-user-avatar"; import ChatUserDisplayName from "discourse/plugins/chat/discourse/components/chat-user-display-name"; export default class ChatUserInfo extends Component { diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/user-row.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/user-row.hbs index 91785854dba..640fd839332 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/user-row.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/user-row.hbs @@ -1,4 +1,4 @@ - + {{#if (gt @content.tracking.unreadCount 0)}} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/user-selection.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/user-selection.hbs index a5bf850b37e..ef9cca035f6 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/user-selection.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/user-selection.hbs @@ -1,4 +1,4 @@ - + {{@selection.model.username}} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/message/avatar.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/message/avatar.hbs index c393efa893d..1d2e9676fbf 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/message/avatar.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat/message/avatar.hbs @@ -2,6 +2,6 @@ {{#if @message.chatWebhookEvent.emoji}} {{else}} - + {{/if}}
\ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread-list/item.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/thread-list/item.hbs index 6424753a6fe..07c18da2323 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/thread-list/item.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat/thread-list/item.hbs @@ -29,11 +29,12 @@