diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.js b/plugins/chat/assets/javascripts/discourse/components/chat-channel.js index 63c0f19a634..f1b01248f12 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.js @@ -560,7 +560,21 @@ export default class ChatLivePane extends Component { } } - this.args.channel.updateLastReadMessage(lastUnreadVisibleMessage.id); + if (!this.args.channel.isFollowing || !lastUnreadVisibleMessage.id) { + return; + } + + if ( + this.args.channel.currentUserMembership.lastReadMessageId >= + lastUnreadVisibleMessage.id + ) { + return; + } + + return this.chatApi.markChannelAsRead( + this.args.channel.id, + lastUnreadVisibleMessage.id + ); }); } diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js b/plugins/chat/assets/javascripts/discourse/models/chat-channel.js index df8db7fa335..0bd1d1f825f 100644 --- a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js +++ b/plugins/chat/assets/javascripts/discourse/models/chat-channel.js @@ -1,6 +1,5 @@ import UserChatChannelMembership from "discourse/plugins/chat/discourse/models/user-chat-channel-membership"; import { TrackedSet } from "@ember-compat/tracked-built-ins"; -import { ajax } from "discourse/lib/ajax"; import { escapeExpression } from "discourse/lib/utilities"; import { tracked } from "@glimmer/tracking"; import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel"; @@ -325,22 +324,6 @@ export default class ChatChannel { this.currentUserMembership.muted = membership.muted; } - updateLastReadMessage(messageId) { - if (!this.isFollowing || !messageId) { - return; - } - - if (this.currentUserMembership.lastReadMessageId >= messageId) { - return; - } - - // TODO (martin) Change this to use chatApi service markChannelAsRead once we change this - // class not to use RestModel. - return ajax(`/chat/api/channels/${this.id}/read/${messageId}`, { - method: "PUT", - }); - } - clearSelectedMessages() { this.selectedMessages.forEach((message) => (message.selected = false)); }