| 
									
										
										
										
											2017-07-15 03:01:39 +02:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-17 00:00:39 +02:00
										 |  |  | class ActivityPub::OutboxesController < ActivityPub::BaseController | 
					
						
							| 
									
										
										
										
											2018-05-04 19:19:11 +02:00
										 |  |  |   LIMIT = 20
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-02 10:19:59 +01:00
										 |  |  |   include SignatureVerification | 
					
						
							| 
									
										
										
										
											2019-07-08 12:03:45 +02:00
										 |  |  |   include AccountOwnedConcern | 
					
						
							| 
									
										
										
										
											2018-02-02 10:19:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-11 20:11:09 +02:00
										 |  |  |   before_action :require_signature!, if: :authorized_fetch_mode? | 
					
						
							| 
									
										
										
										
											2018-05-04 19:19:11 +02:00
										 |  |  |   before_action :set_statuses | 
					
						
							| 
									
										
										
										
											2019-04-04 01:30:44 +02:00
										 |  |  |   before_action :set_cache_headers | 
					
						
							| 
									
										
										
										
											2017-07-15 03:01:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def show | 
					
						
							| 
									
										
										
										
											2020-05-03 16:30:36 +02:00
										 |  |  |     expires_in(page_requested? ? 0 : 3.minutes, public: public_fetch_mode? && !(signed_request_account.present? && page_requested?)) | 
					
						
							| 
									
										
										
										
											2018-03-04 09:19:11 +01:00
										 |  |  |     render json: outbox_presenter, serializer: ActivityPub::OutboxSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json' | 
					
						
							| 
									
										
										
										
											2017-07-15 03:01:39 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def outbox_presenter | 
					
						
							| 
									
										
										
										
											2018-05-04 19:19:11 +02:00
										 |  |  |     if page_requested? | 
					
						
							|  |  |  |       ActivityPub::CollectionPresenter.new( | 
					
						
							| 
									
										
										
										
											2020-09-02 18:42:50 +02:00
										 |  |  |         id: outbox_url(page_params), | 
					
						
							| 
									
										
										
										
											2018-05-04 19:19:11 +02:00
										 |  |  |         type: :ordered, | 
					
						
							| 
									
										
										
										
											2020-09-02 18:42:50 +02:00
										 |  |  |         part_of: outbox_url, | 
					
						
							| 
									
										
										
										
											2018-05-04 19:19:11 +02:00
										 |  |  |         prev: prev_page, | 
					
						
							|  |  |  |         next: next_page, | 
					
						
							|  |  |  |         items: @statuses | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       ActivityPub::CollectionPresenter.new( | 
					
						
							|  |  |  |         id: account_outbox_url(@account), | 
					
						
							|  |  |  |         type: :ordered, | 
					
						
							|  |  |  |         size: @account.statuses_count, | 
					
						
							| 
									
										
										
										
											2020-09-02 18:42:50 +02:00
										 |  |  |         first: outbox_url(page: true), | 
					
						
							|  |  |  |         last: outbox_url(page: true, min_id: 0) | 
					
						
							| 
									
										
										
										
											2018-05-04 19:19:11 +02:00
										 |  |  |       ) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 18:42:50 +02:00
										 |  |  |   def outbox_url(**kwargs) | 
					
						
							|  |  |  |     if params[:account_username].present? | 
					
						
							|  |  |  |       account_outbox_url(@account, **kwargs) | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       instance_actor_outbox_url(**kwargs) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 19:19:11 +02:00
										 |  |  |   def next_page | 
					
						
							|  |  |  |     account_outbox_url(@account, page: true, max_id: @statuses.last.id) if @statuses.size == LIMIT | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def prev_page | 
					
						
							|  |  |  |     account_outbox_url(@account, page: true, min_id: @statuses.first.id) unless @statuses.empty? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def set_statuses | 
					
						
							|  |  |  |     return unless page_requested? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 19:31:56 +09:00
										 |  |  |     @statuses = cache_collection_paginated_by_id( | 
					
						
							| 
									
										
										
										
											2020-09-11 15:16:29 +02:00
										 |  |  |       @account.statuses.permitted_for(@account, signed_request_account), | 
					
						
							| 
									
										
										
										
											2020-08-28 19:31:56 +09:00
										 |  |  |       Status, | 
					
						
							|  |  |  |       LIMIT, | 
					
						
							|  |  |  |       params_slice(:max_id, :min_id, :since_id) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-05-04 19:19:11 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def page_requested? | 
					
						
							| 
									
										
										
										
											2020-05-03 16:30:36 +02:00
										 |  |  |     truthy_param?(:page) | 
					
						
							| 
									
										
										
										
											2018-05-04 19:19:11 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def page_params | 
					
						
							|  |  |  |     { page: true, max_id: params[:max_id], min_id: params[:min_id] }.compact | 
					
						
							| 
									
										
										
										
											2017-07-15 03:01:39 +02:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-09-02 18:42:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def set_account | 
					
						
							|  |  |  |     @account = params[:account_username].present? ? Account.find_local!(username_param) : Account.representative | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-07-15 03:01:39 +02:00
										 |  |  | end |