about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-01-23 21:09:27 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-01-23 21:09:27 +0100
commitf392030ab82a70086f93bb02c3faab53c3fbd28e (patch)
treeb2dc190e9f11a2bb9ab0af55c0b7380832bbfbf3
parentf2e08ff56855a2b14567f6218900823664a0ee2c (diff)
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
-rw-r--r--app/assets/javascripts/components/actions/cards.jsx7
-rw-r--r--app/controllers/api/v1/notifications_controller.rb5
-rw-r--r--app/controllers/api/v1/statuses_controller.rb3
-rw-r--r--app/lib/feed_manager.rb1
-rw-r--r--config/routes.rb16
5 files changed, 21 insertions, 11 deletions
diff --git a/app/assets/javascripts/components/actions/cards.jsx b/app/assets/javascripts/components/actions/cards.jsx
index ee421d5d7..714e80525 100644
--- a/app/assets/javascripts/components/actions/cards.jsx
+++ b/app/assets/javascripts/components/actions/cards.jsx
@@ -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));
     });
   };
diff --git a/app/controllers/api/v1/notifications_controller.rb b/app/controllers/api/v1/notifications_controller.rb
index 3fd701997..ee12446d8 100644
--- a/app/controllers/api/v1/notifications_controller.rb
+++ b/app/controllers/api/v1/notifications_controller.rb
@@ -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
diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb
index 37ed5e6dd..da87ebbad 100644
--- a/app/controllers/api/v1/statuses_controller.rb
+++ b/app/controllers/api/v1/statuses_controller.rb
@@ -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
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index 0056321fa..19f9dc16f 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -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
 
diff --git a/config/routes.rb b/config/routes.rb
index 7b9cda908..15fb924f1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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