FIX: Allow liked notifications consolidation to be disabled.
This commit is contained in:
parent
f8db93df5f
commit
e7b49c42c4
|
@ -76,6 +76,10 @@ class PostActionNotifier
|
|||
post = post_action.post
|
||||
return if post_action.user.blank?
|
||||
|
||||
if SiteSetting.likes_notification_consolidation_threshold.zero?
|
||||
return create_liked_notification(alerter, post, post_action)
|
||||
end
|
||||
|
||||
user_notifications = post.user.notifications
|
||||
|
||||
consolidation_window =
|
||||
|
@ -114,27 +118,30 @@ class PostActionNotifier
|
|||
post_action
|
||||
)
|
||||
else
|
||||
alerter.create_notification(
|
||||
post.user,
|
||||
Notification.types[:liked],
|
||||
post,
|
||||
display_username: post_action.user.username,
|
||||
post_action_id: post_action.id,
|
||||
user_id: post_action.user_id
|
||||
)
|
||||
create_liked_notification(alerter, post, post_action)
|
||||
end
|
||||
end
|
||||
|
||||
def self.update_consolidated_liked_notification_count!(notification)
|
||||
Notification.transaction do
|
||||
data = JSON.parse(notification.data)
|
||||
data["count"] += 1
|
||||
def self.create_liked_notification(alerter, post, post_action)
|
||||
alerter.create_notification(
|
||||
post.user,
|
||||
Notification.types[:liked],
|
||||
post,
|
||||
display_username: post_action.user.username,
|
||||
post_action_id: post_action.id,
|
||||
user_id: post_action.user_id
|
||||
)
|
||||
end
|
||||
private_class_method :create_liked_notification
|
||||
|
||||
notification.update!(
|
||||
data: data.to_json,
|
||||
read: false
|
||||
)
|
||||
end
|
||||
def self.update_consolidated_liked_notification_count!(notification)
|
||||
data = JSON.parse(notification.data)
|
||||
data["count"] += 1
|
||||
|
||||
notification.update!(
|
||||
data: data.to_json,
|
||||
read: false
|
||||
)
|
||||
end
|
||||
private_class_method :update_consolidated_liked_notification_count!
|
||||
|
||||
|
|
|
@ -1789,7 +1789,7 @@ en:
|
|||
|
||||
disable_edit_notifications: "Disables edit notifications by the system user when 'download_remote_images_to_local' is active."
|
||||
|
||||
likes_notification_consolidation_threshold: "Number of liked notifications received before the notifications are consolidated into a single one. The window can be configured via `SiteSetting.likes_notification_consolidation_window_mins`."
|
||||
likes_notification_consolidation_threshold: "Number of liked notifications received before the notifications are consolidated into a single one. Set to 0 to disable. The window can be configured via `SiteSetting.likes_notification_consolidation_window_mins`."
|
||||
|
||||
likes_notification_consolidation_window_mins: "Duration in minutes where liked notifications are consolidated into a single notification once the threshold has been reaced. The threshold can be configured via `SiteSetting.likes_notification_consolidation_threshold`."
|
||||
|
||||
|
|
|
@ -1702,7 +1702,7 @@ uncategorized:
|
|||
|
||||
likes_notification_consolidation_threshold:
|
||||
default: 5
|
||||
min: 3
|
||||
min: 0
|
||||
|
||||
likes_notification_consolidation_window_mins:
|
||||
default: 120
|
||||
|
@ -1819,7 +1819,7 @@ user_preferences:
|
|||
default_categories_watching_first_post:
|
||||
type: category_list
|
||||
default: ''
|
||||
|
||||
|
||||
default_text_size:
|
||||
type: enum
|
||||
default: normal
|
||||
|
|
|
@ -300,15 +300,35 @@ describe PostAction do
|
|||
let(:liker) { Fabricate(:user) }
|
||||
let(:likee) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
SiteSetting.likes_notification_consolidation_threshold = 3
|
||||
it "can be disabled" do
|
||||
SiteSetting.likes_notification_consolidation_threshold = 0
|
||||
|
||||
expect do
|
||||
PostAction.act(
|
||||
liker,
|
||||
Fabricate(:post, user: likee),
|
||||
PostActionType.types[:like]
|
||||
)
|
||||
end.to change { likee.reload.notifications.count }.by(1)
|
||||
|
||||
SiteSetting.likes_notification_consolidation_threshold = 1
|
||||
|
||||
expect do
|
||||
PostAction.act(
|
||||
liker,
|
||||
Fabricate(:post, user: likee),
|
||||
PostActionType.types[:like]
|
||||
)
|
||||
end.to_not change { likee.reload.notifications.count }
|
||||
end
|
||||
|
||||
it 'should consolidate likes notification when the threshold is reached' do
|
||||
SiteSetting.likes_notification_consolidation_threshold = 2
|
||||
|
||||
freeze_time
|
||||
|
||||
expect do
|
||||
4.times do
|
||||
3.times do
|
||||
PostAction.act(
|
||||
liker,
|
||||
Fabricate(:post, user: likee),
|
||||
|
@ -327,7 +347,7 @@ describe PostAction do
|
|||
|
||||
expect(data["username"]).to eq(liker.username)
|
||||
expect(data["display_username"]).to eq(liker.username)
|
||||
expect(data["count"]).to eq(4)
|
||||
expect(data["count"]).to eq(3)
|
||||
|
||||
notification.update!(read: true)
|
||||
|
||||
|
@ -344,7 +364,7 @@ describe PostAction do
|
|||
data = JSON.parse(notification.reload.data)
|
||||
|
||||
expect(notification.read).to eq(false)
|
||||
expect(data["count"]).to eq(6)
|
||||
expect(data["count"]).to eq(5)
|
||||
|
||||
# Like from a different user shouldn't be consolidated
|
||||
expect do
|
||||
|
|
Loading…
Reference in New Issue