FEATURE: implements drafts for threads (#24483)

This commit implements drafts for threads by adding a new `thread_id` column to `chat_drafts` table. This column is used to create draft keys on the frontend which are a compound key of the channel and the thread. If the draft is only for the channel, the key will be `c-${channelId}`, if for a thread: `c-${channelId}:t-${threadId}`.

This commit also moves the draft holder from the service to the channel or thread model. The current draft can now always be accessed by doing: `channel.draft` or `thread.draft`.

Other notable changes of this commit:
- moves ChatChannel to gjs
- moves ChatThread to gjs
This commit is contained in:
Joffrey JAFFEUX
2023-11-22 11:54:23 +01:00
committed by GitHub
parent 39aa70d7cb
commit 906caa63d7
31 changed files with 867 additions and 476 deletions

View File

@ -0,0 +1,8 @@
export default function applyDefaultHandlers(helpers) {
this.post("/chat/api/channels/:channel_id/drafts", () =>
helpers.response({})
);
this.post("/chat/api/channels/:channel_id/threads/:thread_id/drafts", () =>
helpers.response({})
);
}

View File

@ -12,36 +12,24 @@ module(
this.subject = getOwner(this).lookup("service:chat-drafts-manager");
});
hooks.afterEach(function () {
this.subject.reset();
});
test("storing and retrieving message", function (assert) {
test("storing and retrieving message", async function (assert) {
const message1 = fabricators.message();
this.subject.add(message1);
assert.strictEqual(
this.subject.get({ channelId: message1.channel.id }),
message1
);
await this.subject.add(message1, message1.channel.id);
assert.strictEqual(this.subject.get(message1.channel.id), message1);
const message2 = fabricators.message();
this.subject.add(message2);
assert.strictEqual(
this.subject.get({ channelId: message2.channel.id }),
message2
);
await this.subject.add(message2, message2.channel.id);
assert.strictEqual(this.subject.get(message2.channel.id), message2);
});
test("stores only chat messages", function (assert) {
assert.throws(function () {
this.subject.add({ foo: "bar" });
}, /instance of ChatMessage/);
});
test("#reset", async function (assert) {
const message = fabricators.message();
test("#reset", function (assert) {
this.subject.add(fabricators.message());
await this.subject.add(message, message.channel.id);
assert.strictEqual(Object.keys(this.subject.drafts).length, 1);