DEV: Remove AJAX usage in chat-channel model (#22320)

Addressing TODO about using chatApi in the ChatChannel model,
but since it's a model we cannot easily use the chatApi service.
The model function is only called in one place so we may as well
just move the call there since the component can use chatApi
This commit is contained in:
Martin Brennan 2023-06-29 09:21:28 +10:00 committed by GitHub
parent 58c8f91d9a
commit 58c14ba0f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 18 deletions

View File

@ -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
);
});
}

View File

@ -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));
}