Commit 842e5de9 authored by Alex Gleason's avatar Alex Gleason

Merge branch 'avatar-fix' into 'develop'

Fix federation of avatars and images with legacy gab:// URLs

See merge request gab/social/gab-social!43
parents d524741a 28cc38ad
......@@ -3,6 +3,15 @@
class ActivityPub::ActorSerializer < ActivityPub::Serializer
include RoutingHelper
# Conditionally serialize Gab image for gab:// URLs
def self.serializer_for(object, options)
gab_image = object.is_a?(String) and object.start_with?('gab://')
if gab_image and options[:serializer] == ActivityPub::ImageSerializer
return ActivityPub::GabImageSerializer
end
super
end
context :security
context_extensions :manually_approves_followers, :featured, :also_known_as,
......@@ -83,10 +92,12 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
def icon
return object.avatar_remote_url if is_gab_avatar?
object.avatar
end
def image
return object.header_remote_url if is_gab_header?
object.header
end
......@@ -99,11 +110,19 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
end
def avatar_exists?
object.avatar?
object.avatar? or is_gab_avatar?
end
def header_exists?
object.header?
object.header? or is_gab_header?
end
def is_gab_avatar?
object.avatar_remote_url&.start_with?('gab://')
end
def is_gab_header?
object.header_remote_url&.start_with?('gab://')
end
def manually_approves_followers
......
# frozen_string_literal: true
class ActivityPub::GabImageSerializer < ActivityPub::ImageSerializer
def url
object
.sub('gab://avatar/', 'https://gab.com/media/user/')
.sub('gab://header/', 'https://gab.com/media/user/')
end
def media_type; end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment