This reverts commit d78fed7dc6
.
Causing some issues with clearing unreads.
This commit is contained in:
parent
22bccef8f4
commit
931eedeb66
|
@ -425,6 +425,7 @@ export default class ChatLivePane extends Component {
|
||||||
@action
|
@action
|
||||||
didShowMessage(message) {
|
didShowMessage(message) {
|
||||||
message.visible = true;
|
message.visible = true;
|
||||||
|
this.updateLastReadMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
@ -440,34 +441,13 @@ export default class ChatLivePane extends Component {
|
||||||
|
|
||||||
const lastReadId =
|
const lastReadId =
|
||||||
this.args.channel.currentUserMembership?.last_read_message_id;
|
this.args.channel.currentUserMembership?.last_read_message_id;
|
||||||
let lastUnreadVisibleMessage = this.args.channel.visibleMessages.findLast(
|
const lastUnreadVisibleMessage = this.args.channel.visibleMessages.findLast(
|
||||||
(message) => !lastReadId || message.id > lastReadId
|
(message) => !lastReadId || message.id > lastReadId
|
||||||
);
|
);
|
||||||
|
if (lastUnreadVisibleMessage) {
|
||||||
// all intersecting messages are read
|
|
||||||
if (!lastUnreadVisibleMessage) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const element = this._scrollerEl.querySelector(
|
|
||||||
`[data-id='${lastUnreadVisibleMessage.id}']`
|
|
||||||
);
|
|
||||||
|
|
||||||
// if the last visible message is not fully visible, we don't want to mark it as read
|
|
||||||
// attempt to mark previous one as read
|
|
||||||
if (!this.#isBottomOfMessageVisible(element, this._scrollerEl)) {
|
|
||||||
lastUnreadVisibleMessage = lastUnreadVisibleMessage.previousMessage;
|
|
||||||
|
|
||||||
if (
|
|
||||||
!lastUnreadVisibleMessage &&
|
|
||||||
lastReadId > lastUnreadVisibleMessage.id
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.args.channel.updateLastReadMessage(lastUnreadVisibleMessage.id);
|
this.args.channel.updateLastReadMessage(lastUnreadVisibleMessage.id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
scrollToBottom() {
|
scrollToBottom() {
|
||||||
|
@ -522,8 +502,6 @@ export default class ChatLivePane extends Component {
|
||||||
if (this.isAtBottom) {
|
if (this.isAtBottom) {
|
||||||
this.hasNewMessages = false;
|
this.hasNewMessages = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateLastReadMessage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_isBetween(target, a, b) {
|
_isBetween(target, a, b) {
|
||||||
|
@ -1289,10 +1267,4 @@ export default class ChatLivePane extends Component {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#isBottomOfMessageVisible(element, container) {
|
|
||||||
const rect = element.getBoundingClientRect();
|
|
||||||
const containerRect = container.getBoundingClientRect();
|
|
||||||
return rect.bottom <= containerRect.bottom;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ export default class ChatTrackMessage extends Modifier {
|
||||||
this._intersectionObserverCallback,
|
this._intersectionObserverCallback,
|
||||||
{
|
{
|
||||||
root: document,
|
root: document,
|
||||||
threshold: 0,
|
threshold: 0.9,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
RSpec.describe "Mark message as read", type: :system, js: true do
|
|
||||||
fab!(:current_user) { Fabricate(:user) }
|
|
||||||
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
||||||
|
|
||||||
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
||||||
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
|
|
||||||
let(:membership) { Chat::ChatChannelMembershipManager.new(channel_1).find_for_user(current_user) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
chat_system_bootstrap
|
|
||||||
channel_1.add(current_user)
|
|
||||||
membership.update!(last_read_message_id: first_unread.id)
|
|
||||||
25.times { |i| Fabricate(:chat_message, chat_channel: channel_1) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the full message is not visible" do
|
|
||||||
fab!(:first_unread) { Fabricate(:chat_message, chat_channel: channel_1) }
|
|
||||||
|
|
||||||
it "doesn’t mark it as read" do
|
|
||||||
sign_in(current_user)
|
|
||||||
before_last_message = Fabricate(:chat_message, chat_channel: channel_1)
|
|
||||||
last_message = Fabricate(:chat_message, chat_channel: channel_1)
|
|
||||||
chat_page.visit_channel(channel_1)
|
|
||||||
|
|
||||||
page.execute_script("document.querySelector('.chat-messages-scroll').scrollTo(0, -5)")
|
|
||||||
|
|
||||||
try_until_success(timeout: 5) do
|
|
||||||
membership.reload.last_read_message_id = before_last_message.id
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the full message is visible" do
|
|
||||||
fab!(:first_unread) { Fabricate(:chat_message, chat_channel: channel_1) }
|
|
||||||
|
|
||||||
it "marks it as read" do
|
|
||||||
sign_in(current_user)
|
|
||||||
last_message = Fabricate(:chat_message, chat_channel: channel_1)
|
|
||||||
chat_page.visit_channel(channel_1)
|
|
||||||
|
|
||||||
page.execute_script("document.querySelector('.chat-messages-scroll').scrollTo(0, 0)")
|
|
||||||
|
|
||||||
try_until_success(timeout: 5) { membership.reload.last_read_message_id = last_message.id }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue