Skip to content

Commit

Permalink
Allow ActivityPub Note's tag and attachment to be single objects (#5534)
Browse files Browse the repository at this point in the history
  • Loading branch information
puckipedia authored and Gargron committed Oct 27, 2017
1 parent 0129f5e commit 0cb329f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/helpers/jsonld_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def first_of_value(value)
value.is_a?(Array) ? value.first : value
end

def as_array(value)
value.is_a?(Array) ? value : [value]
end

def value_or_id(value)
value.is_a?(String) || value.nil? ? value : value['id']
end
Expand Down
8 changes: 4 additions & 4 deletions app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def status_params
end

def process_tags(status)
return unless @object['tag'].is_a?(Array)
return if @object['tag'].nil?

@object['tag'].each do |tag|
as_array(@object['tag']).each do |tag|
case tag['type']
when 'Hashtag'
process_hashtag tag, status
Expand Down Expand Up @@ -103,9 +103,9 @@ def process_emoji(tag, _status)
end

def process_attachments(status)
return unless @object['attachment'].is_a?(Array)
return if @object['attachment'].nil?

@object['attachment'].each do |attachment|
as_array(@object['attachment']).each do |attachment|
next if unsupported_media_type?(attachment['mediaType']) || attachment['url'].blank?

href = Addressable::URI.parse(attachment['url']).normalize.to_s
Expand Down

0 comments on commit 0cb329f

Please sign in to comment.