Improved /api/v1/accounts/:id/statuses with new params: only_media, exclude_replies

Redirect /:username to /users/:username
Redirect /:username/:id to /users/:username/updates/:id
Updated API documentation and sponsors
signup-info-prompt
Eugen Rochko 2017-03-05 17:27:17 +01:00
parent 07b166af64
commit 5f4e402204
5 changed files with 40 additions and 22 deletions

View File

@ -47,6 +47,8 @@ class Api::V1::AccountsController < ApiController
def statuses def statuses
@statuses = @account.statuses.permitted_for(@account, current_account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id]) @statuses = @account.statuses.permitted_for(@account, current_account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
@statuses = @statuses.where(id: MediaAttachment.where(account: @account).where.not(status_id: nil).reorder('').select('distinct status_id')) if params[:only_media]
@statuses = @statuses.without_replies if params[:exclude_replies]
@statuses = cache_collection(@statuses, Status) @statuses = cache_collection(@statuses, Status)
set_maps(@statuses) set_maps(@statuses)
@ -58,21 +60,6 @@ class Api::V1::AccountsController < ApiController
set_pagination_headers(next_path, prev_path) set_pagination_headers(next_path, prev_path)
end end
def media_statuses
media_ids = MediaAttachment.where(account: @account).where.not(status_id: nil).reorder('').select('distinct status_id')
@statuses = @account.statuses.where(id: media_ids).permitted_for(@account, current_account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
@statuses = cache_collection(@statuses, Status)
set_maps(@statuses)
set_counters_maps(@statuses)
next_path = media_statuses_api_v1_account_url(max_id: @statuses.last.id) unless @statuses.empty?
prev_path = media_statuses_api_v1_account_url(since_id: @statuses.first.id) unless @statuses.empty?
set_pagination_headers(next_path, prev_path)
render action: :statuses
end
def follow def follow
FollowService.new.call(current_user.account, @account.acct) FollowService.new.call(current_user.account, @account.acct)
set_relationship set_relationship

View File

@ -37,6 +37,9 @@ class Status < ApplicationRecord
scope :remote, -> { where.not(uri: nil) } scope :remote, -> { where.not(uri: nil) }
scope :local, -> { where(uri: nil) } scope :local, -> { where(uri: nil) }
scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') }
scope :without_reblogs, -> { where('statuses.reblog_of_id IS NULL') }
cache_associated :account, :application, :media_attachments, :tags, :stream_entry, mentions: :account, reblog: [:account, :application, :stream_entry, :tags, :media_attachments, mentions: :account], thread: :account cache_associated :account, :application, :media_attachments, :tags, :stream_entry, mentions: :account, reblog: [:account, :application, :stream_entry, :tags, :media_attachments, mentions: :account], thread: :account
def reply? def reply?
@ -109,8 +112,8 @@ class Status < ApplicationRecord
def as_public_timeline(account = nil, local_only = false) def as_public_timeline(account = nil, local_only = false)
query = joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id') query = joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id')
.where(visibility: :public) .where(visibility: :public)
.where('(statuses.reply = false OR statuses.in_reply_to_account_id = statuses.account_id)') .without_replies
.where('statuses.reblog_of_id IS NULL') .without_reblogs
query = query.where('accounts.domain IS NULL') if local_only query = query.where('accounts.domain IS NULL') if local_only
@ -121,7 +124,7 @@ class Status < ApplicationRecord
query = tag.statuses query = tag.statuses
.joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id') .joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id')
.where(visibility: :public) .where(visibility: :public)
.where('statuses.reblog_of_id IS NULL') .without_reblogs
query = query.where('accounts.domain IS NULL') if local_only query = query.where('accounts.domain IS NULL') if local_only

View File

@ -153,7 +153,6 @@ Rails.application.routes.draw do
member do member do
get :statuses get :statuses
get 'statuses/media', to: 'accounts#media_statuses', as: :media_statuses
get :followers get :followers
get :following get :following
@ -180,5 +179,8 @@ Rails.application.routes.draw do
root 'home#index' root 'home#index'
get '/:username', to: redirect('/users/%{username}')
get '/:username/:id', to: redirect('/users/%{username}/updates/%{id}')
match '*unmatched_route', via: :all, to: 'application#raise_not_found' match '*unmatched_route', via: :all, to: 'application#raise_not_found'
end end

View File

@ -32,7 +32,7 @@ These people make the development of Mastodon possible through [Patreon](https:/
- [C418](https://mastodon.social/users/C418) - [C418](https://mastodon.social/users/C418)
- [halcy](https://icosahedron.website/users/halcy) - [halcy](https://icosahedron.website/users/halcy)
- [Extropic](https://gnusocial.no/extropic) - [Extropic](https://gnusocial.no/extropic)
- TBD - [Pat Monaghan](http://iwrite.software/)
- TBD - TBD
- TBD - TBD
- TBD - TBD

View File

@ -75,6 +75,10 @@ Query parameters:
- `max_id` (optional): Skip statuses younger than ID (e.g. navigate backwards in time) - `max_id` (optional): Skip statuses younger than ID (e.g. navigate backwards in time)
- `since_id` (optional): Skip statuses older than ID (e.g. check for updates) - `since_id` (optional): Skip statuses older than ID (e.g. check for updates)
Query parameters for public and tag timelines only:
- `local` (optional): Only return statuses originating from this instance
### Notifications ### Notifications
**GET /api/v1/notifications** **GET /api/v1/notifications**
@ -115,7 +119,14 @@ Returns authenticated user's account.
**GET /api/v1/accounts/:id/statuses** **GET /api/v1/accounts/:id/statuses**
Returns statuses by user. Same options as timeline are permitted. Returns statuses by user.
Query parameters:
- `max_id` (optional): Skip statuses younger than ID (e.g. navigate backwards in time)
- `since_id` (optional): Skip statuses older than ID (e.g. check for updates)
- `only_media` (optional): Only return statuses that have media attachments
- `exclude_replies` (optional): Skip statuses that reply to other statuses
**GET /api/v1/accounts/:id/following** **GET /api/v1/accounts/:id/following**
@ -127,7 +138,7 @@ Returns users the given user is followed by.
**GET /api/v1/accounts/relationships** **GET /api/v1/accounts/relationships**
Returns relationships (`following`, `followed_by`, `blocking`) of the current user to a list of given accounts. Returns relationships (`following`, `followed_by`, `blocking`, `muting`, `requested`) of the current user to a list of given accounts.
Query parameters: Query parameters:
@ -146,6 +157,14 @@ Query parameters:
Returns accounts blocked by authenticated user. Returns accounts blocked by authenticated user.
**GET /api/v1/mutes**
Returns accounts muted by authenticated user.
**GET /api/v1/follow_requests**
Returns accounts that want to follow the authenticated user but are waiting for approval.
**GET /api/v1/favourites** **GET /api/v1/favourites**
Returns statuses favourited by authenticated user. Returns statuses favourited by authenticated user.
@ -207,6 +226,13 @@ Returns the updated relationship to the user.
Returns the updated relationship to the user. Returns the updated relationship to the user.
# Muting and unmuting users
**POST /api/v1/accounts/:id/mute**
**POST /api/v1/accounts/:id/unmute**
Returns the updated relationship to the user.
### OAuth apps ### OAuth apps
**POST /api/v1/apps** **POST /api/v1/apps**