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
|
post = post_action.post
|
||||||
return if post_action.user.blank?
|
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
|
user_notifications = post.user.notifications
|
||||||
|
|
||||||
consolidation_window =
|
consolidation_window =
|
||||||
|
@ -114,27 +118,30 @@ class PostActionNotifier
|
||||||
post_action
|
post_action
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
alerter.create_notification(
|
create_liked_notification(alerter, post, post_action)
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_consolidated_liked_notification_count!(notification)
|
def self.create_liked_notification(alerter, post, post_action)
|
||||||
Notification.transaction do
|
alerter.create_notification(
|
||||||
data = JSON.parse(notification.data)
|
post.user,
|
||||||
data["count"] += 1
|
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!(
|
def self.update_consolidated_liked_notification_count!(notification)
|
||||||
data: data.to_json,
|
data = JSON.parse(notification.data)
|
||||||
read: false
|
data["count"] += 1
|
||||||
)
|
|
||||||
end
|
notification.update!(
|
||||||
|
data: data.to_json,
|
||||||
|
read: false
|
||||||
|
)
|
||||||
end
|
end
|
||||||
private_class_method :update_consolidated_liked_notification_count!
|
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."
|
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`."
|
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:
|
likes_notification_consolidation_threshold:
|
||||||
default: 5
|
default: 5
|
||||||
min: 3
|
min: 0
|
||||||
|
|
||||||
likes_notification_consolidation_window_mins:
|
likes_notification_consolidation_window_mins:
|
||||||
default: 120
|
default: 120
|
||||||
|
@ -1819,7 +1819,7 @@ user_preferences:
|
||||||
default_categories_watching_first_post:
|
default_categories_watching_first_post:
|
||||||
type: category_list
|
type: category_list
|
||||||
default: ''
|
default: ''
|
||||||
|
|
||||||
default_text_size:
|
default_text_size:
|
||||||
type: enum
|
type: enum
|
||||||
default: normal
|
default: normal
|
||||||
|
|
|
@ -300,15 +300,35 @@ describe PostAction do
|
||||||
let(:liker) { Fabricate(:user) }
|
let(:liker) { Fabricate(:user) }
|
||||||
let(:likee) { Fabricate(:user) }
|
let(:likee) { Fabricate(:user) }
|
||||||
|
|
||||||
before do
|
it "can be disabled" do
|
||||||
SiteSetting.likes_notification_consolidation_threshold = 3
|
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
|
end
|
||||||
|
|
||||||
it 'should consolidate likes notification when the threshold is reached' do
|
it 'should consolidate likes notification when the threshold is reached' do
|
||||||
|
SiteSetting.likes_notification_consolidation_threshold = 2
|
||||||
|
|
||||||
freeze_time
|
freeze_time
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
4.times do
|
3.times do
|
||||||
PostAction.act(
|
PostAction.act(
|
||||||
liker,
|
liker,
|
||||||
Fabricate(:post, user: likee),
|
Fabricate(:post, user: likee),
|
||||||
|
@ -327,7 +347,7 @@ describe PostAction do
|
||||||
|
|
||||||
expect(data["username"]).to eq(liker.username)
|
expect(data["username"]).to eq(liker.username)
|
||||||
expect(data["display_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)
|
notification.update!(read: true)
|
||||||
|
|
||||||
|
@ -344,7 +364,7 @@ describe PostAction do
|
||||||
data = JSON.parse(notification.reload.data)
|
data = JSON.parse(notification.reload.data)
|
||||||
|
|
||||||
expect(notification.read).to eq(false)
|
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
|
# Like from a different user shouldn't be consolidated
|
||||||
expect do
|
expect do
|
||||||
|
|
Loading…
Reference in New Issue