mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06: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:
@@ -117,6 +117,24 @@ describe Notification do
|
||||
it "increases unread_private_messages" do
|
||||
expect { Fabricate(:private_message_notification, user: user); user.reload }.to change(user, :unread_private_messages)
|
||||
end
|
||||
|
||||
it "increases unread_high_priority_notifications" do
|
||||
expect { Fabricate(:private_message_notification, user: user); user.reload }.to change(user, :unread_high_priority_notifications)
|
||||
end
|
||||
end
|
||||
|
||||
context 'a bookmark reminder message' do
|
||||
it "doesn't increase unread_notifications" do
|
||||
expect { Fabricate(:bookmark_reminder_notification, user: user); user.reload }.not_to change(user, :unread_notifications)
|
||||
end
|
||||
|
||||
it 'increases total_unread_notifications' do
|
||||
expect { Fabricate(:notification, user: user); user.reload }.to change(user, :total_unread_notifications)
|
||||
end
|
||||
|
||||
it "increases unread_high_priority_notifications" do
|
||||
expect { Fabricate(:bookmark_reminder_notification, user: user); user.reload }.to change(user, :unread_high_priority_notifications)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -219,6 +237,13 @@ describe Notification do
|
||||
data: '{}',
|
||||
notification_type: Notification.types[:private_message])
|
||||
|
||||
Notification.create!(read: false,
|
||||
user_id: user.id,
|
||||
topic_id: t.id,
|
||||
post_number: 1,
|
||||
data: '{}',
|
||||
notification_type: Notification.types[:bookmark_reminder])
|
||||
|
||||
other = Notification.create!(read: false,
|
||||
user_id: user.id,
|
||||
topic_id: t.id,
|
||||
@@ -230,8 +255,11 @@ describe Notification do
|
||||
user.reload
|
||||
|
||||
expect(user.unread_notifications).to eq(0)
|
||||
expect(user.total_unread_notifications).to eq(2)
|
||||
expect(user.unread_private_messages).to eq(1)
|
||||
expect(user.total_unread_notifications).to eq(3)
|
||||
# NOTE: because of deprecation this will be equal to unread_high_priority_notifications,
|
||||
# to be remonved in 2.5
|
||||
expect(user.unread_private_messages).to eq(2)
|
||||
expect(user.unread_high_priority_notifications).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -248,7 +276,7 @@ describe Notification do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'ensure consistency' do
|
||||
describe '#ensure_consistency!' do
|
||||
it 'deletes notifications if post is missing or deleted' do
|
||||
|
||||
NotificationEmailer.disable
|
||||
@@ -260,6 +288,8 @@ describe Notification do
|
||||
notification_type: Notification.types[:private_message])
|
||||
Notification.create!(read: false, user_id: p2.user_id, topic_id: p2.topic_id, post_number: p2.post_number, data: '[]',
|
||||
notification_type: Notification.types[:private_message])
|
||||
Notification.create!(read: false, user_id: p2.user_id, topic_id: p2.topic_id, post_number: p2.post_number, data: '[]',
|
||||
notification_type: Notification.types[:bookmark_reminder])
|
||||
|
||||
Notification.create!(read: false, user_id: p2.user_id, topic_id: p2.topic_id, post_number: p2.post_number, data: '[]',
|
||||
notification_type: Notification.types[:liked])
|
||||
@@ -321,6 +351,10 @@ describe Notification do
|
||||
fab(Notification.types[:private_message], false)
|
||||
end
|
||||
|
||||
def unread_bookmark_reminder
|
||||
fab(Notification.types[:bookmark_reminder], false)
|
||||
end
|
||||
|
||||
def pm
|
||||
fab(Notification.types[:private_message], true)
|
||||
end
|
||||
@@ -340,16 +374,17 @@ describe Notification do
|
||||
expect(Notification.visible.count).to eq(0)
|
||||
end
|
||||
|
||||
it 'orders stuff correctly' do
|
||||
it 'orders stuff by creation descending, bumping unread high priority (pms, bookmark reminders) to top' do
|
||||
# note we expect the final order to read bottom-up for this list of variables,
|
||||
# with unread pm + bookmark reminder at the top of that list
|
||||
a = unread_pm
|
||||
regular
|
||||
regular
|
||||
b = unread_bookmark_reminder
|
||||
c = pm
|
||||
d = regular
|
||||
|
||||
# bumps unread pms to front of list
|
||||
|
||||
notifications = Notification.recent_report(user, 3)
|
||||
expect(notifications.map { |n| n.id }).to eq([a.id, d.id, c.id])
|
||||
notifications = Notification.recent_report(user, 4)
|
||||
expect(notifications.map { |n| n.id }).to eq([b.id, a.id, d.id, c.id])
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -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