Clean up notifications if a user can't see a topic
This commit is contained in:
parent
b45e9081ca
commit
b1d2aba0f3
|
@ -61,6 +61,14 @@ class TopicsController < ApplicationController
|
|||
perform_show_response
|
||||
|
||||
canonical_url absolute_without_cdn(@topic_view.canonical_path)
|
||||
rescue Discourse::InvalidAccess => ex
|
||||
|
||||
if current_user
|
||||
# If the user can't see the topic, clean up notifications for it.
|
||||
Notification.remove_for(current_user.id, params[:topic_id])
|
||||
end
|
||||
|
||||
raise ex
|
||||
end
|
||||
|
||||
def wordpress
|
||||
|
|
|
@ -65,6 +65,12 @@ class Notification < ActiveRecord::Base
|
|||
result
|
||||
end
|
||||
|
||||
# Clean up any notifications the user can no longer see. For example, if a topic was previously
|
||||
# public then turns private.
|
||||
def self.remove_for(user_id, topic_id)
|
||||
Notification.where(user_id: user_id, topic_id: topic_id).delete_all
|
||||
end
|
||||
|
||||
# Be wary of calling this frequently. O(n) JSON parsing can suck.
|
||||
def data_hash
|
||||
@data_hash ||= begin
|
||||
|
|
Loading…
Reference in New Issue