2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

FEATURE: Publish read state on group messages. (#7989)

* Enable or disable read state based on group attribute

* When read state needs to be published, the minimum unread count is calculated in the topic query. This way, we can know if someone reads the last post

* The option can be enabled/disabled from the UI

* The read indicator will live-updated using message bus

* Show read indicator on every post

* The read indicator now shows read count and can be expanded to see user avatars

* Read count gets updated everytime someone reads a message

* Simplify topic-list read indicator logic

* Unsubscribe from message bus on willDestroyElement, removed unnecesarry values from post-menu, and added a comment to explain where does minimum_unread_count comes from
This commit is contained in:
Roman Rizzi 2019-08-20 09:46:57 -03:00 committed by GitHub
parent 15e70cc4b4
commit 1630dae2db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 524 additions and 21 deletions

View file

@ -1020,6 +1020,49 @@ describe TopicQuery do
expect(topics).to eq([])
end
context "Calculating minimum unread count for a topic" do
before { group.update!(publish_read_state: true) }
let(:listed_message) do
TopicQuery.new(nil, group_name: group.name)
.list_private_messages_group(creator)
.topics.first
end
it 'returns a positive number when noone has read the last message' do
group_message.update!(highest_post_number: 1)
TopicUser.create!(user: creator, topic: group_message)
expect(listed_message.minimum_unread_count).to eq(1)
end
it 'returns 0 when all posts were read' do
group_message.update!(highest_post_number: 1)
TopicUser.create!(user: creator, topic: group_message, highest_seen_post_number: 1)
expect(listed_message.minimum_unread_count).to eq(0)
end
it 'returns the minimum number of unread posts when there are more than one user' do
new_user = Fabricate(:user)
group.add(new_user)
group_message.update!(highest_post_number: 3)
TopicUser.create!(user: creator, topic: group_message, highest_seen_post_number: 1)
TopicUser.create!(user: new_user, topic: group_message, highest_seen_post_number: 2)
expect(listed_message.minimum_unread_count).to eq(1)
end
it 'returns the minimum number of unread posts when there are more than one user' do
new_user = Fabricate(:topic_allowed_user, topic: group_message).user
group_message.update!(highest_post_number: 3)
TopicUser.create!(user: creator, topic: group_message, highest_seen_post_number: 1)
TopicUser.create!(user: new_user, topic: group_message, highest_seen_post_number: 2)
expect(listed_message.minimum_unread_count).to eq(2)
end
end
end
context "shared drafts" do