Add /api/v1/notifications/clear, non-existing link cards for statuses will

now return empty hash instead of throwing a 404 error. When following,
merge into timeline will filter statuses
This commit is contained in:
Eugen Rochko 2017-01-23 21:09:27 +01:00
parent f2e08ff568
commit f392030ab8
5 changed files with 21 additions and 11 deletions

View File

@ -9,13 +9,12 @@ export function fetchStatusCard(id) {
dispatch(fetchStatusCardRequest(id)); dispatch(fetchStatusCardRequest(id));
api(getState).get(`/api/v1/statuses/${id}/card`).then(response => { api(getState).get(`/api/v1/statuses/${id}/card`).then(response => {
dispatch(fetchStatusCardSuccess(id, response.data)); if (response.data.length === 0) {
}).catch(error => {
if (error.response.status === 404) {
// This is fine
return; return;
} }
dispatch(fetchStatusCardSuccess(id, response.data));
}).catch(error => {
dispatch(fetchStatusCardFail(id, error)); dispatch(fetchStatusCardFail(id, error));
}); });
}; };

View File

@ -24,4 +24,9 @@ class Api::V1::NotificationsController < ApiController
def show def show
@notification = Notification.where(account: current_account).find(params[:id]) @notification = Notification.where(account: current_account).find(params[:id])
end end
def clear
Notification.where(account: current_account).delete_all
render_empty
end
end end

View File

@ -22,7 +22,8 @@ class Api::V1::StatusesController < ApiController
end end
def card def card
@card = PreviewCard.find_by!(status: @status) @card = PreviewCard.find_by(status: @status)
render_empty if @card.nil?
end end
def reblogged_by def reblogged_by

View File

@ -43,6 +43,7 @@ class FeedManager
timeline_key = key(:home, into_account.id) timeline_key = key(:home, into_account.id)
from_account.statuses.limit(MAX_ITEMS).each do |status| from_account.statuses.limit(MAX_ITEMS).each do |status|
next if filter?(:home, status, into_account)
redis.zadd(timeline_key, status.id, status.id) redis.zadd(timeline_key, status.id, status.id)
end end

View File

@ -103,10 +103,11 @@ Rails.application.routes.draw do
get '/timelines/public', to: 'timelines#public', as: :public_timeline get '/timelines/public', to: 'timelines#public', as: :public_timeline
get '/timelines/tag/:id', to: 'timelines#tag', as: :hashtag_timeline get '/timelines/tag/:id', to: 'timelines#tag', as: :hashtag_timeline
resources :follows, only: [:create] resources :follows, only: [:create]
resources :media, only: [:create] resources :media, only: [:create]
resources :apps, only: [:create] resources :apps, only: [:create]
resources :blocks, only: [:index] resources :blocks, only: [:index]
resources :favourites, only: [:index]
resources :follow_requests, only: [:index] do resources :follow_requests, only: [:index] do
member do member do
@ -115,8 +116,11 @@ Rails.application.routes.draw do
end end
end end
resources :notifications, only: [:index, :show] resources :notifications, only: [:index, :show] do
resources :favourites, only: [:index] collection do
post :clear
end
end
resources :accounts, only: [:show] do resources :accounts, only: [:show] do
collection do collection do