Compare commits
1 commit
kb_develop
...
kbtopic-84
Author | SHA1 | Date | |
---|---|---|---|
|
fe0a995867 |
5 changed files with 92 additions and 19 deletions
|
@ -77,6 +77,8 @@ class ActivityPub::Activity::Like < ActivityPub::Activity
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_emoji(tag)
|
def process_emoji(tag)
|
||||||
|
return process_emoji_by_uri(as_array(tag)[0]) if tag.is_a?(String) || tag.is_a?(Array)
|
||||||
|
|
||||||
custom_emoji_parser = ActivityPub::Parser::CustomEmojiParser.new(tag)
|
custom_emoji_parser = ActivityPub::Parser::CustomEmojiParser.new(tag)
|
||||||
|
|
||||||
return if custom_emoji_parser.shortcode.blank? || custom_emoji_parser.image_remote_url.blank?
|
return if custom_emoji_parser.shortcode.blank? || custom_emoji_parser.image_remote_url.blank?
|
||||||
|
@ -100,35 +102,62 @@ class ActivityPub::Activity::Like < ActivityPub::Activity
|
||||||
custom_emoji_parser = original_emoji_parser(custom_emoji_parser) if @account.domain != domain
|
custom_emoji_parser = original_emoji_parser(custom_emoji_parser) if @account.domain != domain
|
||||||
return if custom_emoji_parser.nil?
|
return if custom_emoji_parser.nil?
|
||||||
|
|
||||||
begin
|
update_custom_emoji!(emoji, custom_emoji_parser, domain)
|
||||||
emoji ||= CustomEmoji.new(
|
|
||||||
domain: domain,
|
|
||||||
shortcode: custom_emoji_parser.shortcode,
|
|
||||||
uri: custom_emoji_parser.uri
|
|
||||||
)
|
|
||||||
emoji.image_remote_url = custom_emoji_parser.image_remote_url
|
|
||||||
emoji.license = custom_emoji_parser.license
|
|
||||||
emoji.is_sensitive = custom_emoji_parser.is_sensitive
|
|
||||||
emoji.aliases = custom_emoji_parser.aliases
|
|
||||||
emoji.save
|
|
||||||
rescue Seahorse::Client::NetworkingError => e
|
|
||||||
Rails.logger.warn "Error storing emoji: #{e}"
|
|
||||||
end
|
|
||||||
|
|
||||||
emoji
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def original_emoji_parser(custom_emoji_parser)
|
def original_emoji_parser(custom_emoji_parser)
|
||||||
uri = custom_emoji_parser.uri
|
fetch_original_emoji_parser(custom_emoji_parser.uri, custom_emoji_parser.shortcode || '')
|
||||||
|
end
|
||||||
|
|
||||||
|
def fetch_original_emoji_parser(uri, shortcode = nil)
|
||||||
emoji = fetch_resource_without_id_validation(uri)
|
emoji = fetch_resource_without_id_validation(uri)
|
||||||
return nil unless emoji
|
return nil unless emoji
|
||||||
|
|
||||||
parser = ActivityPub::Parser::CustomEmojiParser.new(emoji)
|
parser = ActivityPub::Parser::CustomEmojiParser.new(emoji)
|
||||||
return nil unless parser.uri == uri && custom_emoji_parser.shortcode == parser.shortcode
|
return nil unless parser.uri == uri
|
||||||
|
return nil if shortcode.present? && shortcode != parser.shortcode
|
||||||
|
|
||||||
parser
|
parser
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def process_emoji_by_uri(uri)
|
||||||
|
return if uri.blank?
|
||||||
|
|
||||||
|
domain = URI.split(uri)[2] || @account.domain
|
||||||
|
|
||||||
|
if domain == Rails.configuration.x.local_domain || domain == Rails.configuration.x.web_domain
|
||||||
|
# Block overwriting remote-but-local data
|
||||||
|
return CustomEmoji.find_by(id: ActivityPub::TagManager.instance.uri_to_local_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
return if domain.present? && skip_download?(domain)
|
||||||
|
|
||||||
|
custom_emoji_parser = nil
|
||||||
|
custom_emoji_parser = fetch_original_emoji_parser(uri) if @account.domain != domain
|
||||||
|
custom_emoji_parser ||= CustomEmoji.find_by(uri: uri)
|
||||||
|
return if custom_emoji_parser.nil?
|
||||||
|
|
||||||
|
update_custom_emoji!(CustomEmoji.find_by(uri: uri), custom_emoji_parser, domain)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_custom_emoji!(emoji, custom_emoji_parser, domain)
|
||||||
|
emoji ||= CustomEmoji.new(
|
||||||
|
domain: domain,
|
||||||
|
shortcode: custom_emoji_parser.shortcode,
|
||||||
|
uri: custom_emoji_parser.uri
|
||||||
|
)
|
||||||
|
emoji.image_remote_url = custom_emoji_parser.image_remote_url
|
||||||
|
emoji.license = custom_emoji_parser.license
|
||||||
|
emoji.is_sensitive = custom_emoji_parser.is_sensitive
|
||||||
|
emoji.aliases = custom_emoji_parser.aliases
|
||||||
|
emoji.save
|
||||||
|
|
||||||
|
emoji
|
||||||
|
rescue Seahorse::Client::NetworkingError => e
|
||||||
|
Rails.logger.warn "Error storing emoji: #{e}"
|
||||||
|
emoji
|
||||||
|
end
|
||||||
|
|
||||||
def skip_download?(domain)
|
def skip_download?(domain)
|
||||||
return true if DomainBlock.reject_media?(domain)
|
return true if DomainBlock.reject_media?(domain)
|
||||||
return false if @account.domain == domain
|
return false if @account.domain == domain
|
||||||
|
|
27
db/migrate/20240912234211_add_custom_emoji_index.rb
Normal file
27
db/migrate/20240912234211_add_custom_emoji_index.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddCustomEmojiIndex < ActiveRecord::Migration[7.1]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
class CustomEmoji < ApplicationRecord
|
||||||
|
end
|
||||||
|
|
||||||
|
def up
|
||||||
|
duplications = CustomEmoji.where('uri IN (SELECT uri FROM custom_emojis GROUP BY uri HAVING COUNT(*) > 1)')
|
||||||
|
.to_a.group_by(&:uri).to_h
|
||||||
|
|
||||||
|
if duplications.any?
|
||||||
|
CustomEmoji.transaction do
|
||||||
|
duplications.each do |h|
|
||||||
|
h[1].drop(1).each(&:destroy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :custom_emojis, :uri, unique: true, algorithm: :concurrently
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_index :custom_emojis, :uri
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2024_08_28_123604) do
|
ActiveRecord::Schema[7.1].define(version: 2024_09_12_234211) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
@ -515,6 +515,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_08_28_123604) do
|
||||||
t.string "license"
|
t.string "license"
|
||||||
t.integer "image_file_size"
|
t.integer "image_file_size"
|
||||||
t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true
|
t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true
|
||||||
|
t.index ["uri"], name: "index_custom_emojis_on_uri", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "custom_filter_keywords", force: :cascade do |t|
|
create_table "custom_filter_keywords", force: :cascade do |t|
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace :dangerous do
|
||||||
end
|
end
|
||||||
|
|
||||||
target_migrations = %w(
|
target_migrations = %w(
|
||||||
|
20240912234211
|
||||||
20240828123604
|
20240828123604
|
||||||
20240709063700
|
20240709063700
|
||||||
20240426233435
|
20240426233435
|
||||||
|
@ -189,6 +190,7 @@ namespace :dangerous do
|
||||||
index_statuses_on_conversation_id
|
index_statuses_on_conversation_id
|
||||||
index_preview_cards_vacuum
|
index_preview_cards_vacuum
|
||||||
index_media_attachments_vacuum
|
index_media_attachments_vacuum
|
||||||
|
index_custom_emojis_on_uri
|
||||||
)
|
)
|
||||||
|
|
||||||
prompt.say 'Processing...'
|
prompt.say 'Processing...'
|
||||||
|
|
|
@ -204,6 +204,20 @@ RSpec.describe ActivityPub::Activity::Like do
|
||||||
expect(subject.first.custom_emoji.domain).to eq 'example.com'
|
expect(subject.first.custom_emoji.domain).to eq 'example.com'
|
||||||
expect(sender.favourited?(status)).to be false
|
expect(sender.favourited?(status)).to be false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'without tag info' do
|
||||||
|
let(:tag) { 'https://example.com/aaa' }
|
||||||
|
|
||||||
|
it 'create emoji reaction' do
|
||||||
|
expect(subject.count).to eq 1
|
||||||
|
expect(subject.first.name).to eq 'tinking'
|
||||||
|
expect(subject.first.account).to eq sender
|
||||||
|
expect(subject.first.custom_emoji).to_not be_nil
|
||||||
|
expect(subject.first.custom_emoji.shortcode).to eq 'tinking'
|
||||||
|
expect(subject.first.custom_emoji.domain).to eq 'example.com'
|
||||||
|
expect(sender.favourited?(status)).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with custom emoji and update license from non-original server account' do
|
context 'with custom emoji and update license from non-original server account' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue