Fossil SCM

Upon initial connect to the chatroom, only load the most recent 50 messages. This magic number "50" ought to be configurable, but is hard-coded for the moment. We also need a way for the user to request more history.

drh 2020-12-23 16:08 chatroom-dev
Commit c017a7b4d072fb6e6ab5310ae427790ed273daf3f9ee84ea5cef308a7f08be37
2 files changed +11 +1 -1
+11
--- src/chat.c
+++ src/chat.c
@@ -224,10 +224,16 @@
224224
** holds. If newer content is available, this routine returns that
225225
** content straight away. If no new content is available, this webpage
226226
** blocks until the new content becomes available. In this way, the
227227
** system implements "hanging-GET" or "long-poll" style event notification.
228228
**
229
+** /chat-poll/N
230
+**
231
+** If N is negative, then the return value is the N most recent messages.
232
+** Hence a request like /chat-poll/-100 can be used to initialize a new
233
+** chat session to just the most recent messages.
234
+**
229235
** The reply from this webpage is JSON that describes the new content.
230236
** Format of the json:
231237
**
232238
** | {
233239
** | "msg":[
@@ -263,10 +269,15 @@
263269
login_check_credentials();
264270
if( !g.perm.Chat ) return;
265271
chat_create_tables();
266272
cgi_set_content_type("text/json");
267273
dataVersion = db_int64(0, "PRAGMA data_version");
274
+ if( msgid<0 ){
275
+ msgid = db_int(0,
276
+ "SELECT msgid FROM chat WHERE mdel IS NOT true"
277
+ " ORDER BY msgid DESC LIMIT 1 OFFSET %d", -msgid);
278
+ }
268279
db_prepare(&q1,
269280
"SELECT msgid, datetime(mtime), xfrom, xmsg, length(file),"
270281
" fname, fmime, mdel"
271282
" FROM chat"
272283
" WHERE msgid>%d"
273284
--- src/chat.c
+++ src/chat.c
@@ -224,10 +224,16 @@
224 ** holds. If newer content is available, this routine returns that
225 ** content straight away. If no new content is available, this webpage
226 ** blocks until the new content becomes available. In this way, the
227 ** system implements "hanging-GET" or "long-poll" style event notification.
228 **
 
 
 
 
 
 
229 ** The reply from this webpage is JSON that describes the new content.
230 ** Format of the json:
231 **
232 ** | {
233 ** | "msg":[
@@ -263,10 +269,15 @@
263 login_check_credentials();
264 if( !g.perm.Chat ) return;
265 chat_create_tables();
266 cgi_set_content_type("text/json");
267 dataVersion = db_int64(0, "PRAGMA data_version");
 
 
 
 
 
268 db_prepare(&q1,
269 "SELECT msgid, datetime(mtime), xfrom, xmsg, length(file),"
270 " fname, fmime, mdel"
271 " FROM chat"
272 " WHERE msgid>%d"
273
--- src/chat.c
+++ src/chat.c
@@ -224,10 +224,16 @@
224 ** holds. If newer content is available, this routine returns that
225 ** content straight away. If no new content is available, this webpage
226 ** blocks until the new content becomes available. In this way, the
227 ** system implements "hanging-GET" or "long-poll" style event notification.
228 **
229 ** /chat-poll/N
230 **
231 ** If N is negative, then the return value is the N most recent messages.
232 ** Hence a request like /chat-poll/-100 can be used to initialize a new
233 ** chat session to just the most recent messages.
234 **
235 ** The reply from this webpage is JSON that describes the new content.
236 ** Format of the json:
237 **
238 ** | {
239 ** | "msg":[
@@ -263,10 +269,15 @@
269 login_check_credentials();
270 if( !g.perm.Chat ) return;
271 chat_create_tables();
272 cgi_set_content_type("text/json");
273 dataVersion = db_int64(0, "PRAGMA data_version");
274 if( msgid<0 ){
275 msgid = db_int(0,
276 "SELECT msgid FROM chat WHERE mdel IS NOT true"
277 " ORDER BY msgid DESC LIMIT 1 OFFSET %d", -msgid);
278 }
279 db_prepare(&q1,
280 "SELECT msgid, datetime(mtime), xfrom, xmsg, length(file),"
281 " fname, fmime, mdel"
282 " FROM chat"
283 " WHERE msgid>%d"
284
+1 -1
--- src/chat.js
+++ src/chat.js
@@ -1,8 +1,8 @@
11
(function(){
22
const form = document.querySelector('#chat-form');
3
- let mxMsg = 0;
3
+ let mxMsg = -50;
44
const F = window.fossil, D = F.dom;
55
const _me = F.user.name;
66
/* State for paste and drag/drop */
77
const BlobXferState = {
88
dropDetails: document.querySelector('#chat-drop-details'),
99
--- src/chat.js
+++ src/chat.js
@@ -1,8 +1,8 @@
1 (function(){
2 const form = document.querySelector('#chat-form');
3 let mxMsg = 0;
4 const F = window.fossil, D = F.dom;
5 const _me = F.user.name;
6 /* State for paste and drag/drop */
7 const BlobXferState = {
8 dropDetails: document.querySelector('#chat-drop-details'),
9
--- src/chat.js
+++ src/chat.js
@@ -1,8 +1,8 @@
1 (function(){
2 const form = document.querySelector('#chat-form');
3 let mxMsg = -50;
4 const F = window.fossil, D = F.dom;
5 const _me = F.user.name;
6 /* State for paste and drag/drop */
7 const BlobXferState = {
8 dropDetails: document.querySelector('#chat-drop-details'),
9

Keyboard Shortcuts

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