Adding enclosures to Atom and statuses JSON
This commit is contained in:
		
							parent
							
								
									eec0dc46a6
								
							
						
					
					
						commit
						1d9c886518
					
				| @ -125,6 +125,10 @@ module AtomBuilderHelper | |||||||
|     xml.link(rel: 'mentioned', href: uri_for_target(account)) |     xml.link(rel: 'mentioned', href: uri_for_target(account)) | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   def link_enclosure(xml, media) | ||||||
|  |     xml.link(rel: 'enclosure', href: full_asset_url(media.file.url), type: media.file_content_type, length: media.file_size) | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   def link_avatar(xml, account) |   def link_avatar(xml, account) | ||||||
|     single_link_avatar(xml, account, :large,  300) |     single_link_avatar(xml, account, :large,  300) | ||||||
|     single_link_avatar(xml, account, :medium, 96) |     single_link_avatar(xml, account, :medium, 96) | ||||||
| @ -205,6 +209,12 @@ module AtomBuilderHelper | |||||||
|     stream_entry.mentions.each do |mentioned| |     stream_entry.mentions.each do |mentioned| | ||||||
|       link_mention xml, mentioned |       link_mention xml, mentioned | ||||||
|     end |     end | ||||||
|  | 
 | ||||||
|  |     if stream_entry.activity.is_a?(Status) | ||||||
|  |       stream_entry.activity.media_attachments.each do |media| | ||||||
|  |         link_enclosure xml, media | ||||||
|  |       end | ||||||
|  |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   private |   private | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ class Status < ApplicationRecord | |||||||
|   validates :text, presence: true, if: Proc.new { |s| s.local? && !s.reblog? } |   validates :text, presence: true, if: Proc.new { |s| s.local? && !s.reblog? } | ||||||
| 
 | 
 | ||||||
|   scope :with_counters, -> { select('statuses.*, (select count(r.id) from statuses as r where r.reblog_of_id = statuses.id) as reblogs_count, (select count(f.id) from favourites as f where f.status_id = statuses.id) as favourites_count') } |   scope :with_counters, -> { select('statuses.*, (select count(r.id) from statuses as r where r.reblog_of_id = statuses.id) as reblogs_count, (select count(f.id) from favourites as f where f.status_id = statuses.id) as favourites_count') } | ||||||
|   scope :with_includes, -> { includes(:account, :mentions, :stream_entry, reblog: [:account, :mentions], thread: :account) } |   scope :with_includes, -> { includes(:account, :mentions, :media_attachments, :stream_entry, reblog: [:account, :mentions], thread: :account) } | ||||||
| 
 | 
 | ||||||
|   def local? |   def local? | ||||||
|     self.uri.nil? |     self.uri.nil? | ||||||
|  | |||||||
| @ -16,3 +16,7 @@ end | |||||||
| child :account do | child :account do | ||||||
|   extends('api/accounts/show') |   extends('api/accounts/show') | ||||||
| end | end | ||||||
|  | 
 | ||||||
|  | child :media_attachments do | ||||||
|  |   node(:url) { |media| full_asset_url(media.file.url) } | ||||||
|  | end | ||||||
|  | |||||||
| @ -174,6 +174,10 @@ RSpec.describe AtomBuilderHelper, type: :helper do | |||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   describe '#link_enclosure' do | ||||||
|  |     pending | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   describe '#logo' do |   describe '#logo' do | ||||||
|     it 'creates a logo' do |     it 'creates a logo' do | ||||||
|       expect(used_in_builder { |xml| helper.logo(xml, 1) }).to match '<logo>1</logo>' |       expect(used_in_builder { |xml| helper.logo(xml, 1) }).to match '<logo>1</logo>' | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user