A platform for community discussion. Free, open, simple.
FEATURE: chat channel emojis (#36288)
David Battersby7564bec8b80f
diff --git a/plugins/chat/app/controllers/chat/api/channels_controller.rb b/plugins/chat/app/controllers/chat/api/channels_controller.rbindex 0c47fa72d87..0cc7612c9dd 100644--- a/plugins/chat/app/controllers/chat/api/channels_controller.rb+++ b/plugins/chat/app/controllers/chat/api/channels_controller.rb@@ -1,7 +1,7 @@# frozen_string_literal: trueclass Chat::Api::ChannelsController < Chat::ApiController- CHANNEL_EDITABLE_PARAMS = %i[name description slug threading_enabled]+ CHANNEL_EDITABLE_PARAMS = %i[name description slug threading_enabled emoji]CATEGORY_CHANNEL_EDITABLE_PARAMS = %i[auto_join_users allow_channel_wide_mentions]def index@@ -49,6 +49,7 @@ class Chat::Api::ChannelsController < Chat::ApiController:description,:auto_join_users,:threading_enabled,+ :emoji,)# NOTE: We don't allow creating channels for anything but category chatable typesdiff --git a/plugins/chat/app/models/chat/category_channel.rb b/plugins/chat/app/models/chat/category_channel.rbindex 48c3e779b2e..4f04ea08264 100644--- a/plugins/chat/app/models/chat/category_channel.rb+++ b/plugins/chat/app/models/chat/category_channel.rb@@ -57,6 +57,7 @@ end# threading_enabled :boolean default(FALSE), not null# last_message_id :bigint# icon_upload_id :integer+# emoji :string## Indexes#diff --git a/plugins/chat/app/models/chat/channel.rb b/plugins/chat/app/models/chat/channel.rbindex 75a556e011b..6c835add43c 100644--- a/plugins/chat/app/models/chat/channel.rb+++ b/plugins/chat/app/models/chat/channel.rb@@ -312,6 +312,7 @@ end# threading_enabled :boolean default(FALSE), not null# last_message_id :bigint# icon_upload_id :integer+# emoji :string## Indexes#diff --git a/plugins/chat/app/models/chat/direct_message_channel.rb b/plugins/chat/app/models/chat/direct_message_channel.rbindex d1046d7d5fb..18a82dddac0 100644--- a/plugins/chat/app/models/chat/direct_message_channel.rb+++ b/plugins/chat/app/models/chat/direct_message_channel.rb@@ -65,6 +65,7 @@ end# threading_enabled :boolean default(FALSE), not null# last_message_id :bigint# icon_upload_id :integer+# emoji :string## Indexes#diff --git a/plugins/chat/app/serializers/chat/channel_serializer.rb b/plugins/chat/app/serializers/chat/channel_serializer.rbindex 7a8c2e37c9d..16ea4b92133 100644--- a/plugins/chat/app/serializers/chat/channel_serializer.rb+++ b/plugins/chat/app/serializers/chat/channel_serializer.rb@@ -10,6 +10,7 @@ module Chat:chatable_type,:chatable_url,:description,+ :emoji,:title,:unicode_title,:slug,@@ -38,6 +39,10 @@ module Chatobject.icon_upload&.urlend+ def include_emoji?+ object.emoji.present?+ end+def include_description?object.description.present?enddiff --git a/plugins/chat/app/services/chat/create_category_channel.rb b/plugins/chat/app/services/chat/create_category_channel.rbindex e6dfa61cf8b..d9e54b13376 100644--- a/plugins/chat/app/services/chat/create_category_channel.rb+++ b/plugins/chat/app/services/chat/create_category_channel.rb@@ -27,6 +27,7 @@ module Chat# @option params [Boolean] :auto_join_users# @option params [Integer] :category_id# @option params [Boolean] :threading_enabled+ # @option params [String] :emoji# @return [Service::Base::Context]policy :public_channels_enabled@@ -40,6 +41,7 @@ module Chatattribute :auto_join_users, :boolean, default: falseattribute :threading_enabled, :boolean, default: falseattribute :icon_upload_id, :integer+ attribute :emoji, :stringbefore_validation doself.auto_join_users = auto_join_users.presence || false@@ -88,6 +90,7 @@ module Chat:description,:auto_join_users,:threading_enabled,+ :emoji,),)enddiff --git a/plugins/chat/app/services/chat/update_channel.rb b/plugins/chat/app/services/chat/update_channel.rbindex fbcadd5bbb3..cf03c59c75b 100644--- a/plugins/chat/app/services/chat/update_channel.rb+++ b/plugins/chat/app/services/chat/update_channel.rb@@ -29,6 +29,7 @@ module Chat# @option params [String,nil] :name# @option params [String,nil] :description# @option params [String,nil] :slug+ # @option params [String,nil] :emoji# @option params [Integer,nil] :icon_upload_id# @option params [Boolean] :threading_enabled# @option params [Boolean] :auto_join_users Only valid for {CategoryChannel}. Whether active users with permission to see the category should automatically join the channel.@@ -45,10 +46,14 @@ module Chatattribute :auto_join_users, :boolean, default: falseattribute :allow_channel_wide_mentions, :boolean, default: trueattribute :icon_upload_id, :integer, default: nil+ attribute :emoji, :stringbefore_validation doassign_attributes(- attributes.symbolize_keys.slice(:name, :description, :slug).transform_values(&:presence),+ attributes+ .symbolize_keys+ .slice(:name, :description, :slug, :emoji)+ .transform_values(&:presence),)endenddiff --git a/plugins/chat/assets/javascripts/discourse/components/channel-icon/index.gjs b/plugins/chat/assets/javascripts/discourse/components/channel-icon/index.gjsindex 72135f8f99d..d83fd660324 100644--- a/plugins/chat/assets/javascripts/discourse/components/channel-icon/index.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/channel-icon/index.gjs@@ -1,6 +1,8 @@import Component from "@glimmer/component";import { htmlSafe } from "@ember/template";+import concatClass from "discourse/helpers/concat-class";import icon from "discourse/helpers/d-icon";+import replaceEmoji from "discourse/helpers/replace-emoji";import ChatUserAvatar from "discourse/plugins/chat/discourse/components/chat-user-avatar";export default class ChatChannelIcon extends Component {@@ -23,6 +25,16 @@ export default class ChatChannelIcon extends Component {return this.args.thread ?? false;}+ get categoryChannelIcon() {+ const { emoji } = this.args.channel;+ return emoji ? replaceEmoji(`:${emoji}:`) : icon("d-chat");+ }++ get directChannelIcon() {+ const { emoji, membershipsCount } = this.args.channel;+ return emoji ? replaceEmoji(`:${emoji}:`) : membershipsCount;+ }+<template>{{#if @channel.isDirectMessageChannel}}<div class="chat-channel-icon">@@ -31,8 +43,13 @@ export default class ChatChannelIcon extends Component {<img src={{@channel.iconUploadUrl}} /></span>{{else if this.groupDirectMessage}}- <span class="chat-channel-icon --users-count">- {{@channel.membershipsCount}}+ <span+ class={{concatClass+ "chat-channel-icon"+ (unless @channel.emoji "--users-count")+ }}+ >+ {{this.directChannelIcon}}</span>{{else}}<div class="chat-channel-icon --avatar">@@ -46,7 +63,7 @@ export default class ChatChannelIcon extends Component {class="chat-channel-icon --category-badge"style={{this.channelColorStyle}}>- {{icon "d-chat"}}+ {{this.categoryChannelIcon}}{{#if @channel.chatable.read_restricted}}{{icon "lock" class="chat-channel-icon__restricted-category-icon"}}{{/if}}diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.gjsindex a6b019bf53d..484a936ca0d 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.gjs@@ -8,7 +8,9 @@ import { cancel } from "@ember/runloop";import { service } from "@ember/service";import { htmlSafe } from "@ember/template";import { isBlank, isPresent } from "@ember/utils";+import DButton from "discourse/components/d-button";import DModal from "discourse/components/d-modal";+import EmojiPicker from "discourse/components/emoji-picker";import DTooltip from "discourse/float-kit/components/d-tooltip";import concatClass from "discourse/helpers/concat-class";import icon from "discourse/helpers/d-icon";@@ -19,6 +21,7 @@ import discourseDebounce from "discourse/lib/debounce";import { escapeExpression } from "discourse/lib/utilities";import Category from "discourse/models/category";import CategoryChooser from "discourse/select-kit/components/category-chooser";+import { not } from "discourse/truth-helpers";import I18n, { i18n } from "discourse-i18n";const DEFAULT_HINT = htmlSafe(@@ -43,6 +46,7 @@ export default class ChatModalCreateChannel extends Component {@tracked categoryPermissionsHint;@tracked autoJoinWarning = "";@tracked loadingPermissionHint = false;+ @tracked editedEmoji = null;#generateSlugHandler = null;@@ -89,6 +93,16 @@ export default class ChatModalCreateChannel extends Component {this.#debouncedGenerateSlug(name);}+ @action+ emojiSelected(emoji) {+ this.editedEmoji = emoji;+ }++ @action+ resetEmoji() {+ this.editedEmoji = null;+ }+@actiononSave(event) {event.preventDefault();@@ -102,6 +116,7 @@ export default class ChatModalCreateChannel extends Component {data.auto_join_users = data.auto_join_users === "on";data.slug ??= this.autoGeneratedSlug;data.threading_enabled = data.threading_enabled === "on";+ data.emoji = this.editedEmoji;if (data.auto_join_users) {this.dialog.yesNoConfirm({@@ -340,6 +355,27 @@ export default class ChatModalCreateChannel extends Component {{{/if}}</div>+ <div class="chat-modal-create-channel__control -emoji">+ <label for="emoji" class="chat-modal-create-channel__label">+ {{i18n "chat.create_channel.emoji.label"}}+ </label>++ <EmojiPicker+ @emoji={{this.editedEmoji}}+ @didSelectEmoji={{this.emojiSelected}}+ @btnClass="btn-emoji"+ @modalForMobile={{false}}+ @context="channel-emoji"+ />++ <DButton+ @label="chat.create_channel.emoji.reset"+ @action={{this.resetEmoji}}+ @disabled={{not this.editedEmoji}}+ class="btn-flat edit-channel-clear-emoji"+ />+ </div>+{{#if this.autoJoinAvailable}}<div class="chat-modal-create-channel__control -auto-join"><label class="chat-modal-create-channel__label">diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-name.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-name.gjsindex 07b87a9d59a..3a885a5318e 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-name.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-name.gjs@@ -8,10 +8,12 @@ import { service } from "@ember/service";import DButton from "discourse/components/d-button";import DModal from "discourse/components/d-modal";import DModalCancel from "discourse/components/d-modal-cancel";+import EmojiPicker from "discourse/components/emoji-picker";import DTooltip from "discourse/float-kit/components/d-tooltip";import { ajax } from "discourse/lib/ajax";import { extractError } from "discourse/lib/ajax-error";import discourseDebounce from "discourse/lib/debounce";+import { not } from "discourse/truth-helpers";import { i18n } from "discourse-i18n";import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";@@ -24,6 +26,7 @@ export default class ChatModalEditChannelName extends Component {@tracked editedName = this.channel.title;@tracked editedSlug = this.channel.slug;+ @tracked editedEmoji = this.channel.emoji;@trackedautoGeneratedSlug = this.channel.slug ?? slugifyChannel(this.channel);@tracked flash;@@ -37,7 +40,8 @@ export default class ChatModalEditChannelName extends Component {get isSaveDisabled() {return ((this.channel.title === this.editedName &&- this.channel.slug === this.editedSlug) ||+ this.channel.slug === this.editedSlug &&+ this.channel.emoji === this.editedEmoji) ||this.editedName?.length > this.siteSettings.max_topic_title_length ||this.editedSlug?.length > SLUG_MAX_LENGTH);@@ -49,10 +53,12 @@ export default class ChatModalEditChannelName extends Component {const result = await this.chatApi.updateChannel(this.channel.id, {name: this.editedName,slug: this.editedSlug || this.autoGeneratedSlug || this.channel.slug,+ emoji: this.editedEmoji,});this.channel.title = result.channel.title;this.channel.slug = result.channel.slug;+ this.channel.emoji = result.channel.emoji;await this.args.closeModal();this.router.replaceWith("chat.channel", ...this.channel.routeModels);} catch (error) {@@ -72,6 +78,16 @@ export default class ChatModalEditChannelName extends Component {this.#debouncedGenerateSlug(this.editedName);}+ @action+ emojiSelected(emoji) {+ this.editedEmoji = emoji;+ }++ @action+ resetEmoji() {+ this.editedEmoji = null;+ }+#debouncedGenerateSlug(name) {cancel(this.#generateSlugHandler);this.autoGeneratedSlug = "";@@ -145,6 +161,27 @@ export default class ChatModalEditChannelName extends Component {@value={{this.editedSlug}}/></div>+ <div class="edit-channel-control">+ <label for="channel-emoji" class="edit-channel-label">+ {{i18n "chat.channel_edit_name_slug_modal.emoji"}}+ </label>++ <EmojiPicker+ @emoji={{this.editedEmoji}}+ @didSelectEmoji={{this.emojiSelected}}+ @btnClass="btn-emoji"+ @modalForMobile={{false}}+ @context="channel-emoji"+ />++ <DButton+ @label="chat.channel_edit_name_slug_modal.reset_emoji"+ @action={{this.resetEmoji}}+ @disabled={{not this.editedEmoji}}+ class="btn-flat edit-channel-clear-emoji"+ />++ </div></:body><:footer><DButtondiff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.jsindex b17fa642955..f6025f3a4c3 100644--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js@@ -200,11 +200,11 @@ export default {}get prefixType() {- return "icon";+ return this.channel.emoji ? "emoji" : "icon";}get prefixValue() {- return "d-chat";+ return this.channel.emoji ?? "d-chat";}get prefixColor() {@@ -435,6 +435,8 @@ export default {get prefixType() {if (this.channel.iconUploadUrl) {return "image";+ } else if (this.channel.emoji) {+ return "emoji";} else if (this.channel.chatable.group) {return "text";} else {@@ -445,6 +447,8 @@ export default {get prefixValue() {if (this.channel.iconUploadUrl) {return this.channel.iconUploadUrl;+ } else if (this.channel.emoji) {+ return this.channel.emoji;} else if (this.channel.chatable.group) {return this.channel.membershipsCount;} else {diff --git a/plugins/chat/assets/javascripts/discourse/lib/hashtag-types/channel.js b/plugins/chat/assets/javascripts/discourse/lib/hashtag-types/channel.jsindex 723f1ea62c5..b4f7a52dd6e 100644--- a/plugins/chat/assets/javascripts/discourse/lib/hashtag-types/channel.js+++ b/plugins/chat/assets/javascripts/discourse/lib/hashtag-types/channel.js@@ -1,4 +1,5 @@import { service } from "@ember/service";+import replaceEmoji from "discourse/helpers/replace-emoji";import HashtagTypeBase from "discourse/lib/hashtag-types/base";import { iconHTML } from "discourse/lib/icon-library";@@ -31,9 +32,13 @@ export default class ChannelHashtagType extends HashtagTypeBase {generateIconHTML(hashtag) {hashtag.colors ? this.onLoad(hashtag) : this.load(hashtag.id);- return iconHTML(hashtag.icon, {- class: `hashtag-color--${this.type}-${hashtag.id}`,- });+ if (hashtag.emoji) {+ return String(replaceEmoji(`:${hashtag.emoji}:`));+ } else {+ return iconHTML(hashtag.icon, {+ class: `hashtag-color--${this.type}-${hashtag.id}`,+ });+ }}isLoaded(id) {diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js b/plugins/chat/assets/javascripts/discourse/models/chat-channel.jsindex e90b691ce0a..bd826cc16ce 100644--- a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js+++ b/plugins/chat/assets/javascripts/discourse/models/chat-channel.js@@ -88,6 +88,7 @@ export default class ChatChannel {this.membershipsCount = args.memberships_count;this.slug = args.slug;this.title = args.title;+ this.emoji = args.emoji;this.unicodeTitle = args.unicode_title;this.status = args.status;this.description = args.description;diff --git a/plugins/chat/assets/stylesheets/common/chat-modal-edit-channel-name.scss b/plugins/chat/assets/stylesheets/common/chat-modal-edit-channel-name.scssnew file mode 100644index 00000000000..bba05753352--- /dev/null+++ b/plugins/chat/assets/stylesheets/common/chat-modal-edit-channel-name.scss@@ -0,0 +1,5 @@+.chat-modal-edit-channel-name {+ .edit-channel-clear-emoji {+ vertical-align: top;+ }+}diff --git a/plugins/chat/assets/stylesheets/common/index.scss b/plugins/chat/assets/stylesheets/common/index.scssindex 49e7216ccf8..b5f9e714f87 100644--- a/plugins/chat/assets/stylesheets/common/index.scss+++ b/plugins/chat/assets/stylesheets/common/index.scss@@ -54,6 +54,7 @@@import "chat-user-avatar";@import "chat-modal-new-message";@import "chat-modal-archive-channel";+@import "chat-modal-edit-channel-name";@import "chat-modal-edit-channel-description";@import "chat-modal-create-channel";@import "chat-modal-channel-summary";diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.ymlindex 8d77a2f3117..22990def43b 100644--- a/plugins/chat/config/locales/client.en.yml+++ b/plugins/chat/config/locales/client.en.yml@@ -383,6 +383,8 @@ en:slug_description: A channel slug is used in the URL instead of the channel namename: Channel nameslug: Channel slug (optional)+ emoji: Channel emoji (optional)+ reset_emoji: Reset emojichannel_edit_description_modal:title: Edit description@@ -451,6 +453,9 @@ en:types:category: "Category"topic: "Topic"+ emoji:+ label: "Channel emoji (optional)"+ reset: "Reset emoji"reviewable:type: "Chat message"diff --git a/plugins/chat/db/migrate/20251125101809_add_emoji_to_chat_channels.rb b/plugins/chat/db/migrate/20251125101809_add_emoji_to_chat_channels.rbnew file mode 100644index 00000000000..ee4dd700cb7--- /dev/null+++ b/plugins/chat/db/migrate/20251125101809_add_emoji_to_chat_channels.rb@@ -0,0 +1,7 @@+# frozen_string_literal: true++class AddEmojiToChatChannels < ActiveRecord::Migration[8.0]+ def change+ add_column :chat_channels, :emoji, :string, null: true+ end+enddiff --git a/plugins/chat/lib/chat/channel_hashtag_data_source.rb b/plugins/chat/lib/chat/channel_hashtag_data_source.rbindex e6de7d9d0e4..b230f482635 100644--- a/plugins/chat/lib/chat/channel_hashtag_data_source.rb+++ b/plugins/chat/lib/chat/channel_hashtag_data_source.rb@@ -14,17 +14,14 @@ module Chat"channel"end- def self.style_type- "icon"- end-def self.channel_to_hashtag_item(guardian, channel)HashtagAutocompleteService::HashtagItem.new.tap do |item|item.text = channel.titleitem.description = channel.descriptionitem.slug = channel.slugitem.icon = icon- item.style_type = style_type+ item.emoji = channel.emoji+ item.style_type = channel.emoji.present? ? "emoji" : "icon"item.colors = [channel.category.color] if channel.category_channel?item.relative_url = channel.relative_urlitem.type = "channel"diff --git a/plugins/chat/spec/services/chat/create_category_channel_spec.rb b/plugins/chat/spec/services/chat/create_category_channel_spec.rbindex d86b20834d1..24a732b08ff 100644--- a/plugins/chat/spec/services/chat/create_category_channel_spec.rb+++ b/plugins/chat/spec/services/chat/create_category_channel_spec.rb@@ -121,6 +121,22 @@ RSpec.describe Chat::CreateCategoryChannel doendendend++ describe "emoji" do+ context "when selected" do+ it "sets emoji" do+ params[:emoji] = ":smile:"+ expect(result.channel.emoji).to eq(":smile:")+ end+ end++ context "when blank" do+ it "sets emoji to nil" do+ params[:emoji] = nil+ expect(result.channel.emoji).to eq(nil)+ end+ end+ endendendenddiff --git a/plugins/chat/spec/system/channel_settings_page_spec.rb b/plugins/chat/spec/system/channel_settings_page_spec.rbindex 09e935238f0..79f58eeb594 100644--- a/plugins/chat/spec/system/channel_settings_page_spec.rb+++ b/plugins/chat/spec/system/channel_settings_page_spec.rb@@ -248,6 +248,31 @@ RSpec.describe "Channel - Info - Settings page", type: :system doexpect(page).to have_current_path("/chat/c/test-channel/#{channel_1.id}")end+ it "can edit emoji" do+ chat_page.visit_channel_settings(channel_1)++ edit_modal = channel_settings_page.open_edit_modal++ edit_modal.select_and_save_emoji("wink")++ channel_emoji = page.find(".chat-channel-title .emoji")["title"]++ expect(channel_emoji).to eq("wink")+ end++ it "can clear the emoji to restore the default chat icon" do+ channel_1.update!(emoji: "smile")+ chat_page.visit_channel_settings(channel_1)++ expect(page.find(".chat-channel-title .emoji")["title"]).to eq("smile")++ edit_modal = channel_settings_page.open_edit_modal+ edit_modal.reset_emoji++ expect(page).to have_no_selector(".chat-channel-title .emoji")+ expect(page).to have_selector(".chat-channel-title .d-icon-d-chat")+ end+it "shows settings page" dochat_page.visit_channel_settings(channel_1)diff --git a/plugins/chat/spec/system/page_objects/modals/chat_edit_modal.rb b/plugins/chat/spec/system/page_objects/modals/chat_edit_modal.rbindex 0930ccb0970..ce75ab77288 100644--- a/plugins/chat/spec/system/page_objects/modals/chat_edit_modal.rb+++ b/plugins/chat/spec/system/page_objects/modals/chat_edit_modal.rb@@ -6,8 +6,11 @@ module PageObjectsinclude SystemHelpersEDIT_MODAL_SELECTOR = PageObjects::Pages::ChatChannelSettings::EDIT_MODAL_SELECTOR+ EMOJI_PICKER = PageObjects::Components::EmojiPicker.newSLUG_INPUT_SELECTOR = ".chat-channel-edit-name-slug-modal__slug-input"NAME_INPUT_SELECTOR = ".chat-channel-edit-name-slug-modal__name-input"+ EMOJI_INPUT_SELECTOR = ".edit-channel-control .btn-emoji"+ CLEAR_EMOJI_BTN = ".edit-channel-clear-emoji"def fill_in_slug(slug)within(EDIT_MODAL_SELECTOR) { find(SLUG_INPUT_SELECTOR).fill_in(with: slug) }@@ -46,6 +49,23 @@ module PageObjectsselfend+ def select_emoji(value)+ within(EDIT_MODAL_SELECTOR) { find(EMOJI_INPUT_SELECTOR).click }+ EMOJI_PICKER.select_emoji(":#{value}:")+ end++ def select_and_save_emoji(value)+ select_emoji(value)+ save_changes+ self+ end++ def reset_emoji+ within(EDIT_MODAL_SELECTOR) { find(CLEAR_EMOJI_BTN).click }+ save_changes+ self+ end+def has_slug_input?(value)within(EDIT_MODAL_SELECTOR) { find(SLUG_INPUT_SELECTOR).value == value }end