DEV: Add ID to channel show route (#223)

DEV: Add ID to channel show route (#223)

diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb
index fa4487b..ff07d78 100644
--- a/app/controllers/chat_channels_controller.rb
+++ b/app/controllers/chat_channels_controller.rb
@@ -21,23 +21,6 @@ class DiscourseChat::ChatChannelsController < DiscourseChat::ChatBaseController
     render_serialized(@chat_channel, ChatChannelSerializer)
   end
 
-  def get_by_title
-    params.require(:title)
-    all_channels = ChatChannel.all
-    channel = all_channels.detect { |c| c.title(current_user) == params[:title] }
-    raise Discourse::NotFound unless channel
-
-    chatable = nil
-    if channel.site_channel?
-      guardian.ensure_can_access_site_chat!
-    else
-      chatable = channel.chatable
-      guardian.ensure_can_see!(chatable)
-    end
-
-    render_serialized(channel, ChatChannelSerializer)
-  end
-
   def follow
     params.require(:chat_channel_id)
 
diff --git a/assets/javascripts/discourse/chat-route-map.js b/assets/javascripts/discourse/chat-route-map.js
index 4cfa864..4504653 100644
--- a/assets/javascripts/discourse/chat-route-map.js
+++ b/assets/javascripts/discourse/chat-route-map.js
@@ -1,5 +1,5 @@
 export default function () {
   this.route("chat", { path: "/chat" }, function () {
-    this.route("channel", { path: "/channel/:channelTitle" });
+    this.route("channel", { path: "/channel/:channelId/:channelTitle" });
   });
 }
diff --git a/assets/javascripts/discourse/components/chat-channel-row.js b/assets/javascripts/discourse/components/chat-channel-row.js
index f2cc87a..552a493 100644
--- a/assets/javascripts/discourse/components/chat-channel-row.js
+++ b/assets/javascripts/discourse/components/chat-channel-row.js
@@ -33,7 +33,10 @@ export default Component.extend({
     if (e.which === 2) {
       // Middle mouse click
       window
-        .open(getURL(`/chat/channel/${this.channel.title}`), "_blank")
+        .open(
+          getURL(`/chat/channel/${this.channel.id}/${this.channel.title}`),
+          "_blank"
+        )
         .focus();
     }
   },
@@ -50,7 +53,7 @@ export default Component.extend({
   active(channel, currentRoute) {
     return (
       currentRoute?.name === "chat.channel" &&
-      currentRoute?.params?.channelTitle === channel.title.toString(10)
+      currentRoute?.params?.channelId === channel.id.toString(10)
     );
   },
 
diff --git a/assets/javascripts/discourse/components/chat-channel-settings-row.js b/assets/javascripts/discourse/components/chat-channel-settings-row.js
index 72153c1..658ef1e 100644
--- a/assets/javascripts/discourse/components/chat-channel-settings-row.js
+++ b/assets/javascripts/discourse/components/chat-channel-settings-row.js
@@ -104,6 +104,10 @@ export default Component.extend({
   @action
   previewChannel() {
     this.closeModal();
-    this.router.transitionTo("chat.channel", this.channel.title);
+    this.router.transitionTo(
+      "chat.channel",
+      this.channel.id,
+      this.channel.title
+    );
   },
 });
diff --git a/assets/javascripts/discourse/components/full-page-chat.js b/assets/javascripts/discourse/components/full-page-chat.js
index ca2604f..c258520 100644
--- a/assets/javascripts/discourse/components/full-page-chat.js
+++ b/assets/javascripts/discourse/components/full-page-chat.js
@@ -92,7 +92,7 @@ export default Component.extend({
     this.set("showingChannels", false);
 
     if (channel.id !== this.chatChannel.id) {
-      this.router.transitionTo("chat.channel", channel.title);
+      this.router.transitionTo("chat.channel", channel.id, channel.title);
     }
     return false;
   },
diff --git a/assets/javascripts/discourse/components/sidebar-channels.js b/assets/javascripts/discourse/components/sidebar-channels.js
index 75ffaa9..e447785 100644
--- a/assets/javascripts/discourse/components/sidebar-channels.js
+++ b/assets/javascripts/discourse/components/sidebar-channels.js
@@ -57,7 +57,7 @@ export default Component.extend({
       this.site.mobileView ||
       this.router.currentRouteName === "chat.channel"
     ) {
-      this.router.transitionTo("chat.channel", channel.title);
+      this.router.transitionTo("chat.channel", channel.id, channel.title);
     } else {
       this.appEvents.trigger("chat:open-channel", channel);
     }
diff --git a/assets/javascripts/discourse/components/topic-chat-float.js b/assets/javascripts/discourse/components/topic-chat-float.js
index 027ad65..c30809c 100644
--- a/assets/javascripts/discourse/components/topic-chat-float.js
+++ b/assets/javascripts/discourse/components/topic-chat-float.js
@@ -216,7 +216,9 @@ export default Component.extend({
     const channel = this.activeChannel;
     if (e.which === 2) {
       // Middle mouse click
-      window.open(getURL(`/chat/channel/${channel.title}`), "_blank").focus();
+      window
+        .open(getURL(`/chat/channel/${channel.id}/${channel.title}`), "_blank")
+        .focus();
       return false;
     }
 
@@ -227,7 +229,11 @@ export default Component.extend({
       activeChannel: null,
     });
     if (channel) {
-      return this.router.transitionTo("chat.channel", channel.title);
+      return this.router.transitionTo(
+        "chat.channel",
+        channel.id,
+        channel.title
+      );
     }
 
     this.router.transitionTo("chat");
diff --git a/assets/javascripts/discourse/controllers/chat-index.js b/assets/javascripts/discourse/controllers/chat-index.js
index edf407b..5ec42ae 100644
--- a/assets/javascripts/discourse/controllers/chat-index.js
+++ b/assets/javascripts/discourse/controllers/chat-index.js
@@ -20,7 +20,7 @@ export default Controller.extend({
   @action
   afterDmCreation(chatChannel) {
     this.cancelDmCreation();
-    this.router.transitionTo("chat.channel", chatChannel.title);
+    this.router.transitionTo("chat.channel", chatChannel.id, chatChannel.title);
   },
 
   @action
diff --git a/assets/javascripts/discourse/routes/chat-channel.js b/assets/javascripts/discourse/routes/chat-channel.js
index d6c7978..5c64add 100644
--- a/assets/javascripts/discourse/routes/chat-channel.js
+++ b/assets/javascripts/discourse/routes/chat-channel.js
@@ -19,25 +19,25 @@ export default DiscourseRoute.extend({
 
   async model(params) {
     let [[chatChannel, previewing], channels] = await Promise.all([
-      this.getChannel(params.channelTitle),
+      this.getChannel(params.channelId),
       this.chat.getChannels(),
     ]);
 
     return EmberObject.create({ chatChannel, channels, previewing });
   },
 
-  async getChannel(title) {
-    let channel = await this.chat.getChannelBy("title", title);
+  async getChannel(id) {
+    let channel = await this.chat.getChannelBy("id", id);
     let previewing = false;
     if (!channel) {
-      channel = await this.getChannelFromServer(title);
+      channel = await this.getChannelFromServer(id);
       previewing = true;
     }
     return [channel, previewing];
   },
 
-  async getChannelFromServer(title) {
-    return ajax(`/chat/chat_channels/by_title/${title}`)
+  async getChannelFromServer(id) {
+    return ajax(`/chat/chat_channels/${id}`)
       .then((response) => {
         return response.chat_channel;
       })
diff --git a/assets/javascripts/discourse/routes/chat.js b/assets/javascripts/discourse/routes/chat.js
index b0dd8e5..a526937 100644
--- a/assets/javascripts/discourse/routes/chat.js
+++ b/assets/javascripts/discourse/routes/chat.js
@@ -23,9 +23,13 @@ export default DiscourseRoute.extend({
       return;
     }
 
-    return this.chat.getIdealFirstChannelTitle().then((channelTitle) => {
-      if (channelTitle) {
-        return this.transitionTo("chat.channel", channelTitle);
+    return this.chat.getIdealFirstChannelIdAndTitle().then((channelInfo) => {
+      if (channelInfo) {
+        return this.transitionTo(
+          "chat.channel",
+          channelInfo.id,
+          channelInfo.title
+        );
       }
     });
   },

[... diff too long, it was truncated ...]

GitHub sha: ba54c3583bec1b987eb3d3700ba660a1efa0828a

This commit appears in #223 which was approved by eviltrout. It was merged by markvanlan.