From 86cc4ce08d4ee8225933c5da9247b3586582a4ca Mon Sep 17 00:00:00 2001 From: eugenijm Date: Mon, 11 May 2020 14:35:55 +0300 Subject: [PATCH] WIP attachments --- src/components/chat/chat.js | 19 ++++++++++++++++--- src/components/chat/chat.vue | 1 - src/components/chat_message/chat_message.js | 13 ++++++++++--- .../post_status_form/post_status_form.js | 1 - .../post_status_form/post_status_form.vue | 9 +++++++-- src/i18n/en.json | 3 ++- src/services/api/api.service.js | 14 ++++++++++---- .../entity_normalizer.service.js | 3 +++ 8 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/components/chat/chat.js b/src/components/chat/chat.js index 8f8e279d..27713e30 100644 --- a/src/components/chat/chat.js +++ b/src/components/chat/chat.js @@ -325,11 +325,24 @@ const Chat = { }) this.fetchChat(true, chatId) }, - poster ({ status }) { - return this.backendInteractor.postChatMessage({ + poster (opts) { + const status = opts.status + + if (!status) { + // TODO: + return Promise.resolve({ error: this.$t('chats.empty_message_error') }) + } + + let params = { id: this.currentChat.id, content: status - }) + } + + if (opts.media && opts.media[0]) { + params.mediaId = opts.media[0].id + } + + return this.backendInteractor.postChatMessage(params) } } } diff --git a/src/components/chat/chat.vue b/src/components/chat/chat.vue index 108681a1..dd8d849e 100644 --- a/src/components/chat/chat.vue +++ b/src/components/chat/chat.vue @@ -76,7 +76,6 @@ :disable-subject="true" :disable-scope-selector="true" :disable-notice="true" - :disable-attachments="true" :disable-polls="true" :poster="poster" :preserve-focus="true" diff --git a/src/components/chat_message/chat_message.js b/src/components/chat_message/chat_message.js index 7e3cfad3..5354aa00 100644 --- a/src/components/chat_message/chat_message.js +++ b/src/components/chat_message/chat_message.js @@ -46,12 +46,19 @@ const ChatMessage = { return this.chatViewItem.type === 'message' }, messageForStatusContent () { - return { + let result = { summary: '', statusnet_html: this.message.content, - text: this.message.content, - attachments: [] + text: this.message.content } + + if (this.message.attachment) { + result.attachments = [this.message.attachment] + } else { + result.attachments = [] + } + + return result }, ...mapState({ betterShadow: state => state.interface.browserSupport.cssFilter, diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 27fd9db1..dcb6220d 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -36,7 +36,6 @@ const PostStatusForm = { 'disableScopeSelector', 'disableNotice', 'disablePolls', - 'disableAttachments', 'placeholder', 'maxHeight', 'poster', diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue index bba79989..cc82f8f4 100644 --- a/src/components/post_status_form/post_status_form.vue +++ b/src/components/post_status_form/post_status_form.vue @@ -169,7 +169,6 @@ >
diff --git a/src/i18n/en.json b/src/i18n/en.json index 9c17a54b..345fcb9e 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -758,7 +758,8 @@ "write_message": "Write a message", "delete": "Delete", "chats": "Chats", - "new": "New Chat" + "new": "New Chat", + "empty_message_error": "Cannot post empty message" }, "display_date": { "today": "Today" diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index d97dd067..9222f94b 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -1158,13 +1158,19 @@ const chatMessages = ({ id, credentials }) => { }) } -const postChatMessage = ({ id, content, credentials }) => { +const postChatMessage = ({ id, content, mediaId = null, credentials }) => { + let payload = { + 'content': content + } + + if (mediaId) { + payload['media_id'] = mediaId + } + return promisedRequest({ url: PLEROMA_CHAT_MESSAGES_URL(id), method: 'POST', - payload: { - 'content': content - }, + payload: payload, credentials }) } diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 5f9be7f1..60b1c6c2 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -386,5 +386,8 @@ export const parseChatMessage = (message) => { output.id = parseInt(message.id, 10) output.created_at = new Date(message.created_at) output.chat_id = parseInt(message.chat_id, 10) + if (message.attachment) { + output.attachment = parseAttachment(message.attachment) + } return output }