Skip to content

A platform for community discussion. Free, open, simple.

FIX: Chat channel onebox icons render and support channel emoji (#39826)

Régis Hanolce2767cf3804
diff --git a/plugins/chat/db/post_migrate/20260507083943_rebake_chat_onebox_posts.rb b/plugins/chat/db/post_migrate/20260507083943_rebake_chat_onebox_posts.rb
new file mode 100644
index 00000000000..32e536b64f3
--- /dev/null
+++ b/plugins/chat/db/post_migrate/20260507083943_rebake_chat_onebox_posts.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class RebakeChatOneboxPosts < ActiveRecord::Migration[8.0]
+ def up
+ execute <<~SQL
+ UPDATE posts
+ SET baked_version = 0
+ WHERE cooked LIKE '%chat-onebox%'
+ SQL
+ end
+
+ def down
+ end
+end
diff --git a/plugins/chat/lib/chat/onebox_handler.rb b/plugins/chat/lib/chat/onebox_handler.rb
index 9803fecc436..7098bd7c8db 100644
--- a/plugins/chat/lib/chat/onebox_handler.rb
+++ b/plugins/chat/lib/chat/onebox_handler.rb
@@ -40,11 +40,18 @@ module Chat
{
channel_id: chat_channel.id,
channel_name: chat_channel.name,
- is_category: chat_channel.category_channel?,
- color: chat_channel.category_channel? ? chat_channel.chatable.color : nil,
+ color: chat_channel.chatable.color,
+ channel_badge: build_channel_badge(chat_channel),
}
end
+ def self.build_channel_badge(chat_channel)
+ return Emoji.codes_to_img(":#{chat_channel.emoji}:") if chat_channel.emoji.present?
+
+ color = chat_channel.chatable.color
+ %(<span class="category-chat-badge" style="color: ##{color}"><svg class="fa d-icon d-icon-comment svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#comment"></use></svg></span>)
+ end
+
def self.render_thread_onebox(args, thread)
args.merge!(
cooked: build_thread_snippet(thread),
diff --git a/plugins/chat/lib/onebox/templates/discourse_chat_channel.mustache b/plugins/chat/lib/onebox/templates/discourse_chat_channel.mustache
index 0766fb627b0..ceb95d6029a 100644
--- a/plugins/chat/lib/onebox/templates/discourse_chat_channel.mustache
+++ b/plugins/chat/lib/onebox/templates/discourse_chat_channel.mustache
@@ -2,11 +2,7 @@
<article class="onebox-body chat-onebox-body">
<h3 class="chat-onebox-title">
<a href="/chat/c/-/{{channel_id}}">
- {{#is_category}}
- <span class="category-chat-badge" style="color: #{{color}}">
- <svg class="fa d-icon d-icon-d-chat svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#d-chat"></use></svg>
- </span>
- {{/is_category}}
+ {{{channel_badge}}}
<span class="clear-badge">{{channel_name}}</span>
</a>
</h3>
diff --git a/plugins/chat/lib/onebox/templates/discourse_chat_message.mustache b/plugins/chat/lib/onebox/templates/discourse_chat_message.mustache
index 0d3ed10ec09..04549f94093 100644
--- a/plugins/chat/lib/onebox/templates/discourse_chat_message.mustache
+++ b/plugins/chat/lib/onebox/templates/discourse_chat_message.mustache
@@ -15,16 +15,7 @@
{{/thread_id}}
</div>
<a class="chat-transcript-channel" href="/chat/c/-/{{channel_id}}">
- {{#is_category}}
- <span class="category-chat-badge" style="color: #{{color}}">
- <svg class="fa d-icon d-icon-d-chat svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#d-chat"></use></svg>
- </span>
- {{/is_category}}
- {{#is_topic}}
- <span class="topic-chat-icon">
- <svg class="fa d-icon d-icon-far-comments svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#far-comments"></use></svg>
- </span>
- {{/is_topic}}
+ {{{channel_badge}}}
{{channel_name}}
</a>
{{#thread_id}}
diff --git a/plugins/chat/lib/onebox/templates/discourse_chat_thread.mustache b/plugins/chat/lib/onebox/templates/discourse_chat_thread.mustache
index 0c53339da69..1386cf5a7d0 100644
--- a/plugins/chat/lib/onebox/templates/discourse_chat_thread.mustache
+++ b/plugins/chat/lib/onebox/templates/discourse_chat_thread.mustache
@@ -11,9 +11,7 @@
</h3>
<span class="thread-title-connector">{{thread_title_connector}}</span>
<a href="/chat/c/-/{{channel_id}}">
- <span class="category-chat-badge" style="color: #{{color}}">
- <svg class="fa d-icon d-icon-d-chat svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#d-chat"></use></svg>
- </span>
+ {{{channel_badge}}}
<span class="clear-badge">{{channel_name}}</span>
</a>
</div>
diff --git a/plugins/chat/spec/lib/chat/onebox_handler_spec.rb b/plugins/chat/spec/lib/chat/onebox_handler_spec.rb
index 08ec5d64c4b..f7890a98098 100644
--- a/plugins/chat/spec/lib/chat/onebox_handler_spec.rb
+++ b/plugins/chat/spec/lib/chat/onebox_handler_spec.rb
@@ -30,7 +30,7 @@ describe Chat::OneboxHandler do
<h3 class="chat-onebox-title">
<a href="/chat/c/-/#{public_channel.id}">
<span class="category-chat-badge" style="color: ##{public_channel.chatable.color}">
- <svg class="fa d-icon d-icon-d-chat svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#d-chat"></use></svg>
+ <svg class="fa d-icon d-icon-comment svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#comment"></use></svg>
</span>
<span class="clear-badge">#{public_channel.name}</span>
</a>
@@ -45,6 +45,28 @@ describe Chat::OneboxHandler do
</aside>
HTML
end
+
+ it "renders the channel emoji in place of the chat bubble when set" do
+ public_channel.update!(emoji: "tada")
+
+ onebox_html = Chat::OneboxHandler.handle(public_chat_url, { channel_id: public_channel.id })
+
+ expect(onebox_html).to match_html <<~HTML
+ <aside class="onebox chat-onebox">
+ <article class="onebox-body chat-onebox-body">
+ <h3 class="chat-onebox-title">
+ <a href="/chat/c/-/#{public_channel.id}">
+ <img src="/images/emoji/twitter/tada.png?v=15" title="tada" class="emoji" alt="tada" loading="lazy" width="20" height="20">
+ <span class="clear-badge">#{public_channel.name}</span>
+ </a>
+ </h3>
+ <div class="chat-onebox-members-count">0 members</div>
+ <div class="chat-onebox-members">
+ </div>
+ </article>
+ </aside>
+ HTML
+ end
end
context "when channel is private" do
@@ -95,7 +117,7 @@ describe Chat::OneboxHandler do
</div>
<a class="chat-transcript-channel" href="/chat/c/-/#{public_channel.id}">
<span class="category-chat-badge" style="color: ##{public_channel.chatable.color}">
- <svg class="fa d-icon d-icon-d-chat svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#d-chat"></use></svg>
+ <svg class="fa d-icon d-icon-comment svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#comment"></use></svg>
</span>
#{public_channel.name}
</a>
@@ -164,7 +186,7 @@ describe Chat::OneboxHandler do
<span class="thread-title-connector">in</span>
<a href="/chat/c/-/#{public_channel.id}">
<span class="category-chat-badge" style="color: ##{public_channel.chatable.color}">
- <svg class="fa d-icon d-icon-d-chat svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#d-chat"></use></svg>
+ <svg class="fa d-icon d-icon-comment svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#comment"></use></svg>
</span>
<span class="clear-badge">#{public_channel.name}</span>
</a>
@@ -206,7 +228,7 @@ describe Chat::OneboxHandler do
<h3 class="chat-onebox-title">
<a href="/chat/c/-/#{public_channel.id}">
<span class="category-chat-badge" style="color: ##{public_channel.chatable.color}">
- <svg class="fa d-icon d-icon-d-chat svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#d-chat"></use></svg>
+ <svg class="fa d-icon d-icon-comment svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#comment"></use></svg>
</span>
<span class="clear-badge">#{public_channel.name}</span>
</a>