Encode custom emojis as resolveable objects in ActivityPub (#5243)
* Encode custom emojis as resolveable objects in ActivityPub * Improve code styleth-downstream
parent
14db4829dc
commit
60925ce0ae
@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class EmojisController < ApplicationController
|
||||
before_action :set_emoji
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: @emoji,
|
||||
serializer: ActivityPub::EmojiSerializer,
|
||||
adapter: ActivityPub::Adapter,
|
||||
content_type: 'application/activity+json'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_emoji
|
||||
@emoji = CustomEmoji.local.find(params[:id])
|
||||
end
|
||||
end
|
@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::EmojiSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :id, :type, :name, :updated
|
||||
|
||||
has_one :icon, serializer: ActivityPub::ImageSerializer
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def type
|
||||
'Emoji'
|
||||
end
|
||||
|
||||
def icon
|
||||
object.image
|
||||
end
|
||||
|
||||
def updated
|
||||
object.updated_at.iso8601
|
||||
end
|
||||
|
||||
def name
|
||||
":#{object.shortcode}:"
|
||||
end
|
||||
end
|
@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::ImageSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :type, :media_type, :url
|
||||
|
||||
def type
|
||||
'Image'
|
||||
end
|
||||
|
||||
def url
|
||||
full_asset_url(object.url(:original))
|
||||
end
|
||||
|
||||
def media_type
|
||||
object.content_type
|
||||
end
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
class AddUriToCustomEmojis < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
add_column :custom_emojis, :uri, :string
|
||||
add_column :custom_emojis, :image_remote_url, :string
|
||||
end
|
||||
end
|
Loading…
Reference in new issue