mirror of
https://github.com/discourse/discourse.git
synced 2026-08-02 09:29:37 -05:00
FIX: ensures users can open channel invites (#24067)
We were incorrectly generating URLs with message id even when it was not provided, resulting in a route ending with "undefined", which was causing an error. This commit also uses this opportunity to: - move `invite_users` into a proper controller inside the API namespace - refactors the code into a service: `Chat::InviteUsersToChannel`
This commit is contained in:
@@ -299,7 +299,7 @@ export default class ChatChannel extends Component {
|
||||
let foundFirstNew = false;
|
||||
const hasNewest = this.messagesManager.messages.some((m) => m.newest);
|
||||
|
||||
result.messages.forEach((messageData, index) => {
|
||||
result?.messages?.forEach((messageData, index) => {
|
||||
messageData.firstOfResults = index === 0;
|
||||
|
||||
if (this.currentUser.ignored_users) {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
{{#if @channel.id}}
|
||||
<ChatChannel
|
||||
@channel={{@channel}}
|
||||
@targetMessageId={{readonly @targetMessageId}}
|
||||
/>
|
||||
<ChatChannel @channel={{@channel}} @targetMessageId={{@targetMessageId}} />
|
||||
{{/if}}
|
||||
@@ -18,22 +18,24 @@ export default {
|
||||
"chat_invitation",
|
||||
(NotificationItemBase) => {
|
||||
return class extends NotificationItemBase {
|
||||
linkTitle = I18n.t("notifications.titles.chat_invitation");
|
||||
icon = "link";
|
||||
description = I18n.t("notifications.chat_invitation");
|
||||
|
||||
get linkHref() {
|
||||
const data = this.notification.data;
|
||||
const slug = slugifyChannel({
|
||||
title: this.notification.data.chat_channel_title,
|
||||
slug: this.notification.data.chat_channel_slug,
|
||||
title: data.chat_channel_title,
|
||||
slug: 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");
|
||||
}
|
||||
let url = `/chat/c/${slug || "-"}/${data.chat_channel_id}`;
|
||||
|
||||
get icon() {
|
||||
return "link";
|
||||
if (data.chat_message_id) {
|
||||
url += `/${data.chat_message_id}`;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
get label() {
|
||||
@@ -41,10 +43,6 @@ export default {
|
||||
this.notification.data.invited_by_username
|
||||
);
|
||||
}
|
||||
|
||||
get description() {
|
||||
return I18n.t("notifications.chat_invitation");
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
@@ -473,9 +473,9 @@ export default class ChatApi extends Service {
|
||||
* @param {number} options.chat_message_id - A message ID to display in the invite.
|
||||
*/
|
||||
invite(channelId, userIds, options = {}) {
|
||||
return ajax(`/chat/${channelId}/invite`, {
|
||||
type: "put",
|
||||
data: { user_ids: userIds, chat_message_id: options.messageId },
|
||||
return this.#postRequest(`/channels/${channelId}/invites`, {
|
||||
user_ids: userIds,
|
||||
message_id: options.messageId,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+8
-3
@@ -38,8 +38,13 @@ createWidgetFrom(DefaultNotificationItem, "chat-invitation-notification-item", {
|
||||
title: data.chat_channel_title,
|
||||
slug: data.chat_channel_slug,
|
||||
});
|
||||
return `/chat/c/${slug || "-"}/${data.chat_channel_id}/${
|
||||
data.chat_message_id
|
||||
}`;
|
||||
|
||||
let url = `/chat/c/${slug || "-"}/${data.chat_channel_id}`;
|
||||
|
||||
if (data.chat_message_id) {
|
||||
url += `/${data.chat_message_id}`;
|
||||
}
|
||||
|
||||
return url;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user