New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encode custom emojis as resolveable objects in ActivityPub #5243
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,21 +142,6 @@ def name | |
end | ||
end | ||
|
||
class CustomEmojiSerializer < ActiveModel::Serializer | ||
include RoutingHelper | ||
|
||
attributes :type, :href, :name | ||
|
||
def type | ||
'Emoji' | ||
end | ||
|
||
def href | ||
full_asset_url(object.image.url) | ||
end | ||
|
||
def name | ||
":#{object.shortcode}:" | ||
end | ||
class CustomEmojiSerializer < ActivityPub::EmojiSerializer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the difference between this and the Emoji serializer? do we need both? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AMS derives serializer name from class name, virtual_tags is array of various objects, some of which are instances of CustomEmoji, but what we need is called ActivityPub::EmojiSerializer. It's easier to do this than define an AMS method that changes how serializer names are derived. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this new? is there a practical implication to this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's just nice