This commit automatically ensures that category channels have slugs when they are created or updated based on the channel name, category name, or existing slug. The behaviour has been copied from the Category model. We also include a backfill here with a simplified version of Slug.for with deduplication to fill the slugs for already created Category chat channels. The channel slug is also now used for chat notifications, and for the UI and navigation for chat. `slugifyChannel` is still used, but now does the following fallback: * Uses channel.slug if it is present * Uses channel.escapedTitle if it is present * Uses channel.title if it is present In future we may want to remove this altogether and always rely on the slug being present, but this is currently not possible because we are not generating slugs for DM channels at this point.
143 lines
4.1 KiB
JavaScript
143 lines
4.1 KiB
JavaScript
import I18n from "I18n";
|
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
import { formatUsername } from "discourse/lib/utilities";
|
|
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
|
|
|
export default {
|
|
name: "chat-user-menu",
|
|
initialize(container) {
|
|
withPluginApi("1.3.0", (api) => {
|
|
const chat = container.lookup("service:chat");
|
|
|
|
if (!chat.userCanChat) {
|
|
return;
|
|
}
|
|
|
|
if (api.registerNotificationTypeRenderer) {
|
|
api.registerNotificationTypeRenderer(
|
|
"chat_invitation",
|
|
(NotificationItemBase) => {
|
|
return class extends NotificationItemBase {
|
|
get linkHref() {
|
|
const slug = slugifyChannel({
|
|
title: this.notification.data.chat_channel_title,
|
|
slug: this.notification.data.chat_channel_slug,
|
|
});
|
|
return `/chat/channel/${
|
|
this.notification.data.chat_channel_id
|
|
}/${slug || "-"}?messageId=${
|
|
this.notification.data.chat_message_id
|
|
}`;
|
|
}
|
|
|
|
get linkTitle() {
|
|
return I18n.t("notifications.titles.chat_invitation");
|
|
}
|
|
|
|
get icon() {
|
|
return "link";
|
|
}
|
|
|
|
get label() {
|
|
return formatUsername(
|
|
this.notification.data.invited_by_username
|
|
);
|
|
}
|
|
|
|
get description() {
|
|
return I18n.t("notifications.chat_invitation");
|
|
}
|
|
};
|
|
}
|
|
);
|
|
|
|
api.registerNotificationTypeRenderer(
|
|
"chat_mention",
|
|
(NotificationItemBase) => {
|
|
return class extends NotificationItemBase {
|
|
get linkHref() {
|
|
const slug = slugifyChannel({
|
|
title: this.notification.data.chat_channel_title,
|
|
slug: this.notification.data.chat_channel_slug,
|
|
});
|
|
return `/chat/channel/${
|
|
this.notification.data.chat_channel_id
|
|
}/${slug || "-"}?messageId=${
|
|
this.notification.data.chat_message_id
|
|
}`;
|
|
}
|
|
|
|
get linkTitle() {
|
|
return I18n.t("notifications.titles.chat_mention");
|
|
}
|
|
|
|
get icon() {
|
|
return "comment";
|
|
}
|
|
|
|
get label() {
|
|
return formatUsername(
|
|
this.notification.data.mentioned_by_username
|
|
);
|
|
}
|
|
|
|
get description() {
|
|
const identifier = this.notification.data.identifier
|
|
? `@${this.notification.data.identifier}`
|
|
: null;
|
|
|
|
const i18nPrefix = this.notification.data
|
|
.is_direct_message_channel
|
|
? "notifications.popup.direct_message_chat_mention"
|
|
: "notifications.popup.chat_mention";
|
|
|
|
const i18nSuffix = identifier ? "other_plain" : "direct";
|
|
|
|
return I18n.t(`${i18nPrefix}.${i18nSuffix}`, {
|
|
identifier,
|
|
channel: this.notification.data.chat_channel_title,
|
|
});
|
|
}
|
|
};
|
|
}
|
|
);
|
|
}
|
|
|
|
if (api.registerUserMenuTab) {
|
|
api.registerUserMenuTab((UserMenuTab) => {
|
|
return class extends UserMenuTab {
|
|
get id() {
|
|
return "chat-notifications";
|
|
}
|
|
|
|
get panelComponent() {
|
|
return "user-menu/chat-notifications-list";
|
|
}
|
|
|
|
get icon() {
|
|
return "comment";
|
|
}
|
|
|
|
get count() {
|
|
return (
|
|
this.getUnreadCountForType("chat_mention") +
|
|
this.getUnreadCountForType("chat_invitation")
|
|
);
|
|
}
|
|
|
|
get notificationTypes() {
|
|
return [
|
|
"chat_invitation",
|
|
"chat_mention",
|
|
"chat_message",
|
|
"chat_quoted",
|
|
];
|
|
}
|
|
};
|
|
});
|
|
}
|
|
});
|
|
},
|
|
};
|