Fossil SCM

Cleaned up the is-first-call handling of the /chat message poller.

stephan 2021-03-21 18:51 chat-fetch-port
Commit 147ff84e21b9fc4302d5f98139ca12e88293570d6795f3a02a8009c2e40a52ef
2 files changed +14 -12 +12
+14 -12
--- src/chat.js
+++ src/chat.js
@@ -1216,12 +1216,13 @@
12161216
btn.addEventListener('click',()=>loadOldMessages(-1));
12171217
D.append(Chat.e.messagesWrapper, toolbar);
12181218
toolbar.disabled = true /*will be enabled when msg load finishes */;
12191219
})()/*end history loading widget setup*/;
12201220
1221
- const afterFetch = function(isFirstCall){
1222
- if(isFirstCall){
1221
+ const afterFetch = function f(){
1222
+ if(true===f.isFirstCall){
1223
+ f.isFirstCall = false;
12231224
Chat.ajaxEnd();
12241225
Chat.e.messagesWrapper.classList.remove('loading');
12251226
setTimeout(function(){
12261227
Chat.scrollMessagesTo(1);
12271228
}, 250);
@@ -1233,18 +1234,20 @@
12331234
"Reload this page to reactivate it.");
12341235
delete Chat.intervalTimer;
12351236
}
12361237
poll.running = false;
12371238
};
1238
- const poll = async function(){
1239
- if(poll.running) return;
1240
- poll.running = true;
1241
- if(0===poll.runCount++){
1239
+ afterFetch.isFirstCall = true;
1240
+ const poll = async function f(){
1241
+ if(f.running) return;
1242
+ f.running = true;
1243
+ Chat._isBatchLoading = f.isFirstCall;
1244
+ if(true===f.isFirstCall){
1245
+ f.isFirstCall = false;
12421246
Chat.ajaxStart();
12431247
Chat.e.messagesWrapper.classList.add('loading');
12441248
}
1245
- Chat._isBatchLoading = (1===poll.runCount);
12461249
F.fetch("chat-poll",{
12471250
timeout: 420 * 1000/*FIXME: get the value from the server*/,
12481251
urlParams:{
12491252
name: Chat.mxMsg
12501253
},
@@ -1256,23 +1259,22 @@
12561259
Chat._isBatchLoading = false;
12571260
console.error(err);
12581261
/* ^^^ we don't use Chat.reportError() here b/c the polling
12591262
fails exepectedly when it times out, but is then immediately
12601263
resumed, and reportError() produces a loud error message. */
1261
- afterFetch(1===poll.runCount);
1264
+ afterFetch();
12621265
},
12631266
onload:function(y){
12641267
newcontent(y);
12651268
Chat._isBatchLoading = false;
1266
- afterFetch(1===poll.runCount);
1269
+ afterFetch();
12671270
}
12681271
});
12691272
};
1270
- poll.runCount = 0;
1273
+ poll.isFirstCall = true;
12711274
Chat._gotServerError = poll.running = false;
1272
- Chat.intervalTimer = setInterval(poll, 1000);
12731275
if( window.fossil.config.chat.fromcli ){
12741276
Chat.chatOnlyMode(true);
12751277
}
1276
-
1278
+ Chat.intervalTimer = setInterval(poll, 1000);
12771279
F.page.chat = Chat/* enables testing the APIs via the dev tools */;
12781280
})();
12791281
--- src/chat.js
+++ src/chat.js
@@ -1216,12 +1216,13 @@
1216 btn.addEventListener('click',()=>loadOldMessages(-1));
1217 D.append(Chat.e.messagesWrapper, toolbar);
1218 toolbar.disabled = true /*will be enabled when msg load finishes */;
1219 })()/*end history loading widget setup*/;
1220
1221 const afterFetch = function(isFirstCall){
1222 if(isFirstCall){
 
1223 Chat.ajaxEnd();
1224 Chat.e.messagesWrapper.classList.remove('loading');
1225 setTimeout(function(){
1226 Chat.scrollMessagesTo(1);
1227 }, 250);
@@ -1233,18 +1234,20 @@
1233 "Reload this page to reactivate it.");
1234 delete Chat.intervalTimer;
1235 }
1236 poll.running = false;
1237 };
1238 const poll = async function(){
1239 if(poll.running) return;
1240 poll.running = true;
1241 if(0===poll.runCount++){
 
 
 
1242 Chat.ajaxStart();
1243 Chat.e.messagesWrapper.classList.add('loading');
1244 }
1245 Chat._isBatchLoading = (1===poll.runCount);
1246 F.fetch("chat-poll",{
1247 timeout: 420 * 1000/*FIXME: get the value from the server*/,
1248 urlParams:{
1249 name: Chat.mxMsg
1250 },
@@ -1256,23 +1259,22 @@
1256 Chat._isBatchLoading = false;
1257 console.error(err);
1258 /* ^^^ we don't use Chat.reportError() here b/c the polling
1259 fails exepectedly when it times out, but is then immediately
1260 resumed, and reportError() produces a loud error message. */
1261 afterFetch(1===poll.runCount);
1262 },
1263 onload:function(y){
1264 newcontent(y);
1265 Chat._isBatchLoading = false;
1266 afterFetch(1===poll.runCount);
1267 }
1268 });
1269 };
1270 poll.runCount = 0;
1271 Chat._gotServerError = poll.running = false;
1272 Chat.intervalTimer = setInterval(poll, 1000);
1273 if( window.fossil.config.chat.fromcli ){
1274 Chat.chatOnlyMode(true);
1275 }
1276
1277 F.page.chat = Chat/* enables testing the APIs via the dev tools */;
1278 })();
1279
--- src/chat.js
+++ src/chat.js
@@ -1216,12 +1216,13 @@
1216 btn.addEventListener('click',()=>loadOldMessages(-1));
1217 D.append(Chat.e.messagesWrapper, toolbar);
1218 toolbar.disabled = true /*will be enabled when msg load finishes */;
1219 })()/*end history loading widget setup*/;
1220
1221 const afterFetch = function f(){
1222 if(true===f.isFirstCall){
1223 f.isFirstCall = false;
1224 Chat.ajaxEnd();
1225 Chat.e.messagesWrapper.classList.remove('loading');
1226 setTimeout(function(){
1227 Chat.scrollMessagesTo(1);
1228 }, 250);
@@ -1233,18 +1234,20 @@
1234 "Reload this page to reactivate it.");
1235 delete Chat.intervalTimer;
1236 }
1237 poll.running = false;
1238 };
1239 afterFetch.isFirstCall = true;
1240 const poll = async function f(){
1241 if(f.running) return;
1242 f.running = true;
1243 Chat._isBatchLoading = f.isFirstCall;
1244 if(true===f.isFirstCall){
1245 f.isFirstCall = false;
1246 Chat.ajaxStart();
1247 Chat.e.messagesWrapper.classList.add('loading');
1248 }
 
1249 F.fetch("chat-poll",{
1250 timeout: 420 * 1000/*FIXME: get the value from the server*/,
1251 urlParams:{
1252 name: Chat.mxMsg
1253 },
@@ -1256,23 +1259,22 @@
1259 Chat._isBatchLoading = false;
1260 console.error(err);
1261 /* ^^^ we don't use Chat.reportError() here b/c the polling
1262 fails exepectedly when it times out, but is then immediately
1263 resumed, and reportError() produces a loud error message. */
1264 afterFetch();
1265 },
1266 onload:function(y){
1267 newcontent(y);
1268 Chat._isBatchLoading = false;
1269 afterFetch();
1270 }
1271 });
1272 };
1273 poll.isFirstCall = true;
1274 Chat._gotServerError = poll.running = false;
 
