mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-10-31 02:04:53 +00:00 
			
		
		
		
	Can send again text message from conversation box
This commit is contained in:
		| @@ -142,7 +142,7 @@ const ConvChatWindow = { | |||||||
| 			appendTo: inputGroup, | 			appendTo: inputGroup, | ||||||
| 			type: "textarea", | 			type: "textarea", | ||||||
| 			class: "form-control", | 			class: "form-control", | ||||||
| 			placeholder: "New message...", | 			placeholder: tr("New message..."), | ||||||
| 		}); | 		}); | ||||||
| 		inputText.maxLength = 200; | 		inputText.maxLength = 200; | ||||||
|  |  | ||||||
| @@ -154,8 +154,8 @@ const ConvChatWindow = { | |||||||
| 			autosize: true, | 			autosize: true, | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		//Create image input (for optionnal image) | 		//Create file input (for optionnal file) | ||||||
| 		var inputImage = createElem2({ | 		var fileInput = createElem2({ | ||||||
| 			type: "input", | 			type: "input", | ||||||
| 			elemType: "file", | 			elemType: "file", | ||||||
| 		}); | 		}); | ||||||
| @@ -175,8 +175,6 @@ const ConvChatWindow = { | |||||||
| 			elemType: "button", | 			elemType: "button", | ||||||
| 			class: "btn btn-flat btn-add-emoji", | 			class: "btn btn-flat btn-add-emoji", | ||||||
| 		}); | 		}); | ||||||
| 		 |  | ||||||
| 			//Add image icon |  | ||||||
| 			createElem2({ | 			createElem2({ | ||||||
| 				type: "i", | 				type: "i", | ||||||
| 				appendTo: emojiButton,  | 				appendTo: emojiButton,  | ||||||
| @@ -199,21 +197,21 @@ const ConvChatWindow = { | |||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		//Add image button | 		//Add image button | ||||||
| 		var imageButton = createElem2({ | 		const fileButton = createElem2({ | ||||||
| 			appendTo: buttonGroup, | 			appendTo: buttonGroup, | ||||||
| 			type: "button", | 			type: "button", | ||||||
| 			elemType: "button", | 			elemType: "button", | ||||||
| 			class: "btn btn-flat btn-add-image", | 			class: "btn btn-flat btn-add-image", | ||||||
| 		}); | 		}); | ||||||
| 		imageButton.onclick = function(){ | 		fileButton.onclick = function(){ | ||||||
| 			//Call file selector | 			//Call file selector | ||||||
| 			inputImage.click(); | 			fileInput.click(); | ||||||
| 		}; | 		}; | ||||||
| 		 | 		 | ||||||
| 			//Add image icon | 			//Add image icon | ||||||
| 			createElem2({ | 			createElem2({ | ||||||
| 				type: "i", | 				type: "i", | ||||||
| 				appendTo: imageButton,  | 				appendTo: fileButton,  | ||||||
| 				class: "fa fa-image" | 				class: "fa fa-image" | ||||||
| 			}); | 			}); | ||||||
| 		 | 		 | ||||||
| @@ -246,7 +244,6 @@ const ConvChatWindow = { | |||||||
| 			sendButton: sendButton, | 			sendButton: sendButton, | ||||||
| 			inputText: inputText, | 			inputText: inputText, | ||||||
| 			textarea2: textarea2, | 			textarea2: textarea2, | ||||||
| 			inputImage: inputImage, |  | ||||||
| 		}; | 		}; | ||||||
|  |  | ||||||
| 		//Success | 		//Success | ||||||
| @@ -654,50 +651,41 @@ const ConvChatWindow = { | |||||||
| 	 * @param {Object} convInfos Information about the conversation | 	 * @param {Object} convInfos Information about the conversation | ||||||
| 	 * @return {Boolean} True for a success | 	 * @return {Boolean} True for a success | ||||||
| 	 */ | 	 */ | ||||||
| 	submitMessageForm: function(convInfos){ | 	submitMessageForm: async function(convInfos){ | ||||||
| 		 | 		 | ||||||
| 		//Log action | 		try { | ||||||
| 		ComunicWeb.debug.logMessage("Send a new message in a conversation system."); |  | ||||||
| 		 | 		 | ||||||
| 		//Extract main fields | 			//Extract main fields | ||||||
| 		var form = convInfos.box.sendMessageForm; | 			var form = convInfos.box.sendMessageForm; | ||||||
|  |  | ||||||
| 		//Check if message is empty | 			//Check if message is empty. | ||||||
| 		if(!checkString(form.inputText.value) && !form.inputImage.files[0]){ | 			let message = form.inputText.value; | ||||||
| 			notify("Please type a valid message before trying to send it !", "danger", 2); |  | ||||||
| 			return false; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		//Lock send button | 			if (message.length == 0) | ||||||
| 		form.sendButton.disabled = true; | 				return; | ||||||
|  |  | ||||||
| 		//Prepare what to do next | 			if(message.length < ServerConfig.conf.min_conversation_message_len || message.length > ServerConfig.conf.max_conversation_message_len){ | ||||||
| 		var onceSent = (result) => { | 				notify(tr("Invalid message length!"), "danger", 2); | ||||||
|  | 				return; | ||||||
| 			//Check for errors |  | ||||||
| 			if(result.error){ |  | ||||||
| 				notify("An error occured while trying to send message! Please try again...", "danger", 2); |  | ||||||
|  |  | ||||||
| 				//Unlock send button |  | ||||||
| 				form.sendButton.disabled = false; |  | ||||||
|  |  | ||||||
| 				return false; |  | ||||||
| 			} | 			} | ||||||
| 			 | 			 | ||||||
|  | 			//Lock send button | ||||||
|  | 			form.sendButton.disabled = true; | ||||||
|  |  | ||||||
|  | 			await ConversationsInterface.sendMessage(convInfos.infos.id, message); | ||||||
|  | 			 | ||||||
| 			//Reset the form | 			//Reset the form | ||||||
| 			ComunicWeb.components.conversations.chatWindows.resetCreateMessageForm(convInfos); | 			ConvChatWindow.resetCreateMessageForm(convInfos); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		//Send the message throught the interface | 		catch(e) | ||||||
| 		ConversationsInterface.sendMessage({ | 		{ | ||||||
| 			conversationID: convInfos.infos.ID, | 			console.error(e) | ||||||
| 			message: form.inputText.value, | 			notify("An error occured while trying to send message! Please try again...", "danger", 2); | ||||||
| 			image: form.inputImage, | 		} | ||||||
| 			callback: onceSent |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		//Success | 		//Unlock send button | ||||||
| 		return true; | 		form.sendButton.disabled = false; | ||||||
| 	}, | 	}, | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| @@ -717,12 +705,6 @@ const ConvChatWindow = { | |||||||
| 		//Empty textarea | 		//Empty textarea | ||||||
| 		form.inputText.value = ""; | 		form.inputText.value = ""; | ||||||
| 		form.textarea2.resetHeight(); | 		form.textarea2.resetHeight(); | ||||||
|  |  | ||||||
| 		//Remove image from image input |  | ||||||
| 		form.inputImage.value = ""; |  | ||||||
|  |  | ||||||
| 		//Success |  | ||||||
| 		return true; |  | ||||||
| 	}, | 	}, | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user