From 7b173e883f0a573dfe5b27e5b8824de8ce6bb898 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 25 Jan 2024 15:30:21 +0100 Subject: [PATCH] FEATURE: display last message on mobile (#25384) Direct messages on mobile will now display the last message in the channels list. --- .../components/channel-icon/index.gjs | 49 +++++++ .../components/channel-name/index.gjs | 79 +++++++++++ .../components/channel-title/index.gjs | 126 +++-------------- .../components/chat-channel-metadata.gjs | 4 +- .../discourse/components/chat-channel-row.gjs | 28 +++- .../stylesheets/common/chat-channel-icon.scss | 56 ++++++++ .../stylesheets/common/chat-channel-name.scss | 18 +++ .../stylesheets/common/chat-channel-row.scss | 129 ++++++++---------- .../common/chat-channel-title.scss | 35 +---- .../chat/assets/stylesheets/common/index.scss | 2 + .../stylesheets/mobile/chat-channel-row.scss | 62 +++++++-- .../spec/system/channel_settings_page_spec.rb | 2 +- .../spec/system/list_channels/mobile_spec.rb | 29 ++++ .../components/channel-icon-test.gjs | 81 +++++++++++ .../components/channel-name-test.gjs | 63 +++++++++ .../components/channel-title-test.gjs | 25 ++++ .../components/channel-title-test.js | 95 ------------- .../components/chat-channel-metadata-test.js | 4 +- .../chat-channel-preview-card-test.js | 4 +- .../components/chat-channel-row-test.js | 6 +- 20 files changed, 568 insertions(+), 329 deletions(-) create mode 100644 plugins/chat/assets/javascripts/discourse/components/channel-icon/index.gjs create mode 100644 plugins/chat/assets/javascripts/discourse/components/channel-name/index.gjs create mode 100644 plugins/chat/assets/stylesheets/common/chat-channel-icon.scss create mode 100644 plugins/chat/assets/stylesheets/common/chat-channel-name.scss create mode 100644 plugins/chat/test/javascripts/components/channel-icon-test.gjs create mode 100644 plugins/chat/test/javascripts/components/channel-name-test.gjs create mode 100644 plugins/chat/test/javascripts/components/channel-title-test.gjs delete mode 100644 plugins/chat/test/javascripts/components/channel-title-test.js diff --git a/plugins/chat/assets/javascripts/discourse/components/channel-icon/index.gjs b/plugins/chat/assets/javascripts/discourse/components/channel-icon/index.gjs new file mode 100644 index 00000000000..a014679d985 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/channel-icon/index.gjs @@ -0,0 +1,49 @@ +import Component from "@glimmer/component"; +import { htmlSafe } from "@ember/template"; +import icon from "discourse-common/helpers/d-icon"; +import ChatUserAvatar from "discourse/plugins/chat/discourse/components/chat-user-avatar"; + +export default class ChatChannelIcon extends Component { + get firstUser() { + return this.args.channel.chatable.users[0]; + } + + get groupDirectMessage() { + return ( + this.args.channel.isDirectMessageChannel && + this.args.channel.chatable.group + ); + } + + get channelColorStyle() { + return htmlSafe(`color: #${this.args.channel.chatable.color}`); + } + + +} diff --git a/plugins/chat/assets/javascripts/discourse/components/channel-name/index.gjs b/plugins/chat/assets/javascripts/discourse/components/channel-name/index.gjs new file mode 100644 index 00000000000..6aeb8aa933f --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/channel-name/index.gjs @@ -0,0 +1,79 @@ +import Component from "@glimmer/component"; +import { get, hash } from "@ember/helper"; +import { inject as service } from "@ember/service"; +import { htmlSafe } from "@ember/template"; +import PluginOutlet from "discourse/components/plugin-outlet"; +import UserStatusMessage from "discourse/components/user-status-message"; +import replaceEmoji from "discourse/helpers/replace-emoji"; + +export default class ChatChannelName extends Component { + @service currentUser; + + get firstUser() { + return this.args.channel.chatable.users[0]; + } + + get users() { + return this.args.channel.chatable.users; + } + + get groupDirectMessage() { + return ( + this.args.channel.isDirectMessageChannel && + this.args.channel.chatable.group + ); + } + + get groupsDirectMessageTitle() { + return this.args.channel.title || this.usernames; + } + + get usernames() { + return this.users.mapBy("username").join(", "); + } + + get channelColorStyle() { + return htmlSafe(`color: #${this.args.channel.chatable.color}`); + } + + get showUserStatus() { + return !!(this.users.length === 1 && this.users[0].status); + } + + +} diff --git a/plugins/chat/assets/javascripts/discourse/components/channel-title/index.gjs b/plugins/chat/assets/javascripts/discourse/components/channel-title/index.gjs index 65b36f386c7..c2339d7f052 100644 --- a/plugins/chat/assets/javascripts/discourse/components/channel-title/index.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/channel-title/index.gjs @@ -1,111 +1,21 @@ -import Component from "@glimmer/component"; -import { get, hash } from "@ember/helper"; -import { inject as service } from "@ember/service"; -import { htmlSafe } from "@ember/template"; -import PluginOutlet from "discourse/components/plugin-outlet"; -import UserStatusMessage from "discourse/components/user-status-message"; -import replaceEmoji from "discourse/helpers/replace-emoji"; -import icon from "discourse-common/helpers/d-icon"; -import ChatUserAvatar from "discourse/plugins/chat/discourse/components/chat-user-avatar"; +import concatClass from "discourse/helpers/concat-class"; +import ChannelIcon from "discourse/plugins/chat/discourse/components/channel-icon"; +import ChannelName from "discourse/plugins/chat/discourse/components/channel-name"; -export default class ChatChannelTitle extends Component { - @service currentUser; +const ChatChannelTitle = ; + +export default ChatChannelTitle; diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs index 7fd591fbe5f..b00f21c38dd 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs @@ -18,9 +18,9 @@ export default class ChatChannelMetadata extends Component { }