mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 16:38:48 +08:00
FEATURE: High priority bookmark reminder notifications (#9290)
Introduce the concept of "high priority notifications" which include PM and bookmark reminder notifications. Now bookmark reminder notifications act in the same way as PM notifications (float to top of recent list, show in the green bubble) and most instances of unread_private_messages in the UI have been replaced with unread_high_priority_notifications. The user email digest is changed to just have a section about unread high priority notifications, the unread PM section has been removed. A high_priority boolean column has been added to the Notification table and relevant indices added to account for it. unread_private_messages has been kept on the User model purely for backwards compat, but now just returns unread_high_priority_notifications count so this may cause some inconsistencies in the UI.
This commit is contained in:
@ -1779,7 +1779,7 @@ describe User do
|
||||
end
|
||||
|
||||
describe '#publish_notifications_state' do
|
||||
it 'should publish the right message' do
|
||||
it 'should publish the right message sorted by ID desc' do
|
||||
notification = Fabricate(:notification, user: user)
|
||||
notification2 = Fabricate(:notification, user: user, read: true)
|
||||
|
||||
@ -1788,8 +1788,41 @@ describe User do
|
||||
end.first
|
||||
|
||||
expect(message.data[:recent]).to eq([
|
||||
[notification2.id, true], [notification.id, false]
|
||||
])
|
||||
[notification2.id, true], [notification.id, false]
|
||||
])
|
||||
end
|
||||
|
||||
it 'floats the unread high priority notifications to the top' do
|
||||
notification = Fabricate(:notification, user: user)
|
||||
notification2 = Fabricate(:notification, user: user, read: true)
|
||||
notification3 = Fabricate(:notification, user: user, notification_type: Notification.types[:private_message])
|
||||
notification4 = Fabricate(:notification, user: user, notification_type: Notification.types[:bookmark_reminder])
|
||||
|
||||
message = MessageBus.track_publish("/notification/#{user.id}") do
|
||||
user.publish_notifications_state
|
||||
end.first
|
||||
|
||||
expect(message.data[:recent]).to eq([
|
||||
[notification4.id, false], [notification3.id, false],
|
||||
[notification2.id, true], [notification.id, false]
|
||||
])
|
||||
end
|
||||
|
||||
it "has the correct counts" do
|
||||
notification = Fabricate(:notification, user: user)
|
||||
notification2 = Fabricate(:notification, user: user, read: true)
|
||||
notification3 = Fabricate(:notification, user: user, notification_type: Notification.types[:private_message])
|
||||
notification4 = Fabricate(:notification, user: user, notification_type: Notification.types[:bookmark_reminder])
|
||||
|
||||
message = MessageBus.track_publish("/notification/#{user.id}") do
|
||||
user.publish_notifications_state
|
||||
end.first
|
||||
|
||||
expect(message.data[:unread_notifications]).to eq(1)
|
||||
# NOTE: because of deprecation this will be equal to unread_high_priority_notifications,
|
||||
# to be remonved in 2.5
|
||||
expect(message.data[:unread_private_messages]).to eq(2)
|
||||
expect(message.data[:unread_high_priority_notifications]).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1821,6 +1854,7 @@ describe User do
|
||||
end
|
||||
|
||||
describe "#unread_notifications" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
before do
|
||||
User.max_unread_notifications = 3
|
||||
end
|
||||
@ -1830,14 +1864,32 @@ describe User do
|
||||
end
|
||||
|
||||
it "limits to MAX_UNREAD_NOTIFICATIONS" do
|
||||
user = Fabricate(:user)
|
||||
|
||||
4.times do
|
||||
Notification.create!(user_id: user.id, notification_type: 1, read: false, data: '{}')
|
||||
end
|
||||
|
||||
expect(user.unread_notifications).to eq(3)
|
||||
end
|
||||
|
||||
it "does not include high priority notifications" do
|
||||
Notification.create!(user_id: user.id, notification_type: 1, read: false, data: '{}')
|
||||
Notification.create!(user_id: user.id, notification_type: Notification.types[:private_message], read: false, data: '{}')
|
||||
Notification.create!(user_id: user.id, notification_type: Notification.types[:bookmark_reminder], read: false, data: '{}')
|
||||
|
||||
expect(user.unread_notifications).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#unread_high_priority_notifications" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
it "only returns an unread count of PM and bookmark reminder notifications" do
|
||||
Notification.create!(user_id: user.id, notification_type: 1, read: false, data: '{}')
|
||||
Notification.create!(user_id: user.id, notification_type: Notification.types[:private_message], read: false, data: '{}')
|
||||
Notification.create!(user_id: user.id, notification_type: Notification.types[:bookmark_reminder], read: false, data: '{}')
|
||||
|
||||
expect(user.unread_high_priority_notifications).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#unstage!" do
|
||||
|
Reference in New Issue
Block a user