mirror of
https://github.com/discourse/discourse.git
synced 2025-02-12 04:14:00 +08:00
![Joffrey JAFFEUX](/assets/img/avatar_default.png)
Recent changes surfaced the various issues with this codepath: - we were not correctly reseting `messageLookup` leading to us trying to scroll to a non existing message in the view - we were calling markAsRead which would scroll to the bottom, even if we had a target message - we were not debouncing fetchMessages, which could cause multiple reload of the messages when loading it with a targetMessageId: first fetch from last read and then immediately fetch from targetMessageId - other naming inconsistencies - not handling drawer This commit also adds tests for classic scenarios related to this use case.
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import DiscourseRoute from "discourse/routes/discourse";
|
|
import { inject as service } from "@ember/service";
|
|
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
|
import { action } from "@ember/object";
|
|
import { schedule } from "@ember/runloop";
|
|
|
|
export default class ChatChannelRoute extends DiscourseRoute {
|
|
@service chat;
|
|
@service router;
|
|
@service chatChannelsManager;
|
|
|
|
async model(params) {
|
|
return this.chatChannelsManager.find(params.channelId);
|
|
}
|
|
|
|
afterModel(model) {
|
|
this.chat.setActiveChannel(model);
|
|
|
|
const { channelTitle, messageId } = this.paramsFor(this.routeName);
|
|
const slug = slugifyChannel(model);
|
|
if (channelTitle !== slug) {
|
|
this.router.replaceWith("chat.channel.index", model.id, slug, {
|
|
queryParams: { messageId },
|
|
});
|
|
}
|
|
}
|
|
|
|
@action
|
|
didTransition() {
|
|
const { channelId, messageId } = this.paramsFor(this.routeName);
|
|
if (channelId && messageId) {
|
|
schedule("afterRender", () => {
|
|
this.chat.openChannelAtMessage(channelId, messageId);
|
|
this.controller.set("messageId", null); // clear the query param
|
|
});
|
|
}
|
|
return true;
|
|
}
|
|
}
|