mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
UX: Update Chat Group Name and Placeholder (#28703)
* UX: Update Chat Group Name and Placeholder * update tests * fix failing tests * better checking of system user when setting dm title
This commit is contained in:
@ -34,7 +34,9 @@ module Chat
|
|||||||
return chat_channel.name if group && chat_channel.name.present?
|
return chat_channel.name if group && chat_channel.name.present?
|
||||||
|
|
||||||
users =
|
users =
|
||||||
(direct_message_users.map(&:user) - [acting_user]).map { |user| user || Chat::NullUser.new }
|
(direct_message_users.map(&:user) - [acting_user])
|
||||||
|
.map { |user| user || Chat::NullUser.new }
|
||||||
|
.reject { |u| u.is_system_user? }
|
||||||
|
|
||||||
# direct message to self
|
# direct message to self
|
||||||
if users.empty?
|
if users.empty?
|
||||||
@ -45,13 +47,13 @@ module Chat
|
|||||||
return chat_channel.id if !users.first
|
return chat_channel.id if !users.first
|
||||||
|
|
||||||
usernames_formatted = users.sort_by(&:username).map { |u| "@#{u.username}" }
|
usernames_formatted = users.sort_by(&:username).map { |u| "@#{u.username}" }
|
||||||
if usernames_formatted.size > 5
|
if usernames_formatted.size > 7
|
||||||
return(
|
return(
|
||||||
I18n.t(
|
I18n.t(
|
||||||
"chat.channel.dm_title.multi_user_truncated",
|
"chat.channel.dm_title.multi_user_truncated",
|
||||||
comma_separated_usernames:
|
comma_separated_usernames:
|
||||||
usernames_formatted[0..4].join(I18n.t("word_connector.comma")),
|
usernames_formatted[0..5].join(I18n.t("word_connector.comma")),
|
||||||
count: usernames_formatted.length - 5,
|
count: usernames_formatted.length - 6,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -81,10 +81,8 @@ export default class ChatComposerChannel extends ChatComposer {
|
|||||||
|
|
||||||
#messageRecipients(channel) {
|
#messageRecipients(channel) {
|
||||||
if (channel.isDirectMessageChannel) {
|
if (channel.isDirectMessageChannel) {
|
||||||
if (channel.chatable.group && channel.title) {
|
if (channel.chatable.group) {
|
||||||
return I18n.t("chat.placeholder_channel", {
|
return I18n.t("chat.placeholder_group");
|
||||||
channelName: `#${channel.title}`,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
const directMessageRecipients = channel.chatable.users;
|
const directMessageRecipients = channel.chatable.users;
|
||||||
if (
|
if (
|
||||||
|
@ -251,6 +251,7 @@ en:
|
|||||||
placeholder_channel: "Chat in %{channelName}"
|
placeholder_channel: "Chat in %{channelName}"
|
||||||
placeholder_thread: "Chat in thread"
|
placeholder_thread: "Chat in thread"
|
||||||
placeholder_users: "Chat with %{commaSeparatedNames}"
|
placeholder_users: "Chat with %{commaSeparatedNames}"
|
||||||
|
placeholder_group: "Chat in group"
|
||||||
placeholder_new_message_disallowed:
|
placeholder_new_message_disallowed:
|
||||||
archived: "Channel is archived, you cannot send new messages right now."
|
archived: "Channel is archived, you cannot send new messages right now."
|
||||||
closed: "Channel is closed, you cannot send new messages right now."
|
closed: "Channel is closed, you cannot send new messages right now."
|
||||||
|
@ -24,11 +24,11 @@ describe Chat::DirectMessage do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a nicely formatted truncated name if it's more than 5 users" do
|
it "returns a nicely formatted truncated name if it's more than 7 users" do
|
||||||
user3 = Fabricate.build(:user, username: "chatdmregent")
|
user3 = Fabricate.build(:user, username: "chatdmregent")
|
||||||
|
|
||||||
users = [user1, user2, user3].concat(
|
users = [user1, user2, user3].concat(
|
||||||
5.times.map { |i| Fabricate(:user, username: "chatdmuser#{i}") },
|
6.times.map { |i| Fabricate(:user, username: "chatdmuser#{i}") },
|
||||||
)
|
)
|
||||||
direct_message = Fabricate(:direct_message, users: users)
|
direct_message = Fabricate(:direct_message, users: users)
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ describe Chat::DirectMessage do
|
|||||||
I18n.t(
|
I18n.t(
|
||||||
"chat.channel.dm_title.multi_user_truncated",
|
"chat.channel.dm_title.multi_user_truncated",
|
||||||
comma_separated_usernames:
|
comma_separated_usernames:
|
||||||
users[1..5]
|
users[1..6]
|
||||||
.sort_by(&:username)
|
.sort_by(&:username)
|
||||||
.map { |u| "@#{u.username}" }
|
.map { |u| "@#{u.username}" }
|
||||||
.join(I18n.t("word_connector.comma")),
|
.join(I18n.t("word_connector.comma")),
|
||||||
|
@ -4,6 +4,7 @@ import { module, test } from "qunit";
|
|||||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||||
import pretender from "discourse/tests/helpers/create-pretender";
|
import pretender from "discourse/tests/helpers/create-pretender";
|
||||||
import { query } from "discourse/tests/helpers/qunit-helpers";
|
import { query } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import I18n from "discourse-i18n";
|
||||||
import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";
|
import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";
|
||||||
|
|
||||||
module(
|
module(
|
||||||
@ -30,13 +31,13 @@ module(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("direct message to multiple folks shows their names", async function (assert) {
|
test("direct message to multiple folks shows their names when not a group", async function (assert) {
|
||||||
pretender.get("/chat/emojis.json", () => [200, [], {}]);
|
pretender.get("/chat/emojis.json", () => [200, [], {}]);
|
||||||
|
|
||||||
this.channel = ChatChannel.create({
|
this.channel = ChatChannel.create({
|
||||||
chatable_type: "DirectMessage",
|
chatable_type: "DirectMessage",
|
||||||
chatable: {
|
chatable: {
|
||||||
group: true,
|
group: false,
|
||||||
users: [
|
users: [
|
||||||
{ name: "Tomtom" },
|
{ name: "Tomtom" },
|
||||||
{ name: "Steaky" },
|
{ name: "Steaky" },
|
||||||
@ -53,6 +54,30 @@ module(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("direct message to group shows Chat in group", async function (assert) {
|
||||||
|
pretender.get("/chat/emojis.json", () => [200, [], {}]);
|
||||||
|
|
||||||
|
this.channel = ChatChannel.create({
|
||||||
|
chatable_type: "DirectMessage",
|
||||||
|
title: "Meetup Chat",
|
||||||
|
chatable: {
|
||||||
|
group: true,
|
||||||
|
users: [
|
||||||
|
{ username: "user1" },
|
||||||
|
{ username: "user2" },
|
||||||
|
{ username: "user3" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await render(hbs`<Chat::Composer::Channel @channel={{this.channel}} />`);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
query(".chat-composer__input").placeholder,
|
||||||
|
I18n.t("chat.placeholder_group")
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("message to channel shows send message to channel name", async function (assert) {
|
test("message to channel shows send message to channel name", async function (assert) {
|
||||||
pretender.get("/chat/emojis.json", () => [200, [], {}]);
|
pretender.get("/chat/emojis.json", () => [200, [], {}]);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user