FIX: Update transcript handling following core updates (#179)

This commit is contained in:
David Taylor 2023-11-27 12:04:54 +00:00 committed by GitHub
parent a6dfc289a4
commit 3860d82625
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 23 deletions

View File

@ -1,32 +1,31 @@
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import DiscourseRoute from "discourse/routes/discourse";
import { next } from "@ember/runloop";
import { inject as service } from "@ember/service";
export default class Trascript extends DiscourseRoute {
model(params) {
if (this.currentUser) {
@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;
this.replaceWith("discovery.latest").then((e) => {
if (this.controllerFor("navigation/default").get("canCreateTopic")) {
next(() => {
ajax(`chat-transcript/${secret}`).then((result) => {
e.send(
"createNewTopicViaParams",
null,
result["content"],
null,
null,
null
);
}, popupAjaxError);
await this.router.replaceWith("discovery.latest").followRedirects();
try {
const result = await ajax(`/chat-transcript/${secret}`);
this.composer.openNewTopic({
body: result.content,
});
}
});
} else {
this.session.set("shouldRedirectToUrl", window.location.href);
this.replaceWith("login");
} catch (e) {
popupAjaxError(e);
}
}
}

View File

@ -0,0 +1,37 @@
import { settled, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
/**
* Workaround for https://github.com/tildeio/router.js/pull/335
*/
async function visitWithRedirects(url) {
try {
await visit(url);
} catch (error) {
const { message } = error;
if (message !== "TransitionAborted") {
throw error;
}
await settled();
}
}
acceptance("Chat Integration - slack transcript", function (needs) {
needs.user({
can_create_topic: true,
});
needs.pretender((server, helper) => {
server.get("/chat-transcript/abcde", () => {
return helper.response({
content: "This is a chat transcript",
});
});
});
test("Can open composer with transcript", async function (assert) {
await visitWithRedirects("/chat-transcript/abcde");
assert.dom(".d-editor-input").hasValue("This is a chat transcript");
});
});