FEATURE: Display new/unread count in browse more messages for PMs. (#14188)

In order to include the new/unread count in the browse more message
under suggested topics, a couple of technical changes have to be made.

1. `PrivateMessageTopicTrackingState` is now auto-injected which is
   similar to how it is done for `TopicTrackingState`. This is done so
we don't have to attempt to pass the `PrivateMessageTopicTrackingState`
object multiple levels down into the suggested-topics component. While
the object is auto-injected, we only fetch the initial state and start
tracking when the relevant private messages routes has been hit and only
when a private message's suggested topics is loaded. This is
done as we do not want to add the extra overhead of fetching the inital
state to all page loads but instead wait till the private messages
routes are hit.

2. Previously, we would stop tracking once the `user-private-messages`
   route has been deactivated. However, that is not ideal since
navigating out of the route and back means we send an API call to the
server each time. Since `PrivateMessageTopicTrackingState` is kept in
sync cheaply via messageBus, we can just continue to track the state
even if the user has navigated away from the relevant stages.
This commit is contained in:
Alan Guo Xiang Tan
2021-09-07 12:30:40 +08:00
committed by GitHub
parent cb63c297b3
commit fc1fd1b416
15 changed files with 423 additions and 134 deletions

View File

@@ -135,7 +135,9 @@ RSpec.describe CurrentUserSerializer do
public_group.save!
payload = serializer.as_json
expect(payload[:groups]).to eq([{ id: public_group.id, name: public_group.name }])
expect(payload[:groups]).to contain_exactly(
{ id: public_group.id, name: public_group.name, has_messages: false }
)
end
end

View File

@@ -151,6 +151,34 @@ describe TopicViewSerializer do
end
end
describe '#suggested_group_name' do
fab!(:pm) { Fabricate(:private_message_post).topic }
fab!(:group) { Fabricate(:group) }
it 'is nil for a regular topic' do
json = serialize_topic(topic, user)
expect(json[:suggested_group_name]).to eq(nil)
end
it 'is nil if user is an allowed user of the private message' do
pm.allowed_users << user
json = serialize_topic(pm, user)
expect(json[:suggested_group_name]).to eq(nil)
end
it 'returns the right group name if user is part of allowed group in the private message' do
pm.allowed_groups << group
group.add(user)
json = serialize_topic(pm, user)
expect(json[:suggested_group_name]).to eq(group.name)
end
end
describe 'when tags added to private message topics' do
fab!(:moderator) { Fabricate(:moderator) }
fab!(:tag) { Fabricate(:tag) }