Roman Rizzi 5c699e4384
DEV: Pass messageId as a dynamic segment instead of a query param (#20013)
* DEV: Rnemae channel path to just c

Also swap the channel id and channel slug params to be consistent with core.

* linting

* channel_path

* Drop slugify helper and channel route without slug

* Request slug and route models through the channel model if possible

* DEV: Pass messageId as a dynamic segment instead of a query param

* Ensure change is backwards-compatible

* drop query param from oneboxes

* Correctly extract channelId from routes

* Better route organization using siblings for regular and near-message

* Ensures sessions are unique even when using parallelism

* prevents didReceiveAttrs to clear input mid test

* we disable animations in capybara so sometimes the message was barely showing

* adds wait

* ensures finished loading

* is it causing more harm than good?

* this check is slowing things for no reason

* actually target the button

* more resilient select chat message

* apply similar fix to bookmark

* fix

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-02-01 12:39:23 -03:00

139 lines
4.0 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/c/${slug || "-"}/${
this.notification.data.chat_channel_id
}/${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/c/${slug || "-"}/${
this.notification.data.chat_channel_id
}/${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",
];
}
};
});
}
});
},
};