]> cat aescling's git repositories - mastodon.git/commitdiff
Add /api/v1/notifications/clear, non-existing link cards for statuses will
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 23 Jan 2017 20:09:27 +0000 (21:09 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 23 Jan 2017 20:09:27 +0000 (21:09 +0100)
now return empty hash instead of throwing a 404 error. When following,
merge into timeline will filter statuses

app/assets/javascripts/components/actions/cards.jsx
app/controllers/api/v1/notifications_controller.rb
app/controllers/api/v1/statuses_controller.rb
app/lib/feed_manager.rb
config/routes.rb

index ee421d5d7c9679cf18d157d71368fe61dbc7db48..714e805255e1ce27e087f49112157fd26cd3cdde 100644 (file)
@@ -9,13 +9,12 @@ export function fetchStatusCard(id) {
     dispatch(fetchStatusCardRequest(id));
 
     api(getState).get(`/api/v1/statuses/${id}/card`).then(response => {
-      dispatch(fetchStatusCardSuccess(id, response.data));
-    }).catch(error => {
-      if (error.response.status === 404) {
-        // This is fine
+      if (response.data.length === 0) {
         return;
       }
 
+      dispatch(fetchStatusCardSuccess(id, response.data));
+    }).catch(error => {
       dispatch(fetchStatusCardFail(id, error));
     });
   };
index 3fd7019976a6905024501a1abd76b08ce5fb498c..ee12446d8217f9fba9836885d98522d793db1041 100644 (file)
@@ -24,4 +24,9 @@ class Api::V1::NotificationsController < ApiController
   def show
     @notification = Notification.where(account: current_account).find(params[:id])
   end
+
+  def clear
+    Notification.where(account: current_account).delete_all
+    render_empty
+  end
 end
index 37ed5e6dd65ff1569fa57a4c1c18dc210d2a3147..da87ebbaddf3ec1ca0fdbc2db0e65123f03379af 100644 (file)
@@ -22,7 +22,8 @@ class Api::V1::StatusesController < ApiController
   end
 
   def card
-    @card = PreviewCard.find_by!(status: @status)
+    @card = PreviewCard.find_by(status: @status)
+    render_empty if @card.nil?
   end
 
   def reblogged_by
index 0056321faf30b1c47fd9e0e205524a4569a93c5d..19f9dc16f5eb8b1f5130860603319593f9fb9042 100644 (file)
@@ -43,6 +43,7 @@ class FeedManager
     timeline_key = key(:home, into_account.id)
 
     from_account.statuses.limit(MAX_ITEMS).each do |status|
+      next if filter?(:home, status, into_account)
       redis.zadd(timeline_key, status.id, status.id)
     end
 
index 7b9cda908d12a8c91efc567101c1e81b05a52fb3..15fb924f117b487de9ccd7575cc9987fa7174d75 100644 (file)
@@ -103,10 +103,11 @@ Rails.application.routes.draw do
       get '/timelines/public',   to: 'timelines#public', as: :public_timeline
       get '/timelines/tag/:id',  to: 'timelines#tag', as: :hashtag_timeline
 
-      resources :follows,  only: [:create]
-      resources :media,    only: [:create]
-      resources :apps,     only: [:create]
-      resources :blocks,   only: [:index]
+      resources :follows,    only: [:create]
+      resources :media,      only: [:create]
+      resources :apps,       only: [:create]
+      resources :blocks,     only: [:index]
+      resources :favourites, only: [:index]
 
       resources :follow_requests, only: [:index] do
         member do
@@ -115,8 +116,11 @@ Rails.application.routes.draw do
         end
       end
 
-      resources :notifications, only: [:index, :show]
-      resources :favourites,    only: [:index]
+      resources :notifications, only: [:index, :show] do
+        collection do
+          post :clear
+        end
+      end
 
       resources :accounts, only: [:show] do
         collection do