mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Auto scroll
This commit is contained in:
		@@ -327,15 +327,10 @@ const ConversationPageConvPart = {
 | 
				
			|||||||
			nameContainer.innerHTML = userFullName(this._conv_info.users["user-" + info.ID_user]);
 | 
								nameContainer.innerHTML = userFullName(this._conv_info.users["user-" + info.ID_user]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Set a timeout to make slimscroll properly work (for newest messages)
 | 
							//Set a timeout to make scroll properly work (for newest messages)
 | 
				
			||||||
		if(toLatestMessages){
 | 
							if(toLatestMessages){
 | 
				
			||||||
			setTimeout(function(){
 | 
								setTimeout(function(){
 | 
				
			||||||
 | 
									messageContainer.scrollIntoView(false)
 | 
				
			||||||
				//Enable / update slimscroll
 | 
					 | 
				
			||||||
				var target = ComunicWeb.pages.conversations.conversation._conv_info.window.messagesTarget;
 | 
					 | 
				
			||||||
				var scrollBottom = $(target).prop("scrollHeight")+"px";
 | 
					 | 
				
			||||||
				//ComunicWeb.pages.conversations.utils.enableSlimScroll(target, "100%", scrollBottom);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			}, 100);
 | 
								}, 100);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
@@ -523,24 +518,19 @@ const ConversationPageConvPart = {
 | 
				
			|||||||
		//Save conversation information
 | 
							//Save conversation information
 | 
				
			||||||
		var convInfo = this._conv_info;
 | 
							var convInfo = this._conv_info;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$(this._conv_info.window.messagesTarget).bind("slimscrolling", function(e, pos){
 | 
							const msgTarget = this._conv_info.window.messagesTarget;
 | 
				
			||||||
 | 
							msgTarget.addEventListener("scroll", () => {
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//Check if a request is already pending
 | 
								//Check if a request is already pending
 | 
				
			||||||
			if(refreshLocked)
 | 
								if(refreshLocked)
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			//Check if we are not at the top of the screen
 | 
								//Check if we are not at the top of the screen
 | 
				
			||||||
			if(pos != 0){
 | 
								if(msgTarget.scrollTop != 0){
 | 
				
			||||||
				topScrollCount = 0;
 | 
					 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			
 | 
					
 | 
				
			||||||
			//Increment value
 | 
					 | 
				
			||||||
			topScrollCount++;
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			//The user must scroll several seconds to request a refresh
 | 
					 | 
				
			||||||
			if(topScrollCount < 3)
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//Lock refresh
 | 
								//Lock refresh
 | 
				
			||||||
			refreshLocked = true;
 | 
								refreshLocked = true;
 | 
				
			||||||
@@ -576,14 +566,9 @@ const ConversationPageConvPart = {
 | 
				
			|||||||
					ComunicWeb.pages.conversations.conversation.addMessage(message);
 | 
										ComunicWeb.pages.conversations.conversation.addMessage(message);
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				//Update slimscroll
 | 
									//Scroll to newest message
 | 
				
			||||||
				newScrollPos = oldestMessage.offsetTop - 30;
 | 
									document.querySelector("[data-chatpage-msg-text-id=\""+response[0].ID+"\"]").scrollIntoView()
 | 
				
			||||||
				if(newScrollPos < 0)
 | 
									
 | 
				
			||||||
					newScrollPos = 0;
 | 
					 | 
				
			||||||
				/*ComunicWeb.pages.conversations.utils.enableSlimScroll(
 | 
					 | 
				
			||||||
					convInfo.window.messagesTarget,
 | 
					 | 
				
			||||||
					"100%", 
 | 
					 | 
				
			||||||
					newScrollPos);*/
 | 
					 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user