DEV: /channel -> /c chat route rename (#19782)
* DEV: Rnemae channel path to just c Also swap the channel id and channel slug params to be consistent with core. * linting * channel_path * params in wrong order * Drop slugify helper and channel route without slug * Request slug and route models through the channel model if possible * Add client side redirection for backwards-compatibility Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
export default function () {
|
||||
this.route("chat", { path: "/chat" }, function () {
|
||||
// TODO(roman): Remove after the 3.1 release
|
||||
this.route("channel-legacy", {
|
||||
path: "/channel/:channelId/:channelTitle",
|
||||
});
|
||||
|
||||
this.route(
|
||||
"channel",
|
||||
{ path: "/channel/:channelId/:channelTitle" },
|
||||
{ path: "/c/:channelTitle/:channelId/" },
|
||||
function () {
|
||||
this.route("info", { path: "/info" }, function () {
|
||||
this.route("about", { path: "/about" });
|
||||
|
||||
@@ -24,10 +24,7 @@
|
||||
<DButton
|
||||
@class="edit-name-btn btn-flat"
|
||||
@label="chat.channel_settings.edit"
|
||||
@action={{if
|
||||
this.onEditChatChannelName
|
||||
this.onEditChatChannelName
|
||||
}}
|
||||
@action={{if this.onEditChatChannelName this.onEditChatChannelName}}
|
||||
/>
|
||||
</div>
|
||||
{{/if}}
|
||||
@@ -90,4 +87,4 @@
|
||||
leaveIcon="sign-out-alt"
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -11,7 +11,7 @@
|
||||
<div class="chat-channel-card__header">
|
||||
<LinkTo
|
||||
@route="chat.channel"
|
||||
@models={{array @channel.id (slugify-channel @channel)}}
|
||||
@models={{@channel.routeModels}}
|
||||
class="chat-channel-card__name-container"
|
||||
>
|
||||
<span class="chat-channel-card__name">
|
||||
@@ -26,7 +26,7 @@
|
||||
{{#if @channel.currentUserMembership.muted}}
|
||||
<LinkTo
|
||||
@route="chat.channel.info.settings"
|
||||
@models={{array @channel.id (slugify-channel @channel)}}
|
||||
@models={{@channel.routeModels}}
|
||||
class="chat-channel-card__tag -muted"
|
||||
tabindex="-1"
|
||||
>
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
<LinkTo
|
||||
@route="chat.channel.info.settings"
|
||||
@models={{array @channel.id (slugify-channel @channel)}}
|
||||
@models={{@channel.routeModels}}
|
||||
class="chat-channel-card__setting"
|
||||
tabindex="-1"
|
||||
>
|
||||
@@ -79,7 +79,7 @@
|
||||
{{#if (gt @channel.membershipsCount 0)}}
|
||||
<LinkTo
|
||||
@route="chat.channel.info.members"
|
||||
@models={{array @channel.id (slugify-channel @channel)}}
|
||||
@models={{@channel.routeModels}}
|
||||
class="chat-channel-card__members"
|
||||
tabindex="-1"
|
||||
>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<LinkTo
|
||||
@route="chat.channel"
|
||||
@models={{array @channel.id (or @channel.slug "-")}}
|
||||
@models={{@channel.routeModels}}
|
||||
class={{concat-class
|
||||
"chat-channel-row"
|
||||
(if @channel.focused "focused")
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
|
||||
<ChatChannelArchiveStatus @channel={{this.channel}} />
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
@@ -47,10 +47,7 @@
|
||||
{{#if this.chatStateManager.isDrawerExpanded}}
|
||||
<LinkTo
|
||||
@route={{this.infoTabRoute}}
|
||||
@models={{array
|
||||
this.chat.activeChannel.id
|
||||
(slugify-channel this.chat.activeChannel)
|
||||
}}
|
||||
@models={{this.chat.activeChannel.routeModels}}
|
||||
class="chat-drawer-header__title"
|
||||
>
|
||||
<div class="chat-drawer-header__top-line">
|
||||
|
||||
@@ -306,7 +306,7 @@ export default Component.extend({
|
||||
return "/chat/draft-channel";
|
||||
case CHAT_VIEW:
|
||||
if (channel) {
|
||||
return `/chat/channel/${channel.id}/${channel.slug || "-"}`;
|
||||
return `/chat/c/${channel.slug || "-"}/${channel.id}`;
|
||||
} else {
|
||||
return "/chat";
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<LinkTo
|
||||
@route={{this.infoTabRoute}}
|
||||
@models={{array this.chatChannel.id (slugify-channel this.chatChannel)}}
|
||||
@models={{this.chatChannel.routeModels}}
|
||||
class="chat-channel-title-wrapper"
|
||||
>
|
||||
<ChatChannelTitle @channel={{this.chatChannel}} />
|
||||
@@ -152,4 +152,4 @@
|
||||
{{else}}
|
||||
<ChatChannelPreviewCard @channel={{this.chatChannel}} />
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
@@ -786,7 +786,7 @@ export default Component.extend({
|
||||
|
||||
const { protocol, host } = window.location;
|
||||
let url = getURL(
|
||||
`/chat/channel/${this.details.chat_channel_id}/-?messageId=${this.message.id}`
|
||||
`/chat/c/-/${this.details.chat_channel_id}?messageId=${this.message.id}`
|
||||
);
|
||||
url = url.indexOf("/") === 0 ? protocol + "//" + host + url : url;
|
||||
clipboardCopy(url);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="flagged-post-header">
|
||||
<LinkTo
|
||||
@route="chat.channel"
|
||||
@models={{array this.chatChannel.id this.chatChannel.title}}
|
||||
@models={{this.chatChannel.routeModels}}
|
||||
@query={{hash messageId=@reviewable.target_id}}
|
||||
>
|
||||
<ChatChannelTitle @channel={{this.chatChannel}} />
|
||||
|
||||
@@ -15,7 +15,7 @@ registerUnbound("format-chat-date", function (message, details, mode) {
|
||||
|
||||
if (details) {
|
||||
url = getURL(
|
||||
`/chat/channel/${details.chat_channel_id}/-?messageId=${message.id}`
|
||||
`/chat/c/-/${details.chat_channel_id}?messageId=${message.id}`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
||||
import Helper from "@ember/component/helper";
|
||||
|
||||
export default class SlugifyChannel extends Helper {
|
||||
compute(inputs) {
|
||||
return slugifyChannel(inputs[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { htmlSafe } from "@ember/template";
|
||||
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import I18n from "I18n";
|
||||
import { bind } from "discourse-common/utils/decorators";
|
||||
@@ -32,7 +31,7 @@ export default {
|
||||
}
|
||||
|
||||
get name() {
|
||||
return dasherize(slugifyChannel(this.channel));
|
||||
return dasherize(this.channel.slugifiedTitle);
|
||||
}
|
||||
|
||||
@computed("chatService.activeChannel")
|
||||
@@ -57,7 +56,7 @@ export default {
|
||||
}
|
||||
|
||||
get models() {
|
||||
return [this.channel.id, slugifyChannel(this.channel)];
|
||||
return this.channel.routeModels;
|
||||
}
|
||||
|
||||
get text() {
|
||||
@@ -195,7 +194,7 @@ export default {
|
||||
}
|
||||
|
||||
get name() {
|
||||
return slugifyChannel(this.channel);
|
||||
return this.channel.slugifiedTitle;
|
||||
}
|
||||
|
||||
@computed("chatService.activeChannel")
|
||||
@@ -220,7 +219,7 @@ export default {
|
||||
}
|
||||
|
||||
get models() {
|
||||
return [this.channel.id, slugifyChannel(this.channel)];
|
||||
return this.channel.routeModels;
|
||||
}
|
||||
|
||||
get title() {
|
||||
|
||||
@@ -24,11 +24,9 @@ export default {
|
||||
title: this.notification.data.chat_channel_title,
|
||||
slug: this.notification.data.chat_channel_slug,
|
||||
});
|
||||
return `/chat/channel/${
|
||||
return `/chat/c/${slug || "-"}/${
|
||||
this.notification.data.chat_channel_id
|
||||
}/${slug || "-"}?messageId=${
|
||||
this.notification.data.chat_message_id
|
||||
}`;
|
||||
}?messageId=${this.notification.data.chat_message_id}`;
|
||||
}
|
||||
|
||||
get linkTitle() {
|
||||
@@ -61,11 +59,9 @@ export default {
|
||||
title: this.notification.data.chat_channel_title,
|
||||
slug: this.notification.data.chat_channel_slug,
|
||||
});
|
||||
return `/chat/channel/${
|
||||
return `/chat/c/${slug || "-"}/${
|
||||
this.notification.data.chat_channel_id
|
||||
}/${slug || "-"}?messageId=${
|
||||
this.notification.data.chat_message_id
|
||||
}`;
|
||||
}?messageId=${this.notification.data.chat_message_id}`;
|
||||
}
|
||||
|
||||
get linkTitle() {
|
||||
|
||||
@@ -4,6 +4,11 @@ export default function slugifyChannel(channel) {
|
||||
if (channel.slug) {
|
||||
return channel.slug;
|
||||
}
|
||||
|
||||
if (!channel.escapedTitle && !channel.title) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
const slug = slugify(channel.escapedTitle || channel.title);
|
||||
const resolvedSlug = (
|
||||
slug.length
|
||||
|
||||
@@ -5,6 +5,7 @@ import UserChatChannelMembership from "discourse/plugins/chat/discourse/models/u
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { escapeExpression } from "discourse/lib/utilities";
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
||||
|
||||
export const CHATABLE_TYPES = {
|
||||
directMessageChannel: "DirectMessage",
|
||||
@@ -73,6 +74,14 @@ export default class ChatChannel extends RestModel {
|
||||
return escapeExpression(this.description);
|
||||
}
|
||||
|
||||
get slugifiedTitle() {
|
||||
return this.slug || slugifyChannel(this);
|
||||
}
|
||||
|
||||
get routeModels() {
|
||||
return [this.slugifiedTitle, this.id];
|
||||
}
|
||||
|
||||
get isDirectMessageChannel() {
|
||||
return this.chatable_type === CHATABLE_TYPES.directMessageChannel;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import { inject as service } from "@ember/service";
|
||||
|
||||
export default class ChatChannelLegacyRoute extends DiscourseRoute {
|
||||
@service router;
|
||||
|
||||
redirect() {
|
||||
const { channelTitle, channelId, messageId } = this.paramsFor(
|
||||
this.routeName
|
||||
);
|
||||
|
||||
this.router.replaceWith("chat.channel", channelTitle, channelId, {
|
||||
queryParams: { messageId },
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import { inject as service } from "@ember/service";
|
||||
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
||||
import { action } from "@ember/object";
|
||||
import { schedule } from "@ember/runloop";
|
||||
|
||||
@@ -17,9 +16,8 @@ export default class ChatChannelRoute extends DiscourseRoute {
|
||||
this.chat.setActiveChannel(model);
|
||||
|
||||
const { channelTitle, messageId } = this.paramsFor(this.routeName);
|
||||
const slug = slugifyChannel(model);
|
||||
if (channelTitle !== slug) {
|
||||
this.router.replaceWith("chat.channel.index", model.id, slug, {
|
||||
if (channelTitle !== model.slugifiedTitle) {
|
||||
this.router.replaceWith("chat.channel.index", ...model.routeModels, {
|
||||
queryParams: { messageId },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ export default class ChatMessageRoute extends DiscourseRoute {
|
||||
.then((response) => {
|
||||
this.transitionTo(
|
||||
"chat.channel",
|
||||
response.chat_channel_id,
|
||||
response.chat_channel_title,
|
||||
response.chat_channel_id,
|
||||
{
|
||||
queryParams: { messageId: params.messageId },
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ export default class ChatNotificationManager extends Service {
|
||||
|
||||
@bind
|
||||
_pageChanged(path) {
|
||||
this.set("_inChat", path.startsWith("/chat/channel/"));
|
||||
this.set("_inChat", path.startsWith("/chat/c/"));
|
||||
if (this._inChat) {
|
||||
this._chatPresenceChannel.enter({ onlyWhileActive: false });
|
||||
this._corePresenceChannel.leave();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import userSearch from "discourse/lib/user-search";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
@@ -297,8 +296,8 @@ export default class Chat extends Service {
|
||||
|
||||
return this.router.transitionTo(
|
||||
"chat.channel",
|
||||
channel.slugifiedTitle,
|
||||
channel.id,
|
||||
slugifyChannel(channel),
|
||||
{ queryParams }
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
@channel={{this.model}}
|
||||
@onEditChatChannelName={{action "onEditChatChannelName"}}
|
||||
@onEditChatChannelDescription={{action "onEditChatChannelDescription"}}
|
||||
/>
|
||||
/>
|
||||
@@ -13,7 +13,7 @@
|
||||
{{else}}
|
||||
<LinkTo
|
||||
@route="chat.channel"
|
||||
@models={{array this.model.id (slugify-channel this.model)}}
|
||||
@models={{this.model.routeModels}}
|
||||
class="chat-full-page-header__back-btn no-text btn-flat btn"
|
||||
title={{i18n "chat.channel_info.back_to_channel"}}
|
||||
>
|
||||
@@ -38,7 +38,7 @@
|
||||
>
|
||||
<LinkTo
|
||||
@route={{concat "chat.channel.info." tab}}
|
||||
@models={{array this.model.id (slugify-channel this.model)}}
|
||||
@models={{this.model.routeModels}}
|
||||
class="chat-tabs-list__link"
|
||||
>
|
||||
<span>{{i18n (concat "chat.channel_info.tabs." tab)}}</span>
|
||||
@@ -62,4 +62,4 @@
|
||||
{{outlet}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+1
-1
@@ -19,4 +19,4 @@
|
||||
@disabled={{this.isSaveDisabled}}
|
||||
/>
|
||||
<DModalCancel @close={{route-action "closeModal"}} />
|
||||
</div>
|
||||
</div>
|
||||
@@ -85,4 +85,4 @@
|
||||
@label="chat.create_channel.create"
|
||||
@disabled={{this.createDisabled}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
+1
-1
@@ -38,7 +38,7 @@ createWidgetFrom(DefaultNotificationItem, "chat-invitation-notification-item", {
|
||||
title: data.chat_channel_title,
|
||||
slug: data.chat_channel_slug,
|
||||
});
|
||||
return `/chat/channel/${data.chat_channel_id}/${slug || "-"}?messageId=${
|
||||
return `/chat/c/${slug || "-"}/${data.chat_channel_id}?messageId=${
|
||||
data.chat_message_id
|
||||
}`;
|
||||
},
|
||||
|
||||
@@ -48,7 +48,7 @@ const chatNotificationItem = {
|
||||
title: data.chat_channel_title,
|
||||
slug: data.chat_channel_slug,
|
||||
});
|
||||
return `/chat/channel/${data.chat_channel_id}/${slug || "-"}?messageId=${
|
||||
return `/chat/c/${slug || "-"}/${data.chat_channel_id}?messageId=${
|
||||
data.chat_message_id
|
||||
}`;
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@ const chatTranscriptRule = {
|
||||
const channelName = tagInfo.attrs.channel;
|
||||
const channelId = tagInfo.attrs.channelId;
|
||||
const channelLink = channelId
|
||||
? options.getURL(`/chat/channel/${channelId}/-`)
|
||||
? options.getURL(`/chat/c/-/${channelId}`)
|
||||
: null;
|
||||
|
||||
if (!username || !messageIdStart || !messageTimeStart) {
|
||||
|
||||
Reference in New Issue
Block a user