1275 if( window.fossil.config.chat.fromcli ){
1276 Chat.chatOnlyMode(true);
1277 }
1278 Chat.intervalTimer = setInterval(poll, 1000);
1279 F.page.chat = Chat/* enables testing the APIs via the dev tools */;
1280 })();
1281
--- src/fossil.fetch.js
+++ src/fossil.fetch.js
@@ -166,10 +166,22 @@
166166
opt.onerror(new Error("XHR timeout of "+x.timeout+"ms expired."));
167167
};
168168
x.onreadystatechange = function(){
169169
if(XMLHttpRequest.DONE !== x.readyState) return;
170170
try{opt.aftersend()}catch(e){/*ignore*/}
171
+ if(false && 0===x.status){
172
+ /* For reasons unknown, we _sometimes_ trigger x.status==0 in FF
173
+ when the /chat page starts up, but not in Chrome nor in other
174
+ apps. Insofar as has been determined, this happens before a
175
+ request is actually sent and it appears to have no
176
+ side-effects on the app other than to generate an error
177
+ (i.e. no requests/responses are missing). This is a silly
178
+ workaround which may or may not bite us later. If so, it can
179
+ be removed at the cost of an unsightly console error message
180
+ in FF. */
181
+ return;
182
+ }
171183
if(200!==x.status){
172184
let err;
173185
try{
174186
const j = JSON.parse(x.response);
175187
if(j.error) err = new Error(j.error);
176188
--- src/fossil.fetch.js
+++ src/fossil.fetch.js
@@ -166,10 +166,22 @@
166 opt.onerror(new Error("XHR timeout of "+x.timeout+"ms expired."));
167 };
168 x.onreadystatechange = function(){
169 if(XMLHttpRequest.DONE !== x.readyState) return;
170 try{opt.aftersend()}catch(e){/*ignore*/}
 
 
 
 
 
 
 
 
 
 
 
 
171 if(200!==x.status){
172 let err;
173 try{
174 const j = JSON.parse(x.response);
175 if(j.error) err = new Error(j.error);
176
--- src/fossil.fetch.js
+++ src/fossil.fetch.js
@@ -166,10 +166,22 @@
166 opt.onerror(new Error("XHR timeout of "+x.timeout+"ms expired."));
167 };
168 x.onreadystatechange = function(){
169 if(XMLHttpRequest.DONE !== x.readyState) return;
170 try{opt.aftersend()}catch(e){/*ignore*/}
171 if(false && 0===x.status){
172 /* For reasons unknown, we _sometimes_ trigger x.status==0 in FF
173 when the /chat page starts up, but not in Chrome nor in other
174 apps. Insofar as has been determined, this happens before a
175 request is actually sent and it appears to have no
176 side-effects on the app other than to generate an error
177 (i.e. no requests/responses are missing). This is a silly
178 workaround which may or may not bite us later. If so, it can
179 be removed at the cost of an unsightly console error message
180 in FF. */
181 return;
182 }
183 if(200!==x.status){
184 let err;
185 try{
186 const j = JSON.parse(x.response);
187 if(j.error) err = new Error(j.error);
188

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button