This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/components/chat-mention-warnings.js
Gerhard Schlager 7ef482a292
REFACTOR: Fix pluralized strings in chat plugin (#20357)
* FIX: Use pluralized string

* REFACTOR: Fix misuse of pluralized string

* REFACTOR: Fix misuse of pluralized string

* DEV: Remove linting of `one` key in MessageFormat string, it doesn't work

* REFACTOR: Fix misuse of pluralized string

This also ensures that the URL works on subfolder and shows the site setting link only for admins instead of staff. The string is quite complicated, so the best option was to switch to MessageFormat.

* REFACTOR: Fix misuse of pluralized string

* FIX: Use pluralized string

This also ensures that the URL works on subfolder and shows the site setting link only for admins instead of staff.

* REFACTOR: Correctly pluralize reaction tooltips in chat

This also ensures that maximum 5 usernames are shown and fixes the number of "others" which was off by 1 if the current user reacted on a message.

* REFACTOR: Use translatable string as comma separator

* DEV: Add comment to translation to clarify the meaning of `%{identifier}`

* REFACTOR: Use translatable comma separator and use explicit interpolation keys

* REFACTOR: Don't interpolate lowercase channel status

* REFACTOR: Fix misuse of pluralized string

* REFACTOR: Don't interpolate channel status

* REFACTOR: Use %{count} interpolation key

* REFACTOR: Fix misuse of pluralized string

* REFACTOR: Correctly pluralize DM chat channel titles
2023-02-20 10:31:02 +01:00

144 lines
3.9 KiB
JavaScript

import Component from "@glimmer/component";
import I18n from "I18n";
import { htmlSafe } from "@ember/template";
import { inject as service } from "@ember/service";
import getURL from "discourse-common/lib/get-url";
export default class ChatMentionWarnings extends Component {
@service siteSettings;
@service currentUser;
@service chatComposerWarningsTracker;
get unreachableGroupMentions() {
return this.chatComposerWarningsTracker.unreachableGroupMentions;
}
get overMembersLimitGroupMentions() {
return this.chatComposerWarningsTracker.overMembersLimitGroupMentions;
}
get hasTooManyMentions() {
return this.chatComposerWarningsTracker.tooManyMentions;
}
get mentionsCount() {
return this.chatComposerWarningsTracker.mentionsCount;
}
get unreachableGroupMentionsCount() {
return this.unreachableGroupMentions.length;
}
get overMembersLimitMentionsCount() {
return this.overMembersLimitGroupMentions.length;
}
get hasUnreachableGroupMentions() {
return this.unreachableGroupMentionsCount > 0;
}
get hasOverMembersLimitGroupMentions() {
return this.overMembersLimitMentionsCount > 0;
}
get warningsCount() {
return (
this.unreachableGroupMentionsCount + this.overMembersLimitMentionsCount
);
}
get show() {
return (
this.hasTooManyMentions ||
this.hasUnreachableGroupMentions ||
this.hasOverMembersLimitGroupMentions
);
}
get listStyleClass() {
if (this.hasTooManyMentions) {
return "chat-mention-warnings-list__simple";
}
if (this.warningsCount > 1) {
return "chat-mention-warnings-list__multiple";
} else {
return "chat-mention-warnings-list__simple";
}
}
get warningHeaderText() {
if (this.mentionsCount <= this.warningsCount || this.hasTooManyMentions) {
return I18n.t("chat.mention_warning.groups.header.all");
} else {
return I18n.t("chat.mention_warning.groups.header.some");
}
}
get tooManyMentionsBody() {
if (!this.hasTooManyMentions) {
return;
}
if (this.currentUser.admin) {
return htmlSafe(
I18n.t("chat.mention_warning.too_many_mentions_admin", {
count: this.siteSettings.max_mentions_per_chat_message,
siteSettingUrl: getURL(
"/admin/site_settings/category/plugins?filter=max_mentions_per_chat_message"
),
})
);
} else {
return htmlSafe(
I18n.t("chat.mention_warning.too_many_mentions", {
count: this.siteSettings.max_mentions_per_chat_message,
})
);
}
}
get unreachableBody() {
if (!this.hasUnreachableGroupMentions) {
return;
}
switch (this.unreachableGroupMentionsCount) {
case 1:
return I18n.t("chat.mention_warning.groups.unreachable_1", {
group: this.unreachableGroupMentions[0],
});
case 2:
return I18n.t("chat.mention_warning.groups.unreachable_2", {
group1: this.unreachableGroupMentions[0],
group2: this.unreachableGroupMentions[1],
});
default:
return I18n.t("chat.mention_warning.groups.unreachable_multiple", {
group: this.unreachableGroupMentions[0],
count: this.unreachableGroupMentionsCount - 1,
});
}
}
get overMembersLimitBody() {
if (!this.hasOverMembersLimitGroupMentions) {
return;
}
return htmlSafe(
I18n.messageFormat("chat.mention_warning.groups.too_many_members_MF", {
groupCount: this.overMembersLimitMentionsCount,
isAdmin: this.currentUser.admin,
siteSettingUrl: getURL(
"/admin/site_settings/category/plugins?filter=max_users_notified_per_group_mention"
),
notificationLimit:
this.siteSettings.max_users_notified_per_group_mention,
group1: this.overMembersLimitGroupMentions[0],
group2: this.overMembersLimitGroupMentions[1],
})
);
}
}