From b44755b91ee8cbebf7b185d7f69393be26b85acd Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 6 Mar 2021 15:04:10 +0100 Subject: [PATCH] searchPrivate --- .../components/conversations/chatWindows.js | 12 +++++ .../js/components/conversations/interface.js | 3 -- assets/js/components/conversations/utils.js | 44 +++++++++++++++++++ assets/js/pages/conversations/conversation.js | 37 +--------------- 4 files changed, 57 insertions(+), 39 deletions(-) diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index 30e50a64..bfd4e4fb 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -196,6 +196,10 @@ const ConvChatWindow = { }); + + + + // =========== SEND FILES =========== //Add image button const fileButton = createElem2({ appendTo: buttonGroup, @@ -229,6 +233,14 @@ const ConvChatWindow = { type: "i", class: "fa fa-send-o", }); + + console.info(infosBox) + //ConversationsUtils.registerInputToSendFile(, fileInput, formContainer); + + // =========== /SEND FILES =========== + + + //Prevent textarea from adding a new line when pressing enter $(inputText).keypress(function(event){ diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index 0e3820cc..875c44c8 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -237,9 +237,6 @@ const ConversationsInterface = { callback(result); }); - - //Success - return true; }, /** diff --git a/assets/js/components/conversations/utils.js b/assets/js/components/conversations/utils.js index 41e53ad2..fe3d8107 100644 --- a/assets/js/components/conversations/utils.js +++ b/assets/js/components/conversations/utils.js @@ -210,6 +210,50 @@ const ConversationsUtils = { "2": users.get(msg.server_message.user_removed).fullName }); } + }, + + /** + * @param {number} convID + * @param {HTMLInputElement} input + * @param {HTMLElement} target + */ + registerInputToSendFile: function(convID, fileInput, splashScreenTarget){ + fileInput.addEventListener("change", async (e) => { + e.preventDefault(); + + let el; + + try { + + if(fileInput.files.length == 0) + return; + + const file = fileInput.files[0]; + + if (ServerConfig.conf.allowed_conversation_files_type.indexOf(file.type) < 0) { + notify(tr("This file type is not allowed!"), "danger") + return; + } + + + if (file.size > ServerConfig.conf.conversation_files_max_size) { + notify(tr("This file is too big (max file size: %1%)", {"1": fileSizeToHuman(ServerConfig.conf.conversation_files_max_size)}), "danger"); + return; + } + + el = Page.showTransparentWaitSplashScreen(splashScreenTarget); + + await ConversationsInterface.sendMessage(convID, null, fileInput); + } + + catch(e) { + console.error(e); + notify(tr("Failed to send file!"), "danger"); + } + + el.remove(); + + }); } } diff --git a/assets/js/pages/conversations/conversation.js b/assets/js/pages/conversations/conversation.js index 6f17860c..c07c050d 100644 --- a/assets/js/pages/conversations/conversation.js +++ b/assets/js/pages/conversations/conversation.js @@ -445,42 +445,7 @@ const ConversationPageConvPart = { class: "fa fa-plus" }); - fileInput.addEventListener("change", async (e) => { - e.preventDefault(); - - let el; - - try { - - if(fileInput.files.length == 0) - return; - - const file = fileInput.files[0]; - - if (ServerConfig.conf.allowed_conversation_files_type.indexOf(file.type) < 0) { - notify(tr("This file type is not allowed!"), "danger") - return; - } - - - if (file.size > ServerConfig.conf.conversation_files_max_size) { - notify(tr("This file is too big (max file size: %1%)", {"1": fileSizeToHuman(ServerConfig.conf.conversation_files_max_size)}), "danger"); - return; - } - - el = Page.showTransparentWaitSplashScreen(); - - await ConversationsInterface.sendMessage(this._conv_info.id, null, fileInput); - } - - catch(e) { - console.error(e); - notify(tr("Failed to send file!"), "danger"); - } - - el.remove(); - - }); + ConversationsUtils.registerInputToSendFile(this._conv_info.id, fileInput, formContainer); // ==== /FILE INPUT ====