FEATURE: Track last_viewed_at datetime for channel members (#22294)

Whenever a user opens a channel or marks it read, we now
update the last_viewed_at datetime for that channel membership
record. This is so we will be able to show thread unread indicators
in the channel sidebar that clear independently of the main thread
unread indicators. This unread functionality will follow in another
PR.
This commit is contained in:
Martin Brennan
2023-06-29 09:22:17 +10:00
committed by GitHub
parent 58c14ba0f9
commit 1194ed10e1
6 changed files with 40 additions and 4 deletions
@@ -37,6 +37,8 @@ RSpec.describe Chat::ChannelViewBuilder do
}
end
before { channel.add(current_user) }
it "threads_enabled is false by default" do
expect(result.threads_enabled).to eq(false)
end
@@ -76,6 +78,14 @@ RSpec.describe Chat::ChannelViewBuilder do
)
end
it "updates the channel membership last_viewed_at" do
membership = channel.membership_for(current_user)
membership.update!(last_viewed_at: 1.day.ago)
old_last_viewed_at = membership.last_viewed_at
result
expect(membership.reload.last_viewed_at).not_to eq_time(old_last_viewed_at)
end
it "does not query thread tracking overview or state by default" do
Chat::TrackingStateReportQuery.expects(:call).never
result
@@ -109,6 +109,13 @@ RSpec.describe Chat::UpdateUserLastRead do
it "publishes new last read to clients" do
expect(messages.map(&:channel)).to include("/chat/user-tracking-state/#{current_user.id}")
end
it "updates the channel membership last_viewed_at datetime" do
membership.update!(last_viewed_at: 1.day.ago)
old_last_viewed_at = membership.last_viewed_at
result
expect(membership.reload.last_viewed_at).not_to eq_time(old_last_viewed_at)
end
end
end
end