Merge branch 'avatar-fix' into 'develop'
Fix federation of avatars and images with legacy gab:// URLs See merge request gab/social/gab-social!43
This commit is contained in:
commit
842e5de971
@ -3,6 +3,15 @@
|
|||||||
class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||||
include RoutingHelper
|
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 :security
|
||||||
|
|
||||||
context_extensions :manually_approves_followers, :featured, :also_known_as,
|
context_extensions :manually_approves_followers, :featured, :also_known_as,
|
||||||
@ -83,10 +92,12 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def icon
|
def icon
|
||||||
|
return object.avatar_remote_url if is_gab_avatar?
|
||||||
object.avatar
|
object.avatar
|
||||||
end
|
end
|
||||||
|
|
||||||
def image
|
def image
|
||||||
|
return object.header_remote_url if is_gab_header?
|
||||||
object.header
|
object.header
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -99,11 +110,19 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def avatar_exists?
|
def avatar_exists?
|
||||||
object.avatar?
|
object.avatar? or is_gab_avatar?
|
||||||
end
|
end
|
||||||
|
|
||||||
def header_exists?
|
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
|
end
|
||||||
|
|
||||||
def manually_approves_followers
|
def manually_approves_followers
|
||||||
|
11
app/serializers/activitypub/gab_image_serializer.rb
Normal file
11
app/serializers/activitypub/gab_image_serializer.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# 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
|
Loading…
Reference in New Issue
Block a user