From b02e485ce7afaa0ace85e4344f405f14437940ab Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Mon, 8 Apr 2024 10:53:10 +0800 Subject: [PATCH] ability to add attachments to messages, fixed chat-tray styling --- addon/components/chat-tray.hbs | 26 ++++++++++++++------------ addon/components/chat-window.js | 28 +++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/addon/components/chat-tray.hbs b/addon/components/chat-tray.hbs index dfb3dce..5ad51e8 100644 --- a/addon/components/chat-tray.hbs +++ b/addon/components/chat-tray.hbs @@ -13,22 +13,24 @@
-
+
{{#each this.channels as |channel|}} -
- -
- +
+
+ +
{{/each}} diff --git a/addon/components/chat-window.js b/addon/components/chat-window.js index 8242f26..046c3d0 100644 --- a/addon/components/chat-window.js +++ b/addon/components/chat-window.js @@ -3,6 +3,7 @@ import { tracked } from '@glimmer/tracking'; import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import { task } from 'ember-concurrency'; +import { all } from 'rsvp'; export default class ChatWindowComponent extends Component { @service chat; @@ -101,10 +102,35 @@ export default class ChatWindowComponent extends Component { } @action sendMessage() { - this.chat.sendMessage(this.channel, this.sender, this.pendingMessageContent); + this.chat.sendMessage(this.channel, this.sender, this.pendingMessageContent).then((chatMessageRecord) => { + this.sendAttachments(chatMessageRecord); + }); this.pendingMessageContent = ''; } + @action sendAttachments(chatMessageRecord) { + // create file attachments + const attachments = this.pendingAttachmentFiles.map((file) => { + const attachment = this.store.createRecord('chat-attachment', { + chat_channel_uuid: this.channel.id, + file_uuid: file.id, + sender_uuid: this.sender.id, + }); + + if (chatMessageRecord) { + attachment.set('chat_message_uuid', chatMessageRecord.id); + } + + return attachment; + }); + + // clear pending attachments + this.pendingAttachmentFiles = []; + + // save attachments + return all(attachments.map((_) => _.save())); + } + @action closeChannel() { this.chat.closeChannel(this.channel); }