26 lines
651 B
Ruby
26 lines
651 B
Ruby
module EjabberdManager
|
|
class GetAvatar < EjabberdManagerService
|
|
def initialize(user:)
|
|
@user = user
|
|
end
|
|
|
|
def call
|
|
res = get_vcard2 @user, "PHOTO", "BINVAL"
|
|
|
|
if res.status == 200
|
|
# VCARD PHOTO/BINVAL prop exists
|
|
img_base64 = JSON.parse(res.body)["content"]
|
|
ct_res = get_vcard2 @user, "PHOTO", "TYPE"
|
|
content_type = JSON.parse(ct_res.body)["content"]
|
|
{ content_type:, img_base64: }
|
|
elsif res.status == 400
|
|
# VCARD or PHOTO/BINVAL prop does not exist
|
|
nil
|
|
else
|
|
# Unexpected error, let job fail
|
|
raise res.inspect
|
|
end
|
|
end
|
|
end
|
|
end
|