* 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
90 lines
2.2 KiB
JavaScript
90 lines
2.2 KiB
JavaScript
import { isBlank, isPresent } from "@ember/utils";
|
|
import Component from "@ember/component";
|
|
import { inject as service } from "@ember/service";
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
import I18n from "I18n";
|
|
import { fmt } from "discourse/lib/computed";
|
|
import { next } from "@ember/runloop";
|
|
|
|
export default Component.extend({
|
|
tagName: "",
|
|
presence: service(),
|
|
presenceChannel: null,
|
|
chatChannel: null,
|
|
|
|
@discourseComputed("presenceChannel.users.[]")
|
|
usernames(users) {
|
|
return users
|
|
?.filter((u) => u.id !== this.currentUser.id)
|
|
?.mapBy("username");
|
|
},
|
|
|
|
@discourseComputed("usernames.[]")
|
|
text(usernames) {
|
|
if (isBlank(usernames)) {
|
|
return;
|
|
}
|
|
|
|
if (usernames.length === 1) {
|
|
return I18n.t("chat.replying_indicator.single_user", {
|
|
username: usernames[0],
|
|
});
|
|
}
|
|
|
|
if (usernames.length < 4) {
|
|
const lastUsername = usernames.pop();
|
|
const commaSeparatedUsernames = usernames.join(
|
|
I18n.t("word_connector.comma")
|
|
);
|
|
return I18n.t("chat.replying_indicator.multiple_users", {
|
|
commaSeparatedUsernames,
|
|
lastUsername,
|
|
});
|
|
}
|
|
|
|
const commaSeparatedUsernames = usernames
|
|
.slice(0, 2)
|
|
.join(I18n.t("word_connector.comma"));
|
|
return I18n.t("chat.replying_indicator.many_users", {
|
|
commaSeparatedUsernames,
|
|
count: usernames.length - 2,
|
|
});
|
|
},
|
|
|
|
@discourseComputed("usernames.[]")
|
|
shouldDisplay(usernames) {
|
|
return isPresent(usernames);
|
|
},
|
|
|
|
channelName: fmt("chatChannel.id", "/chat-reply/%@"),
|
|
|
|
didReceiveAttrs() {
|
|
this._super(...arguments);
|
|
|
|
if (!this.chatChannel || this.chatChannel.isDraft) {
|
|
this.presenceChannel?.unsubscribe();
|
|
return;
|
|
}
|
|
|
|
if (this.presenceChannel?.name !== this.channelName) {
|
|
this.presenceChannel?.unsubscribe();
|
|
|
|
next(() => {
|
|
if (this.isDestroyed || this.isDestroying) {
|
|
return;
|
|
}
|
|
|
|
const presenceChannel = this.presence.getChannel(this.channelName);
|
|
this.set("presenceChannel", presenceChannel);
|
|
presenceChannel.subscribe();
|
|
});
|
|
}
|
|
},
|
|
|
|
willDestroyElement() {
|
|
this._super(...arguments);
|
|
|
|
this.presenceChannel?.unsubscribe();
|
|
},
|
|
});
|