mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Send notification when user is writing a message
This commit is contained in:
		@@ -4,7 +4,7 @@
 | 
				
			|||||||
 * @author Pierre HUBERT
 | 
					 * @author Pierre HUBERT
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ComunicWeb.common.date = {
 | 
					const ComunicDate = {
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get current timestamp
 | 
						 * Get current timestamp
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
@@ -100,3 +100,5 @@ ComunicWeb.common.date = {
 | 
				
			|||||||
		return this.diffToStr(this.time() - time);
 | 
							return this.diffToStr(this.time() - time);
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ComunicWeb.common.date = ComunicDate;
 | 
				
			||||||
@@ -146,6 +146,9 @@ const ConvChatWindow = {
 | 
				
			|||||||
		});
 | 
							});
 | 
				
			||||||
		inputText.maxLength = ServerConfig.conf.max_conversation_message_len;
 | 
							inputText.maxLength = ServerConfig.conf.max_conversation_message_len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Notify other users when this user is writing a message
 | 
				
			||||||
 | 
							ConversationsUtils.listenToInputChangeEvents(inputText, infosBox.conversationID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Enable textarea 2.0 on the message
 | 
							//Enable textarea 2.0 on the message
 | 
				
			||||||
		var textarea2 = new ComunicWeb.components.textarea();
 | 
							var textarea2 = new ComunicWeb.components.textarea();
 | 
				
			||||||
		textarea2.init({
 | 
							textarea2.init({
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -284,6 +284,30 @@ const ConversationsUtils = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		await ConversationsInterface.sendNewConversationImage(convID, input);
 | 
							await ConversationsInterface.sendNewConversationImage(convID, input);
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Automatically listen to change events of an input
 | 
				
			||||||
 | 
						 * to notify other users current user is writing a message
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {HTMLInputElement} input
 | 
				
			||||||
 | 
						 * @param {number} convID
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						listenToInputChangeEvents: async function(input, convID) {
 | 
				
			||||||
 | 
							let last_update = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							input.addEventListener("keyup", e => {
 | 
				
			||||||
 | 
								if(input.value == "")
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								const t = ComunicDate.time();
 | 
				
			||||||
 | 
								if (t - last_update < ServerConfig.conf.conversation_writing_event_interval)
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								last_update = t;
 | 
				
			||||||
 | 
								ws("conversations/writing", {convID: convID});
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ComunicWeb.components.conversations.utils = ConversationsUtils;
 | 
					ComunicWeb.components.conversations.utils = ConversationsUtils;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -465,6 +465,9 @@ const ConversationPageConvPart = {
 | 
				
			|||||||
		inputText.maxLength = ServerConfig.conf.max_conversation_message_len;
 | 
							inputText.maxLength = ServerConfig.conf.max_conversation_message_len;
 | 
				
			||||||
		inputText.focus();
 | 
							inputText.focus();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Notify other users when this user is writing a message
 | 
				
			||||||
 | 
							ConversationsUtils.listenToInputChangeEvents(inputText, this._conv_info.id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Enable textarea 2.0 on the message
 | 
							//Enable textarea 2.0 on the message
 | 
				
			||||||
		var textarea2 = new ComunicWeb.components.textarea();
 | 
							var textarea2 = new ComunicWeb.components.textarea();
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								assets/js/typings/ServerConfig.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								assets/js/typings/ServerConfig.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -36,4 +36,6 @@ declare interface StaticServerConfig {
 | 
				
			|||||||
    max_conversation_message_len: number,
 | 
					    max_conversation_message_len: number,
 | 
				
			||||||
    allowed_conversation_files_type: String[],
 | 
					    allowed_conversation_files_type: String[],
 | 
				
			||||||
    conversation_files_max_size: number,
 | 
					    conversation_files_max_size: number,
 | 
				
			||||||
 | 
					    conversation_writing_event_interval: number,
 | 
				
			||||||
 | 
					    conversation_writing_event_lifetime: number,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user