From 2c5041f182f259523d27cb4b1acd0554d49dc7c6 Mon Sep 17 00:00:00 2001 From: Aung Kyaw Phyo Date: Thu, 31 Jul 2025 14:12:39 +0700 Subject: [PATCH 01/10] Output logs to debug --- app/controllers/api/v1/joined_communities_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/api/v1/joined_communities_controller.rb b/app/controllers/api/v1/joined_communities_controller.rb index b08b097a..7f82a0bd 100644 --- a/app/controllers/api/v1/joined_communities_controller.rb +++ b/app/controllers/api/v1/joined_communities_controller.rb @@ -100,19 +100,26 @@ def find_patchwork_community(slug) end def load_joined_channels + Rails.logger.info "Loading joined communities for account: #{@account.id} #{@account.user.email} with platform type: #{params[:platform_type]}" channel_type = is_newsmast? ? Community.channel_types[:newsmast] : Community.channel_types[:channel] + Rails.logger.info "Channel type: #{channel_type}" @joined_communities = @account&.communities.where(deleted_at: nil).where( channel_type: channel_type ) + Rails.logger.info "Joined communities loaded: #{@joined_communities.size}" @community = Community.find_by(slug: params[:id]) + Rails.logger.info "Community found: #{@community&.name} with ID: #{@community&.id}" if @community end def sort_by_primary! + Rails.logger.info "Sorting joined communities by primary status for account: #{@account.id}" @joined_communities = @joined_communities&.to_a || [] + Rails.logger.info "Joined communities before sorting: #{@joined_communities.size}" @joined_communities.sort_by! do |community| joined = community.joined_communities.find_by(account_id: @account.id) joined&.is_primary ? 0 : 1 end + Rails.logger.info "Joined communities after sorting: #{@joined_communities.size}" end def is_newsmast? From cdb2763984c2065e9f0ff6de91cafc4208fd5416 Mon Sep 17 00:00:00 2001 From: Aung Kyaw Phyo Date: Thu, 31 Jul 2025 14:23:04 +0700 Subject: [PATCH 02/10] Fix bug --- app/controllers/api/v1/joined_communities_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/joined_communities_controller.rb b/app/controllers/api/v1/joined_communities_controller.rb index 7f82a0bd..ba747742 100644 --- a/app/controllers/api/v1/joined_communities_controller.rb +++ b/app/controllers/api/v1/joined_communities_controller.rb @@ -100,7 +100,7 @@ def find_patchwork_community(slug) end def load_joined_channels - Rails.logger.info "Loading joined communities for account: #{@account.id} #{@account.user.email} with platform type: #{params[:platform_type]}" + Rails.logger.info "Loading joined communities for account: #{@account.id} #{@account.display_name} with platform type: #{params[:platform_type]}" channel_type = is_newsmast? ? Community.channel_types[:newsmast] : Community.channel_types[:channel] Rails.logger.info "Channel type: #{channel_type}" @joined_communities = @account&.communities.where(deleted_at: nil).where( From aca9d54420107cf0ccd23ca41e35c273eb39b71d Mon Sep 17 00:00:00 2001 From: Aung Kyaw Phyo Date: Thu, 31 Jul 2025 14:46:37 +0700 Subject: [PATCH 03/10] Output more logs to debug --- app/controllers/api/v1/channels_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/v1/channels_controller.rb b/app/controllers/api/v1/channels_controller.rb index 01513553..ab731cec 100644 --- a/app/controllers/api/v1/channels_controller.rb +++ b/app/controllers/api/v1/channels_controller.rb @@ -68,7 +68,9 @@ def channel_feeds end def newsmast_channels + Rails.logger.info "Fetching newsmast channels for instance domain: #{params[:instance_domain]} for current_remote_account: #{current_remote_account&.id} and current_account: #{current_account&.id}" newsmast_channels = Community.filter_newsmast_channels.exclude_incomplete_channels.exclude_deleted_channels.exclude_not_recommended.with_all_includes + Rails.logger.info "Newsmast channels fetched: #{newsmast_channels.size}" if newsmast_channels.present? render json: Api::V1::ChannelSerializer.new(newsmast_channels , { params: { current_account: current_remote_account } }).serializable_hash.to_json else From 490258dba512824de71ff39cfd9c57c1ff3d5e0d Mon Sep 17 00:00:00 2001 From: Aung Kyaw Phyo Date: Thu, 31 Jul 2025 15:37:11 +0700 Subject: [PATCH 04/10] Output more logs to debug --- app/controllers/api_controller.rb | 4 ++++ app/services/remote_account_verify_service.rb | 3 +++ 2 files changed, 7 insertions(+) diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index dbdb7f3b..3b403569 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -62,13 +62,17 @@ def authenticate_user_from_header end def validate_mastodon_account + Rails.logger.info "Validating Mastodon account for instance domain: #{params[:instance_domain]}" token = bearer_token + Rails.logger.info "Bearer token: #{token}" return render json: { error: 'Authentication required!' }, status: :unauthorized unless token && !instance_domain.nil? acc_id = RemoteAccountVerifyService.new(token, instance_domain).call.fetch_remote_account_id + Rails.logger.info "Remote account ID: #{acc_id}" if acc_id @current_remote_account = Account.find_by(id: acc_id) + Rails.logger.info "Current remote account: #{@current_remote_account&.id} - #{@current_remote_account&.username}" else render json: { error: 'Account not found' }, status: :unauthorized end diff --git a/app/services/remote_account_verify_service.rb b/app/services/remote_account_verify_service.rb index b8dd1753..ee431310 100644 --- a/app/services/remote_account_verify_service.rb +++ b/app/services/remote_account_verify_service.rb @@ -25,9 +25,12 @@ def verify_account_credentials def fetch_remote_account_id # Find account in local server + Rails.logger.info "Fetching remote account ID for username: #{@remote_account['username']} on domain: #{@domain}" account_id = if acc = Account.find_by(username: @remote_account["username"], domain: @domain) + Rails.logger.info "Found local account with ID: #{acc.id}" acc.id else + Rails.logger.info "Account not found locally, searching in remote instance" account_handler = "@#{@remote_account["username"]}@#{@domain}" search_target_account_id(account_handler) end From 234f2bb7edc26002ecd12856fe347140531efad1 Mon Sep 17 00:00:00 2001 From: Aung Kyaw Phyo Date: Thu, 31 Jul 2025 16:08:41 +0700 Subject: [PATCH 05/10] Patch domain issue --- app/services/remote_account_verify_service.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/services/remote_account_verify_service.rb b/app/services/remote_account_verify_service.rb index ee431310..2b7cc17f 100644 --- a/app/services/remote_account_verify_service.rb +++ b/app/services/remote_account_verify_service.rb @@ -26,12 +26,16 @@ def verify_account_credentials def fetch_remote_account_id # Find account in local server Rails.logger.info "Fetching remote account ID for username: #{@remote_account['username']} on domain: #{@domain}" - account_id = if acc = Account.find_by(username: @remote_account["username"], domain: @domain) + domain = @domain + if @domain == 'backend.newsmast.org' + domain = 'newsmast.social' + end + account_id = if acc = Account.find_by(username: @remote_account["username"], domain: domain) Rails.logger.info "Found local account with ID: #{acc.id}" acc.id else Rails.logger.info "Account not found locally, searching in remote instance" - account_handler = "@#{@remote_account["username"]}@#{@domain}" + account_handler = "@#{@remote_account["username"]}@#{domain}" search_target_account_id(account_handler) end account_id From 5897171ad9db94c8d44fbd8f3e336390c208963a Mon Sep 17 00:00:00 2001 From: Aung Kyaw Phyo Date: Thu, 31 Jul 2025 16:37:15 +0700 Subject: [PATCH 06/10] Remove logs --- app/controllers/api/v1/channels_controller.rb | 2 -- app/controllers/api/v1/joined_communities_controller.rb | 7 ------- app/controllers/api_controller.rb | 4 ---- app/services/remote_account_verify_service.rb | 3 --- 4 files changed, 16 deletions(-) diff --git a/app/controllers/api/v1/channels_controller.rb b/app/controllers/api/v1/channels_controller.rb index ab731cec..01513553 100644 --- a/app/controllers/api/v1/channels_controller.rb +++ b/app/controllers/api/v1/channels_controller.rb @@ -68,9 +68,7 @@ def channel_feeds end def newsmast_channels - Rails.logger.info "Fetching newsmast channels for instance domain: #{params[:instance_domain]} for current_remote_account: #{current_remote_account&.id} and current_account: #{current_account&.id}" newsmast_channels = Community.filter_newsmast_channels.exclude_incomplete_channels.exclude_deleted_channels.exclude_not_recommended.with_all_includes - Rails.logger.info "Newsmast channels fetched: #{newsmast_channels.size}" if newsmast_channels.present? render json: Api::V1::ChannelSerializer.new(newsmast_channels , { params: { current_account: current_remote_account } }).serializable_hash.to_json else diff --git a/app/controllers/api/v1/joined_communities_controller.rb b/app/controllers/api/v1/joined_communities_controller.rb index ba747742..b08b097a 100644 --- a/app/controllers/api/v1/joined_communities_controller.rb +++ b/app/controllers/api/v1/joined_communities_controller.rb @@ -100,26 +100,19 @@ def find_patchwork_community(slug) end def load_joined_channels - Rails.logger.info "Loading joined communities for account: #{@account.id} #{@account.display_name} with platform type: #{params[:platform_type]}" channel_type = is_newsmast? ? Community.channel_types[:newsmast] : Community.channel_types[:channel] - Rails.logger.info "Channel type: #{channel_type}" @joined_communities = @account&.communities.where(deleted_at: nil).where( channel_type: channel_type ) - Rails.logger.info "Joined communities loaded: #{@joined_communities.size}" @community = Community.find_by(slug: params[:id]) - Rails.logger.info "Community found: #{@community&.name} with ID: #{@community&.id}" if @community end def sort_by_primary! - Rails.logger.info "Sorting joined communities by primary status for account: #{@account.id}" @joined_communities = @joined_communities&.to_a || [] - Rails.logger.info "Joined communities before sorting: #{@joined_communities.size}" @joined_communities.sort_by! do |community| joined = community.joined_communities.find_by(account_id: @account.id) joined&.is_primary ? 0 : 1 end - Rails.logger.info "Joined communities after sorting: #{@joined_communities.size}" end def is_newsmast? diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 3b403569..dbdb7f3b 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -62,17 +62,13 @@ def authenticate_user_from_header end def validate_mastodon_account - Rails.logger.info "Validating Mastodon account for instance domain: #{params[:instance_domain]}" token = bearer_token - Rails.logger.info "Bearer token: #{token}" return render json: { error: 'Authentication required!' }, status: :unauthorized unless token && !instance_domain.nil? acc_id = RemoteAccountVerifyService.new(token, instance_domain).call.fetch_remote_account_id - Rails.logger.info "Remote account ID: #{acc_id}" if acc_id @current_remote_account = Account.find_by(id: acc_id) - Rails.logger.info "Current remote account: #{@current_remote_account&.id} - #{@current_remote_account&.username}" else render json: { error: 'Account not found' }, status: :unauthorized end diff --git a/app/services/remote_account_verify_service.rb b/app/services/remote_account_verify_service.rb index 2b7cc17f..c2b4134a 100644 --- a/app/services/remote_account_verify_service.rb +++ b/app/services/remote_account_verify_service.rb @@ -25,16 +25,13 @@ def verify_account_credentials def fetch_remote_account_id # Find account in local server - Rails.logger.info "Fetching remote account ID for username: #{@remote_account['username']} on domain: #{@domain}" domain = @domain if @domain == 'backend.newsmast.org' domain = 'newsmast.social' end account_id = if acc = Account.find_by(username: @remote_account["username"], domain: domain) - Rails.logger.info "Found local account with ID: #{acc.id}" acc.id else - Rails.logger.info "Account not found locally, searching in remote instance" account_handler = "@#{@remote_account["username"]}@#{domain}" search_target_account_id(account_handler) end From 5dfe9cc0324be2a7cc922488ecdf6704308f3ae6 Mon Sep 17 00:00:00 2001 From: NangKhatMang Date: Fri, 1 Aug 2025 11:50:19 +0630 Subject: [PATCH 07/10] UI fix --- app/services/contributor_search_service.rb | 2 +- app/views/collections/_form.html.haml | 6 ++++-- app/views/communities/_form_step1.html.haml | 12 ++++++++---- app/views/communities/_form_step3.html.haml | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/services/contributor_search_service.rb b/app/services/contributor_search_service.rb index 50383602..28595265 100644 --- a/app/services/contributor_search_service.rb +++ b/app/services/contributor_search_service.rb @@ -41,7 +41,7 @@ def find_saved_accounts_with_retry(accounts) { 'id' => account.id.to_s, 'username' => account.username, - 'display_name' => account.display_name, + 'display_name' => account.display_name.gsub(/:[^:\s]+:/, '').strip, 'domain' => account.domain, 'note' => account.note, 'avatar_url' => account.avatar_url, diff --git a/app/views/collections/_form.html.haml b/app/views/collections/_form.html.haml index 2b502a16..d230273f 100644 --- a/app/views/collections/_form.html.haml +++ b/app/views/collections/_form.html.haml @@ -26,9 +26,11 @@ .avatar-upload-container .rounded-circle.border.d-inline-flex.align-items-center.justify-content-center{ style: "width: 90px; height: 90px; border: dotted; overflow: hidden;" } - avatar_image_url = @collection.avatar_image.present? && @collection.avatar_image.respond_to?(:url) ? @collection.avatar_image.url : '' + - margin_left = avatar_image_url.present? ? '0' : '16px' - %img{ id: "currentAvatar", src: avatar_image_url, style: "display: #{avatar_image_url.present? ? 'block' : 'none'}; width: 100%; height: 100%; object-fit: cover; margin-left: 16px;" } - %i.fa-solid.fa-image + %img{ id: "currentAvatar", src: avatar_image_url, style: "display: #{avatar_image_url.present? ? 'block' : 'none'}; width: 100%; height: 100%; object-fit: cover; margin-left: #{margin_left};" } + - if avatar_image_url.blank? + %i.fa-solid.fa-image = f.input :avatar_image, as: :file, label: false, input_html: { id: "customFileAvatar", class: "form-control-file upload-input", style: "display: none;", accept: "image/*", 'data-preview-id': "currentAvatar", 'data-aspect-ratio': "1" } .avatar-image-upload diff --git a/app/views/communities/_form_step1.html.haml b/app/views/communities/_form_step1.html.haml index 364490eb..a5381642 100644 --- a/app/views/communities/_form_step1.html.haml +++ b/app/views/communities/_form_step1.html.haml @@ -155,8 +155,10 @@ .logo-upload-container .rounded.border.d-inline-flex.align-items-center.justify-content-center{ style: "width: 300px; height: 150px; border: dotted; overflow: hidden;" } - logo_image_url = @community_form.logo_image.present? && @community_form.logo_image.respond_to?(:url) ? @community_form.logo_image.url : '' - %img{ id: "currentlogo", src: logo_image_url, alt: "Logo Preview", style: "display: #{logo_image_url.present? ? 'block' : 'none'}; width: 100%; height: 100%; object-fit: cover; margin-left: 16px;" } - %i.fa-solid.fa-image + - margin_left = logo_image_url.present? ? '0' : '16px' + %img{ id: "currentlogo", src: logo_image_url, alt: "Logo Preview", style: "display: #{logo_image_url.present? ? 'block' : 'none'}; width: 100%; height: 100%; object-fit: cover; margin-left: #{margin_left};" } + - if logo_image_url.blank? + %i.fa-solid.fa-image = f.input :logo_image, as: :file, label: false, input_html: { id: "customFilelogo", class: "form-control-file upload-input", style: "display: none;", accept: "image/*", 'data-preview-id': "currentlogo", 'data-aspect-ratio': "2.1" } .logo-image-upload %button.btn.btn-primary.mt-2{ onclick: "event.preventDefault(); document.getElementById('customFilelogo').click();" } Upload image @@ -169,8 +171,10 @@ .avatar-upload-container .rounded-circle.border.d-inline-flex.align-items-center.justify-content-center{ style: "width: 90px; height: 90px; border: dotted; overflow: hidden;" } - avatar_image_url = @community_form.avatar_image.present? && @community_form.avatar_image.respond_to?(:url) ? @community_form.avatar_image.url : '' - %img{ id: "currentAvatar", src: avatar_image_url, alt: "Avatar Preview", style: "display: #{avatar_image_url.present? ? 'block' : 'none'}; width: 100%; height: 100%; object-fit: cover; margin-left: 16px;" } - %i.fa-solid.fa-image + - margin_left = avatar_image_url.present? ? '0' : '16px' + %img{ id: "currentAvatar", src: avatar_image_url, alt: "Avatar Preview", style: "display: #{avatar_image_url.present? ? 'block' : 'none'}; width: 100%; height: 100%; object-fit: cover; margin-left: #{margin_left};" } + - if avatar_image_url.blank? + %i.fa-solid.fa-image = f.input :avatar_image, as: :file, label: false, input_html: { id: "customFileAvatar", class: "form-control-file upload-input", style: "display: none;", accept: "image/*", 'data-preview-id': "currentAvatar", 'data-aspect-ratio': "1" } .avatar-image-upload %button.btn.btn-primary.mt-2{ onclick: "event.preventDefault(); document.getElementById('customFileAvatar').click();" } Upload image diff --git a/app/views/communities/_form_step3.html.haml b/app/views/communities/_form_step3.html.haml index eb0eaa03..22456365 100644 --- a/app/views/communities/_form_step3.html.haml +++ b/app/views/communities/_form_step3.html.haml @@ -122,7 +122,7 @@ %td{ style: 'width: 10%;' } %img{ alt: "", src: record.avatar_url, class: "rounded-circle mr-2", style: "width: 70px; height: 70px; border: 2px solid white;" } %td{ style: 'width: 80%;' } - = record.display_name + = record.display_name.gsub(/:[^:\s]+:/, '').strip - domain = record&.domain.present? ? "https://#{record.domain}" : ENV.fetch('MASTODON_INSTANCE_URL', nil) %br %a{ href: "#{record.url}", target: "_blank" }= "@#{record.username}@#{record.domain || 'channel.org'}" From 447fc4301f475da5c1fc204dc289a035e8c15701 Mon Sep 17 00:00:00 2001 From: Min Khant Kyaw Date: Mon, 4 Aug 2025 17:27:49 +0630 Subject: [PATCH 08/10] modify:mo-me menu --- config/routes/api_v1.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes/api_v1.rb b/config/routes/api_v1.rb index cea4aa9b..1cda608d 100644 --- a/config/routes/api_v1.rb +++ b/config/routes/api_v1.rb @@ -15,7 +15,7 @@ when 'newsmast' { display: true, app_name: 'newsmast' } when 'mo-me' - { display: true, app_name: 'mo-me' } + { display: false, app_name: 'mo-me' } else { display: true, app_name: app_name } end From 134bb01a523c04f4b203b2929aa59b1c0bce74ff Mon Sep 17 00:00:00 2001 From: Min Khant Kyaw Date: Tue, 5 Aug 2025 09:35:22 +0630 Subject: [PATCH 09/10] update mo-me menu display --- config/routes/api_v1.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes/api_v1.rb b/config/routes/api_v1.rb index 1cda608d..cea4aa9b 100644 --- a/config/routes/api_v1.rb +++ b/config/routes/api_v1.rb @@ -15,7 +15,7 @@ when 'newsmast' { display: true, app_name: 'newsmast' } when 'mo-me' - { display: false, app_name: 'mo-me' } + { display: true, app_name: 'mo-me' } else { display: true, app_name: app_name } end From 94614dd80084dfbf359566b1ee430ca11c66753f Mon Sep 17 00:00:00 2001 From: Aung Kyaw Phyo Date: Tue, 5 Aug 2025 15:16:59 +0700 Subject: [PATCH 10/10] Render custom emojis --- app/assets/stylesheets/application.scss | 5 ++++ app/helpers/application_helper.rb | 13 ++++++++++ app/views/accounts/index.html.haml | 2 +- app/views/accounts/show.html.haml | 2 +- app/views/communities/_form_step3.html.haml | 2 +- app/views/communities/follower_list.html.haml | 2 +- config/initializers/mastodon_emojis.rb | 24 +++++++++++++++++++ 7 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 config/initializers/mastodon_emojis.rb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 6092a416..cf30c640 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -793,3 +793,8 @@ ul.pagination { display: inline; line-height: 1; } + +.custom-emoji { + height: 1.25em; + vertical-align: middle; +} \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 428100fd..d41e672d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -92,4 +92,17 @@ def hub_admin? def newsmast_admin? current_user && policy(current_user).newsmast_admin? end + + def render_custom_emojis(text) + emoji_map = MastodonEmoji.fetch_and_cache_emojis + + pattern = /:([a-zA-Z0-9_+-]+):/ + text.gsub(pattern) do |match| + if emoji_map[match] + image_tag emoji_map[match], alt: match, class: "custom-emoji" + else + match + end + end.html_safe + end end diff --git a/app/views/accounts/index.html.haml b/app/views/accounts/index.html.haml index 249c5682..c18ff795 100644 --- a/app/views/accounts/index.html.haml +++ b/app/views/accounts/index.html.haml @@ -29,7 +29,7 @@ %td = check_box_tag "selected_accounts[]", account.id, false, class: 'select_account' %td= account.username - %td= account.display_name + %td= render_custom_emojis(account.display_name) %td= account.user ? account.user.email : "-" %td= account.created_at.strftime('%Y-%m-%d %H:%M:%S') %td= account.domain ? account.domain : ENV['MASTODON_INSTANCE_URL'] diff --git a/app/views/accounts/show.html.haml b/app/views/accounts/show.html.haml index 66ad2306..3276a64d 100644 --- a/app/views/accounts/show.html.haml +++ b/app/views/accounts/show.html.haml @@ -18,7 +18,7 @@ .col-sm-3.text-secondary.text-right Display name: .col-sm-9.text-left - = @account.display_name.presence || '-' + = @account.display_name.presence ? render_custom_emojis(@account.display_name) : '-' .row.border-bottom.mb-4 .col-sm-3.text-secondary.text-right Username: diff --git a/app/views/communities/_form_step3.html.haml b/app/views/communities/_form_step3.html.haml index 22456365..ba566e2d 100644 --- a/app/views/communities/_form_step3.html.haml +++ b/app/views/communities/_form_step3.html.haml @@ -122,7 +122,7 @@ %td{ style: 'width: 10%;' } %img{ alt: "", src: record.avatar_url, class: "rounded-circle mr-2", style: "width: 70px; height: 70px; border: 2px solid white;" } %td{ style: 'width: 80%;' } - = record.display_name.gsub(/:[^:\s]+:/, '').strip + = render_custom_emojis(record.display_name) - domain = record&.domain.present? ? "https://#{record.domain}" : ENV.fetch('MASTODON_INSTANCE_URL', nil) %br %a{ href: "#{record.url}", target: "_blank" }= "@#{record.username}@#{record.domain || 'channel.org'}" diff --git a/app/views/communities/follower_list.html.haml b/app/views/communities/follower_list.html.haml index c64a3808..36677f4e 100644 --- a/app/views/communities/follower_list.html.haml +++ b/app/views/communities/follower_list.html.haml @@ -29,7 +29,7 @@ %p.text-muted.small There's no follower. - @records.each do |account| %tr - %td= account&.display_name.present? ? account&.display_name : " - " + %td= account&.display_name.present? ? render_custom_emojis(account.display_name) : " - " %td - if account.present? %span.copyable-text{title: "Click to copy", style: "cursor: pointer;", onclick: "copyToClipboard('#{account_url(account)}')"}= "@#{username(account)}@#{domain(account)}" diff --git a/config/initializers/mastodon_emojis.rb b/config/initializers/mastodon_emojis.rb new file mode 100644 index 00000000..816da3f5 --- /dev/null +++ b/config/initializers/mastodon_emojis.rb @@ -0,0 +1,24 @@ +# config/initializers/mastodon_emojis.rb + +require 'net/http' +require 'json' + +module MastodonEmoji + INSTANCE_URL = ENV.fetch("MASTODON_INSTANCE_URL", "https://channel.org") + CACHE_KEY = "mastodon_custom_emojis" + CACHE_EXPIRY = 24.hours + + def self.fetch_and_cache_emojis + Rails.cache.fetch(CACHE_KEY, expires_in: CACHE_EXPIRY) do + url = URI("#{INSTANCE_URL}/api/v1/custom_emojis") + response = Net::HTTP.get(url) + JSON.parse(response).each_with_object({}) do |emoji, hash| + shortcode = ":#{emoji['shortcode']}:" + hash[shortcode] = emoji['url'] + end + rescue => e + Rails.logger.error("Failed to fetch Mastodon emojis: #{e.message}") + {} + end + end +end