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:
parent
58c8f91d9a
commit
58c14ba0f9
|
@ -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
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue