FIX: Update transcript handling following core updates (#179)
This commit is contained in:
parent
a6dfc289a4
commit
3860d82625
|
@ -1,32 +1,31 @@
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import { next } from "@ember/runloop";
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class Trascript extends DiscourseRoute {
|
export default class Trascript extends DiscourseRoute {
|
||||||
model(params) {
|
@service currentUser;
|
||||||
if (this.currentUser) {
|
@service composer;
|
||||||
const secret = params.secret;
|
@service router;
|
||||||
|
|
||||||
this.replaceWith("discovery.latest").then((e) => {
|
async model(params) {
|
||||||
if (this.controllerFor("navigation/default").get("canCreateTopic")) {
|
if (!this.currentUser) {
|
||||||
next(() => {
|
|
||||||
ajax(`chat-transcript/${secret}`).then((result) => {
|
|
||||||
e.send(
|
|
||||||
"createNewTopicViaParams",
|
|
||||||
null,
|
|
||||||
result["content"],
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
}, popupAjaxError);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.session.set("shouldRedirectToUrl", window.location.href);
|
this.session.set("shouldRedirectToUrl", window.location.href);
|
||||||
this.replaceWith("login");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# name: discourse-chat-integration
|
# name: discourse-chat-integration
|
||||||
# about: Allows integration with several external chat system providers
|
# about: Allows integration with several external chat system providers
|
||||||
# meta_topic_id: 66522
|
# meta_topic_id: 66522
|
||||||
# version: 0.1
|
# version: 0.1
|
||||||
# url: https://github.com/discourse/discourse-chat-integration
|
# url: https://github.com/discourse/discourse-chat-integration
|
||||||
|
|
|
@ -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");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue