Stop showing first notification prompt once user sees the notification.
This commit is contained in:
parent
6431b03d66
commit
8c6d8c85db
|
@ -56,7 +56,6 @@ class Notification < ActiveRecord::Base
|
||||||
.update_all("read = 't'")
|
.update_all("read = 't'")
|
||||||
|
|
||||||
if count > 0
|
if count > 0
|
||||||
user.mark_first_notification_read
|
|
||||||
user.publish_notifications_state
|
user.publish_notifications_state
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -69,7 +68,6 @@ class Notification < ActiveRecord::Base
|
||||||
read: false).update_all(read: true)
|
read: false).update_all(read: true)
|
||||||
|
|
||||||
if count > 0
|
if count > 0
|
||||||
user.mark_first_notification_read
|
|
||||||
user.publish_notifications_state
|
user.publish_notifications_state
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -345,22 +345,6 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
TRACK_FIRST_NOTIFICATION_READ_DURATION = 1.week.to_i
|
TRACK_FIRST_NOTIFICATION_READ_DURATION = 1.week.to_i
|
||||||
|
|
||||||
def self.first_notification_read_key(user)
|
|
||||||
"#{user.id}:first-notification-read"
|
|
||||||
end
|
|
||||||
|
|
||||||
def mark_first_notification_read
|
|
||||||
first_notification_read_key = User.first_notification_read_key(self)
|
|
||||||
|
|
||||||
if !$redis.get(first_notification_read_key)
|
|
||||||
$redis.setex(
|
|
||||||
first_notification_read_key,
|
|
||||||
User::TRACK_FIRST_NOTIFICATION_READ_DURATION,
|
|
||||||
1
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def read_first_notification?
|
def read_first_notification?
|
||||||
if (trust_level > TrustLevel[0] ||
|
if (trust_level > TrustLevel[0] ||
|
||||||
created_at < TRACK_FIRST_NOTIFICATION_READ_DURATION.seconds.ago)
|
created_at < TRACK_FIRST_NOTIFICATION_READ_DURATION.seconds.ago)
|
||||||
|
@ -368,7 +352,7 @@ class User < ActiveRecord::Base
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
!!$redis.get(self.class.first_notification_read_key(self))
|
self.seen_notification_id == 0 ? false : true
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish_notifications_state
|
def publish_notifications_state
|
||||||
|
|
|
@ -1319,49 +1319,21 @@ describe User do
|
||||||
|
|
||||||
describe '#read_first_notification?' do
|
describe '#read_first_notification?' do
|
||||||
let(:user) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
let(:user) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||||
let(:post) { Fabricate(:post) }
|
let(:notification) { Fabricate(:private_message_notification) }
|
||||||
let(:topic) { Fabricate(:topic, first_post: post) }
|
|
||||||
|
|
||||||
let(:notification) do
|
describe 'when first notification has not been seen' do
|
||||||
Fabricate(:private_message_notification,
|
|
||||||
user: user, read: false, topic: topic, post_number: post.post_number
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
after do
|
|
||||||
$redis.del(User.first_notification_read_key(user))
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'when first notification has not been read' do
|
|
||||||
it 'should return the right value' do
|
it 'should return the right value' do
|
||||||
expect(user.read_first_notification?).to eq(false)
|
expect(user.read_first_notification?).to eq(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when first notification has been read' do
|
describe 'when first notification has been seen' do
|
||||||
it 'should return the right value' do
|
it 'should return the right value' do
|
||||||
notification
|
user.update_attributes!(seen_notification_id: notification.id)
|
||||||
Notification.read(user, [notification.id])
|
|
||||||
|
|
||||||
expect(user.reload.read_first_notification?).to eq(true)
|
expect(user.reload.read_first_notification?).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when post has been read' do
|
|
||||||
it 'should return the right value' do
|
|
||||||
notification
|
|
||||||
Notification.mark_posts_read(user, notification.topic_id, [1])
|
|
||||||
|
|
||||||
expect(user.read_first_notification?).to eq(true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'when user does not have any notifications' do
|
|
||||||
it 'should return the right value' do
|
|
||||||
expect(user.read_first_notification?).to eq(false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'when user is not trust level 0' do
|
describe 'when user is not trust level 0' do
|
||||||
it 'should return the right value' do
|
it 'should return the right value' do
|
||||||
user.update_attributes!(trust_level: TrustLevel[1])
|
user.update_attributes!(trust_level: TrustLevel[1])
|
||||||
|
|
Loading…
Reference in New Issue