Fossil SCM
chat: when loading older messages, return scroll point to the position it was at when load was started, per chat room request.
Commit
49cc6f28e81998f2f1af3072f1e7122bbd6e893601e11b1e3b6159c11b1a20d8
Parent
0a5fd03e5cb49d4…
1 file changed
+5
+5
| --- src/chat.js | ||
| +++ src/chat.js | ||
| @@ -946,10 +946,12 @@ | ||
| 946 | 946 | const loadOldMessages = function(n){ |
| 947 | 947 | Chat.ajaxStart(); |
| 948 | 948 | Chat.e.messagesWrapper.classList.add('loading'); |
| 949 | 949 | Chat.isBatchLoading = true; |
| 950 | 950 | var gotMessages = false; |
| 951 | + const scrollHt = Chat.e.messagesWrapper.scrollHeight, | |
| 952 | + scrollTop = Chat.e.messagesWrapper.scrollTop; | |
| 951 | 953 | fetch("chat-poll?before="+Chat.mnMsg+"&n="+n) |
| 952 | 954 | .then(x=>x.json()) |
| 953 | 955 | .then(function(x){ |
| 954 | 956 | gotMessages = x.msgs.length; |
| 955 | 957 | newcontent(x,true); |
| @@ -973,10 +975,13 @@ | ||
| 973 | 975 | if(ndx>=0) Chat.disableDuringAjax.splice(ndx,1); |
| 974 | 976 | Chat.e.loadOlderToolbar.disabled = true; |
| 975 | 977 | } |
| 976 | 978 | if(gotMessages > 0){ |
| 977 | 979 | F.toast.message("Loaded "+gotMessages+" older messages."); |
| 980 | + Chat.e.messagesWrapper.scrollTo( | |
| 981 | + 0, Chat.e.messagesWrapper.scrollHeight - scrollHt + scrollTop | |
| 982 | + ); | |
| 978 | 983 | } |
| 979 | 984 | Chat.ajaxEnd(); |
| 980 | 985 | }); |
| 981 | 986 | }; |
| 982 | 987 | const wrapper = D.div(); /* browsers don't all properly handle >1 child in a fieldset */; |
| 983 | 988 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -946,10 +946,12 @@ | |
| 946 | const loadOldMessages = function(n){ |
| 947 | Chat.ajaxStart(); |
| 948 | Chat.e.messagesWrapper.classList.add('loading'); |
| 949 | Chat.isBatchLoading = true; |
| 950 | var gotMessages = false; |
| 951 | fetch("chat-poll?before="+Chat.mnMsg+"&n="+n) |
| 952 | .then(x=>x.json()) |
| 953 | .then(function(x){ |
| 954 | gotMessages = x.msgs.length; |
| 955 | newcontent(x,true); |
| @@ -973,10 +975,13 @@ | |
| 973 | if(ndx>=0) Chat.disableDuringAjax.splice(ndx,1); |
| 974 | Chat.e.loadOlderToolbar.disabled = true; |
| 975 | } |
| 976 | if(gotMessages > 0){ |
| 977 | F.toast.message("Loaded "+gotMessages+" older messages."); |
| 978 | } |
| 979 | Chat.ajaxEnd(); |
| 980 | }); |
| 981 | }; |
| 982 | const wrapper = D.div(); /* browsers don't all properly handle >1 child in a fieldset */; |
| 983 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -946,10 +946,12 @@ | |
| 946 | const loadOldMessages = function(n){ |
| 947 | Chat.ajaxStart(); |
| 948 | Chat.e.messagesWrapper.classList.add('loading'); |
| 949 | Chat.isBatchLoading = true; |
| 950 | var gotMessages = false; |
| 951 | const scrollHt = Chat.e.messagesWrapper.scrollHeight, |
| 952 | scrollTop = Chat.e.messagesWrapper.scrollTop; |
| 953 | fetch("chat-poll?before="+Chat.mnMsg+"&n="+n) |
| 954 | .then(x=>x.json()) |
| 955 | .then(function(x){ |
| 956 | gotMessages = x.msgs.length; |
| 957 | newcontent(x,true); |
| @@ -973,10 +975,13 @@ | |
| 975 | if(ndx>=0) Chat.disableDuringAjax.splice(ndx,1); |
| 976 | Chat.e.loadOlderToolbar.disabled = true; |
| 977 | } |
| 978 | if(gotMessages > 0){ |
| 979 | F.toast.message("Loaded "+gotMessages+" older messages."); |
| 980 | Chat.e.messagesWrapper.scrollTo( |
| 981 | 0, Chat.e.messagesWrapper.scrollHeight - scrollHt + scrollTop |
| 982 | ); |
| 983 | } |
| 984 | Chat.ajaxEnd(); |
| 985 | }); |
| 986 | }; |
| 987 | const wrapper = D.div(); /* browsers don't all properly handle >1 child in a fieldset */; |
| 988 |