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
|
||||
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
|
||||
|
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