discourse-chat-integration/assets/javascripts/discourse/routes/transcript.js

32 lines
828 B
JavaScript
Raw Normal View History

2023-11-29 17:01:31 -05:00
import { inject as service } from "@ember/service";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import DiscourseRoute from "discourse/routes/discourse";
2023-01-23 13:30:48 -05:00
export default class Trascript extends DiscourseRoute {
@service currentUser;
@service composer;
@service router;
async model(params) {
if (!this.currentUser) {
this.session.set("shouldRedirectToUrl", window.location.href);
this.router.replaceWith("login");
return;
}
const secret = params.secret;
await this.router.replaceWith("discovery.latest").followRedirects();
try {
const result = await ajax(`/chat-transcript/${secret}`);
this.composer.openNewTopic({
body: result.content,
});
} catch (e) {
popupAjaxError(e);
}
2023-01-23 13:30:48 -05:00
}
}