about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authorOndřej Hruška <ondra@ondrovo.com>2017-07-25 21:36:22 +0200
committerOndřej Hruška <ondra@ondrovo.com>2017-07-25 21:36:22 +0200
commit7e5691804d4f0019a89b8b8a3dad532bc9d940ea (patch)
tree84c2f4e4ac07bea3915639a50df84eb62b6c5768 /app/controllers
parent852acbd7385a640d9e00e462d58a847851744034 (diff)
parent7232cdf7e8249f79078005931b1165e54e413fa9 (diff)
Merge git://github.com/tootsuite/mastodon into tootsuite-master
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/api/v1/favourites_controller.rb4
-rw-r--r--app/controllers/api/web/push_subscriptions_controller.rb23
2 files changed, 19 insertions, 8 deletions
diff --git a/app/controllers/api/v1/favourites_controller.rb b/app/controllers/api/v1/favourites_controller.rb
index 92c0a62a9..9d73bb337 100644
--- a/app/controllers/api/v1/favourites_controller.rb
+++ b/app/controllers/api/v1/favourites_controller.rb
@@ -20,9 +20,7 @@ class Api::V1::FavouritesController < Api::BaseController
 
   def cached_favourites
     cache_collection(
-      Status.where(
-        id: results.map(&:status_id)
-      ),
+      Status.reorder(nil).joins(:favourites).merge(results),
       Status
     )
   end
diff --git a/app/controllers/api/web/push_subscriptions_controller.rb b/app/controllers/api/web/push_subscriptions_controller.rb
index 8425db7b4..d66237feb 100644
--- a/app/controllers/api/web/push_subscriptions_controller.rb
+++ b/app/controllers/api/web/push_subscriptions_controller.rb
@@ -6,8 +6,8 @@ class Api::Web::PushSubscriptionsController < Api::BaseController
   before_action :require_user!
 
   def create
-    params.require(:data).require(:endpoint)
-    params.require(:data).require(:keys).require([:auth, :p256dh])
+    params.require(:subscription).require(:endpoint)
+    params.require(:subscription).require(:keys).require([:auth, :p256dh])
 
     active_session = current_session
 
@@ -16,10 +16,23 @@ class Api::Web::PushSubscriptionsController < Api::BaseController
       active_session.update!(web_push_subscription: nil)
     end
 
+    # Mobile devices do not support regular notifications, so we enable push notifications by default
+    alerts_enabled = active_session.detection.device.mobile? || active_session.detection.device.tablet?
+
+    data = {
+      alerts: {
+        follow: alerts_enabled,
+        favourite: alerts_enabled,
+        reblog: alerts_enabled,
+        mention: alerts_enabled,
+      },
+    }
+
     web_subscription = ::Web::PushSubscription.create!(
-      endpoint: params[:data][:endpoint],
-      key_p256dh: params[:data][:keys][:p256dh],
-      key_auth: params[:data][:keys][:auth]
+      endpoint: params[:subscription][:endpoint],
+      key_p256dh: params[:subscription][:keys][:p256dh],
+      key_auth: params[:subscription][:keys][:auth],
+      data: data
     )
 
     active_session.update!(web_push_subscription: web_subscription)