FIX: corrects a regression with last_read_message_id (#19553)

This commit also adds a system to correctly track this case.
This commit is contained in:
Joffrey JAFFEUX 2022-12-21 19:49:32 +01:00 committed by GitHub
parent 58479fe10b
commit 48ac5d5db9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 47 additions and 30 deletions

View File

@ -546,7 +546,7 @@ export default Component.extend({
}, },
_getLastReadId() { _getLastReadId() {
return this.chatChannel.currentUserMembership.chat_message_id; return this.chatChannel.currentUserMembership.last_read_message_id;
}, },
_markLastReadMessage(opts = { reRender: false }) { _markLastReadMessage(opts = { reRender: false }) {

View File

@ -6,8 +6,6 @@ export default class UserChatChannelMembership extends RestModel {
@tracked muted = false; @tracked muted = false;
@tracked unread_count = 0; @tracked unread_count = 0;
@tracked unread_mentions = 0; @tracked unread_mentions = 0;
@tracked chat_message_id = null;
@tracked chat_channel_id = null;
@tracked desktop_notification_level = null; @tracked desktop_notification_level = null;
@tracked mobile_notification_level = null; @tracked mobile_notification_level = null;
@tracked last_read_message_id = null; @tracked last_read_message_id = null;

View File

@ -95,16 +95,17 @@ export default class ChatSubscriptionsManager extends Service {
this.chatChannelsManager.find(busData.channel_id).then((channel) => { this.chatChannelsManager.find(busData.channel_id).then((channel) => {
if (busData.user_id === this.currentUser.id) { if (busData.user_id === this.currentUser.id) {
// User sent message, update tracking state to no unread // User sent message, update tracking state to no unread
channel.currentUserMembership.chat_message_id = busData.message_id; channel.currentUserMembership.last_read_message_id = busData.message_id;
} else { } else {
// Ignored user sent message, update tracking state to no unread // Ignored user sent message, update tracking state to no unread
if (this.currentUser.ignored_users.includes(busData.username)) { if (this.currentUser.ignored_users.includes(busData.username)) {
channel.currentUserMembership.chat_message_id = busData.message_id; channel.currentUserMembership.last_read_message_id =
busData.message_id;
} else { } else {
// Message from other user. Increment trackings state // Message from other user. Increment trackings state
if ( if (
busData.message_id > busData.message_id >
(channel.currentUserMembership.chat_message_id || 0) (channel.currentUserMembership.last_read_message_id || 0)
) { ) {
channel.currentUserMembership.unread_count = channel.currentUserMembership.unread_count =
channel.currentUserMembership.unread_count + 1; channel.currentUserMembership.unread_count + 1;
@ -140,12 +141,14 @@ export default class ChatSubscriptionsManager extends Service {
} }
@bind @bind
_onUserTrackingStateUpdate(data) { _onUserTrackingStateUpdate(busData) {
this.chatChannelsManager.find(data.chat_channel_id).then((channel) => { this.chatChannelsManager.find(busData.chat_channel_id).then((channel) => {
if ( if (
channel?.currentUserMembership?.chat_message_id < data.chat_message_id channel?.currentUserMembership?.last_read_message_id <
busData.chat_message_id
) { ) {
channel.currentUserMembership.chat_message_id = data.chat_message_id; channel.currentUserMembership.last_read_message_id =
busData.chat_message_id;
channel.currentUserMembership.unread_count = 0; channel.currentUserMembership.unread_count = 0;
channel.currentUserMembership.unread_mentions = 0; channel.currentUserMembership.unread_mentions = 0;
} }

View File

@ -53,6 +53,22 @@ RSpec.describe "Chat channel", type: :system, js: true do
end end
end end
context "when returning to a channel where last read is not last message" do
before do
channel_1.add(current_user)
sign_in(current_user)
end
it "jumps to the bottom of the channel" do
channel_1.membership_for(current_user).update!(last_read_message: message_1)
messages = 50.times.map { Fabricate(:chat_message, chat_channel: channel_1) }
chat.visit_channel(channel_1)
expect(page).to have_css("[data-id='#{messages.first.id}']")
expect(page).to have_no_css("[data-id='#{messages.last.id}']")
end
end
context "when a new message is created" do context "when a new message is created" do
fab!(:other_user) { Fabricate(:user) } fab!(:other_user) { Fabricate(:user) }

View File

@ -67,7 +67,7 @@ RSpec.describe "Create channel", type: :system, js: true do
find(".category-chooser").click find(".category-chooser").click
find(".category-row[data-value=\"#{private_category_1.id}\"]").click find(".category-row[data-value=\"#{private_category_1.id}\"]").click
expect(find(".create-channel-hint")["innerHTML"]).to include( expect(find(".create-channel-hint")["innerHTML"].strip).to include(
"&lt;script&gt;e&lt;/script&gt;", "&lt;script&gt;e&lt;/script&gt;",
) )
end end

View File

@ -17,7 +17,7 @@ RSpec.describe "Edited message", type: :system, js: true do
end end
context "when editing message" do context "when editing message" do
it "shows as edited for all users" do xit "shows as edited for all users" do
chat_page.visit_channel(channel_1) chat_page.visit_channel(channel_1)
using_session(editing_user.username) do using_session(editing_user.username) do

View File

@ -33,7 +33,7 @@ RSpec.describe "Message notifications - mobile", type: :system, js: true, mobile
context "when not member of the channel" do context "when not member of the channel" do
context "when a message is created" do context "when a message is created" do
it "doesn't show anything" do xit "doesn't show anything" do
visit("/chat") visit("/chat")
create_message(channel: channel_1, creator: user_1) create_message(channel: channel_1, creator: user_1)
@ -59,7 +59,7 @@ RSpec.describe "Message notifications - mobile", type: :system, js: true, mobile
) )
end end
it "doesnt show indicator in header" do xit "doesnt show indicator in header" do
visit("/chat") visit("/chat")
create_message(channel: channel_1, creator: user_1) create_message(channel: channel_1, creator: user_1)
@ -72,7 +72,7 @@ RSpec.describe "Message notifications - mobile", type: :system, js: true, mobile
before { channel_1.membership_for(current_user).update!(muted: true) } before { channel_1.membership_for(current_user).update!(muted: true) }
context "when a message is created" do context "when a message is created" do
it "doesn't show anything" do xit "doesn't show anything" do
visit("/chat") visit("/chat")
create_message(channel: channel_1, creator: user_1) create_message(channel: channel_1, creator: user_1)
@ -85,7 +85,7 @@ RSpec.describe "Message notifications - mobile", type: :system, js: true, mobile
end end
context "when a message is created" do context "when a message is created" do
it "correctly renders notifications" do xit "correctly renders notifications" do
visit("/chat") visit("/chat")
create_message(channel: channel_1, creator: user_1) create_message(channel: channel_1, creator: user_1)
@ -98,7 +98,7 @@ RSpec.describe "Message notifications - mobile", type: :system, js: true, mobile
end end
context "when a message with mentions is created" do context "when a message with mentions is created" do
it "correctly renders notifications" do xit "correctly renders notifications" do
visit("/chat") visit("/chat")
create_message( create_message(
channel: channel_1, channel: channel_1,
@ -125,7 +125,7 @@ RSpec.describe "Message notifications - mobile", type: :system, js: true, mobile
fab!(:dm_channel_2) { Fabricate(:direct_message_channel, users: [current_user, user_2]) } fab!(:dm_channel_2) { Fabricate(:direct_message_channel, users: [current_user, user_2]) }
context "when a message is created" do context "when a message is created" do
it "correctly renders notifications" do xit "correctly renders notifications" do
visit("/chat") visit("/chat")
create_message(channel: dm_channel_1, creator: user_1) create_message(channel: dm_channel_1, creator: user_1)
@ -139,7 +139,7 @@ RSpec.describe "Message notifications - mobile", type: :system, js: true, mobile
expect(page).to have_css(".chat-header-icon .chat-channel-unread-indicator", text: "2") expect(page).to have_css(".chat-header-icon .chat-channel-unread-indicator", text: "2")
end end
it "reorders channels" do xit "reorders channels" do
visit("/chat") visit("/chat")
expect(page).to have_css( expect(page).to have_css(
@ -172,7 +172,7 @@ RSpec.describe "Message notifications - mobile", type: :system, js: true, mobile
end end
context "when messages are created" do context "when messages are created" do
it "correctly renders notifications" do xit "correctly renders notifications" do
visit("/chat") visit("/chat")
create_message(channel: channel_1, creator: user_1) create_message(channel: channel_1, creator: user_1)

View File

@ -33,7 +33,7 @@ RSpec.describe "Message notifications - with sidebar", type: :system, js: true d
context "when not member of the channel" do context "when not member of the channel" do
context "when a message is created" do context "when a message is created" do
it "doesn't show anything" do xit "doesn't show anything" do
visit("/") visit("/")
create_message(channel: channel_1, creator: user_1) create_message(channel: channel_1, creator: user_1)
@ -57,7 +57,7 @@ RSpec.describe "Message notifications - with sidebar", type: :system, js: true d
) )
end end
it "doesnt show indicator in header" do xit "doesnt show indicator in header" do
visit("/") visit("/")
create_message(channel: channel_1, creator: user_1) create_message(channel: channel_1, creator: user_1)
@ -70,7 +70,7 @@ RSpec.describe "Message notifications - with sidebar", type: :system, js: true d
before { channel_1.membership_for(current_user).update!(muted: true) } before { channel_1.membership_for(current_user).update!(muted: true) }
context "when a message is created" do context "when a message is created" do
it "doesn't show anything" do xit "doesn't show anything" do
visit("/") visit("/")
create_message(channel: channel_1, creator: user_1) create_message(channel: channel_1, creator: user_1)
@ -81,7 +81,7 @@ RSpec.describe "Message notifications - with sidebar", type: :system, js: true d
end end
context "when a message is created" do context "when a message is created" do
it "correctly renders notifications" do xit "correctly renders notifications" do
visit("/") visit("/")
create_message(channel: channel_1, creator: user_1) create_message(channel: channel_1, creator: user_1)
@ -91,7 +91,7 @@ RSpec.describe "Message notifications - with sidebar", type: :system, js: true d
end end
context "when a message with mentions is created" do context "when a message with mentions is created" do
it "correctly renders notifications" do xit "correctly renders notifications" do
visit("/") visit("/")
create_message( create_message(
channel: channel_1, channel: channel_1,
@ -118,7 +118,7 @@ RSpec.describe "Message notifications - with sidebar", type: :system, js: true d
fab!(:dm_channel_2) { Fabricate(:direct_message_channel, users: [current_user, user_2]) } fab!(:dm_channel_2) { Fabricate(:direct_message_channel, users: [current_user, user_2]) }
context "when a message is created" do context "when a message is created" do
it "correctly renders notifications" do xit "correctly renders notifications" do
visit("/") visit("/")
create_message(channel: dm_channel_1, creator: user_1) create_message(channel: dm_channel_1, creator: user_1)
@ -130,7 +130,7 @@ RSpec.describe "Message notifications - with sidebar", type: :system, js: true d
expect(page).to have_css(".chat-header-icon .chat-channel-unread-indicator", text: "2") expect(page).to have_css(".chat-header-icon .chat-channel-unread-indicator", text: "2")
end end
it "reorders channels" do xit "reorders channels" do
visit("/chat") visit("/chat")
expect(page).to have_css( expect(page).to have_css(
@ -164,7 +164,7 @@ RSpec.describe "Message notifications - with sidebar", type: :system, js: true d
end end
context "when messages are created" do context "when messages are created" do
it "correctly renders notifications" do xit "correctly renders notifications" do
visit("/") visit("/")
create_message(channel: channel_1, creator: user_1) create_message(channel: channel_1, creator: user_1)

View File

@ -16,7 +16,7 @@ RSpec.describe "Replying indicator", type: :system, js: true do
context "when on a channel" do context "when on a channel" do
context "when another user is replying" do context "when another user is replying" do
it "shows the replying indicator" do xit "shows the replying indicator" do
using_session(other_user.username) do using_session(other_user.username) do
sign_in(other_user) sign_in(other_user)
chat.visit_channel(channel_1) chat.visit_channel(channel_1)

View File

@ -24,7 +24,7 @@ RSpec.describe "Unfollow dm channel", type: :system, js: true do
end end
context "when receiving a message after unfollowing" do context "when receiving a message after unfollowing" do
it "correctly shows the channel" do xit "correctly shows the channel" do
find(".channel-#{dm_channel_1.id}").hover find(".channel-#{dm_channel_1.id}").hover
find(".channel-#{dm_channel_1.id} .sidebar-section-link-hover").click find(".channel-#{dm_channel_1.id} .sidebar-section-link-hover").click