Fossil SCM

Fix the /chat-poll page so that it works even when called from "fossil ui".

drh 2020-12-23 18:21 chatroom-dev
Commit 6f424a32b5ef1ddbc086dba562ff7e2ff3b5a422686ebbfa5fbcf8684692f6c8
1 file changed +7 -3
+7 -3
--- src/chat.c
+++ src/chat.c
@@ -263,11 +263,10 @@
263263
** The "mdel" will only exist if "xmsg" is an empty string and "fsize" is zero.
264264
*/
265265
void chat_poll_webpage(void){
266266
Blob json; /* The json to be constructed and returned */
267267
sqlite3_int64 dataVersion; /* Data version. Used for polling. */
268
- sqlite3_int64 newDataVers;
269268
int iDelay = 1000; /* Delay until next poll (milliseconds) */
270269
const char *zSep = "{\"msgs\":[\n"; /* List separator */
271270
int msgid = atoi(PD("name","0"));
272271
Stmt q1;
273272
login_check_credentials();
@@ -325,20 +324,25 @@
325324
blob_appendf(&json, ",\"mdel\":%d}", iToDel);
326325
}else{
327326
blob_append(&json, "}", 1);
328327
}
329328
}
329
+ db_reset(&q1);
330330
if( cnt ){
331331
blob_append(&json, "\n]}", 3);
332332
cgi_set_content(&json);
333333
break;
334334
}
335335
sqlite3_sleep(iDelay);
336
- while( (newDataVers = db_int64(0,"PRAGMA data_version"))==dataVersion ){
336
+ while( 1 ){
337
+ sqlite3_int64 newDataVers = db_int64(0,"PRAGMA repository.data_version");
338
+ if( newDataVers!=dataVersion ){
339
+ dataVersion = newDataVers;
340
+ break;
341
+ }
337342
sqlite3_sleep(iDelay);
338343
}
339
- dataVersion = newDataVers;
340344
} /* Exit by "break" */
341345
db_finalize(&q1);
342346
return;
343347
}
344348
345349
--- src/chat.c
+++ src/chat.c
@@ -263,11 +263,10 @@
263 ** The "mdel" will only exist if "xmsg" is an empty string and "fsize" is zero.
264 */
265 void chat_poll_webpage(void){
266 Blob json; /* The json to be constructed and returned */
267 sqlite3_int64 dataVersion; /* Data version. Used for polling. */
268 sqlite3_int64 newDataVers;
269 int iDelay = 1000; /* Delay until next poll (milliseconds) */
270 const char *zSep = "{\"msgs\":[\n"; /* List separator */
271 int msgid = atoi(PD("name","0"));
272 Stmt q1;
273 login_check_credentials();
@@ -325,20 +324,25 @@
325 blob_appendf(&json, ",\"mdel\":%d}", iToDel);
326 }else{
327 blob_append(&json, "}", 1);
328 }
329 }
 
330 if( cnt ){
331 blob_append(&json, "\n]}", 3);
332 cgi_set_content(&json);
333 break;
334 }
335 sqlite3_sleep(iDelay);
336 while( (newDataVers = db_int64(0,"PRAGMA data_version"))==dataVersion ){
 
 
 
 
 
337 sqlite3_sleep(iDelay);
338 }
339 dataVersion = newDataVers;
340 } /* Exit by "break" */
341 db_finalize(&q1);
342 return;
343 }
344
345
--- src/chat.c
+++ src/chat.c
@@ -263,11 +263,10 @@
263 ** The "mdel" will only exist if "xmsg" is an empty string and "fsize" is zero.
264 */
265 void chat_poll_webpage(void){
266 Blob json; /* The json to be constructed and returned */
267 sqlite3_int64 dataVersion; /* Data version. Used for polling. */
 
268 int iDelay = 1000; /* Delay until next poll (milliseconds) */
269 const char *zSep = "{\"msgs\":[\n"; /* List separator */
270 int msgid = atoi(PD("name","0"));
271 Stmt q1;
272 login_check_credentials();
@@ -325,20 +324,25 @@
324 blob_appendf(&json, ",\"mdel\":%d}", iToDel);
325 }else{
326 blob_append(&json, "}", 1);
327 }
328 }
329 db_reset(&q1);
330 if( cnt ){
331 blob_append(&json, "\n]}", 3);
332 cgi_set_content(&json);
333 break;
334 }
335 sqlite3_sleep(iDelay);
336 while( 1 ){
337 sqlite3_int64 newDataVers = db_int64(0,"PRAGMA repository.data_version");
338 if( newDataVers!=dataVersion ){
339 dataVersion = newDataVers;
340 break;
341 }
342 sqlite3_sleep(iDelay);
343 }
 
344 } /* Exit by "break" */
345 db_finalize(&q1);
346 return;
347 }
348
349

Keyboard Shortcuts

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