Browse Source

Fix scroll behavior and prevent history loading when the conversation is empty

pull/1474/head
Timothée Jaussoin 2 months ago
parent
commit
8cd3d190e6
  1. 9
      app/Widgets/Chat/Chat.php
  2. 13
      app/Widgets/Chat/chat.js

9
app/Widgets/Chat/Chat.php

@ -1012,7 +1012,8 @@ class Chat extends \Movim\Widget\Base
->first();
if ($contextMessage) {
$this->ajaxGetHistory($jid, $contextMessage->published, muc: $contextMessage->isMuc(), prepend: false, tryMam: false, clear: true);
$this->rpc('MovimTpl.fill', '#' . cleanupId($jid) . '-conversation', '');
$this->ajaxGetHistory($jid, $contextMessage->published, muc: $contextMessage->isMuc(), prepend: false, tryMam: false);
$this->rpc('Chat.scrollAndBlinkMessageMid', $mid);
$this->rpc('MovimUtils.addClass', '#chat_widget .contained', 'history');
}
@ -1024,7 +1025,7 @@ class Chat extends \Movim\Widget\Base
* @param string jid
* @param string time
*/
public function ajaxGetHistory(string $jid, ?string $date = null, bool $muc = false, bool $prepend = true, bool $tryMam = true, ?bool $clear = false)
public function ajaxGetHistory(string $jid, ?string $date = null, bool $muc = false, bool $prepend = true, bool $tryMam = true)
{
if (!validateJid($jid)) return;
@ -1048,10 +1049,6 @@ class Chat extends \Movim\Widget\Base
$this->prepareMessage($message);
}
if ($clear) {
$this->rpc('MovimTpl.fill', '#' . cleanupId($jid) . '-conversation', '');
}
$this->rpc('Chat.appendMessagesWrapper', $this->_wrapper, $prepend);
$this->_wrapper = [];
}

13
app/Widgets/Chat/chat.js

@ -658,10 +658,11 @@ var Chat = {
},
setScrollBehaviour: function () {
var discussion = Chat.getDiscussion();
if (discussion == null) return;
if (!discussion) return;
discussion.onscroll = function () {
if (this.scrollTop < 1) {
// Don't get more history the conversation is already empty
if (discussion.querySelector('.conversation').innerHTML != '' && this.scrollTop < 100) {
Chat.getHistory(true);
}
@ -672,7 +673,7 @@ var Chat = {
},
setScroll: function () {
var discussion = Chat.getDiscussion();
if (discussion == null) return;
if (!discussion) return;
Chat.lastHeight = discussion.scrollHeight;
Chat.lastScroll = discussion.scrollTop + discussion.clientHeight;
@ -700,7 +701,7 @@ var Chat = {
},
scrollTotally: function () {
var discussion = Chat.getDiscussion();
if (discussion == null) return;
if (!discussion) return;
discussion.scrollTop = discussion.scrollHeight;
},
@ -722,7 +723,7 @@ var Chat = {
},
scrollToSeparator: function () {
var discussion = Chat.getDiscussion();
if (discussion == null) return;
if (!discussion) return;
var separator = discussion.querySelector('.separator');
if (separator) {
@ -1273,6 +1274,8 @@ var Chat = {
appendDate: function (date, prepend) {
var list = document.querySelector('#chat_widget > div ul.conversation');
if (!list) return;
dateNode = Chat.date.cloneNode(true);
dateNode.querySelector('p').innerHTML = date;
dateNode.id = MovimUtils.cleanupId(date);

Loading…
Cancel
Save