FEATURE: mark last notification unread when removing timings

This calls a bit more attention to the deferred topic by amending the "read"
state of the last notification on the topic.
This commit is contained in:
Sam Saffron
2019-04-09 12:42:21 +10:00
parent f0bb492d24
commit f6db30a5da
2 changed files with 46 additions and 6 deletions

View File

@@ -254,10 +254,25 @@ class TopicsController < ApplicationController
end
def destroy_timings
topic_id = params[:topic_id].to_i
if params[:last].to_s == "1"
PostTiming.destroy_last_for(current_user, params[:topic_id])
PostTiming.destroy_last_for(current_user, topic_id)
else
PostTiming.destroy_for(current_user.id, [params[:topic_id].to_i])
PostTiming.destroy_for(current_user.id, [topic_id])
end
last_notification = Notification
.where(
user_id: current_user.id,
topic_id: topic_id
)
.order(created_at: :desc)
.limit(1)
.first
if last_notification
last_notification.update!(read: false)
end
render body: nil