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.
Commit
c017a7b4d072fb6e6ab5310ae427790ed273daf3f9ee84ea5cef308a7f08be37
Parent
2480ce94653f2b9…
2 files changed
+11
+1
-1
+11
| --- src/chat.c | ||
| +++ src/chat.c | ||
| @@ -224,10 +224,16 @@ | ||
| 224 | 224 | ** holds. If newer content is available, this routine returns that |
| 225 | 225 | ** content straight away. If no new content is available, this webpage |
| 226 | 226 | ** blocks until the new content becomes available. In this way, the |
| 227 | 227 | ** system implements "hanging-GET" or "long-poll" style event notification. |
| 228 | 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 | +** | |
| 229 | 235 | ** The reply from this webpage is JSON that describes the new content. |
| 230 | 236 | ** Format of the json: |
| 231 | 237 | ** |
| 232 | 238 | ** | { |
| 233 | 239 | ** | "msg":[ |
| @@ -263,10 +269,15 @@ | ||
| 263 | 269 | login_check_credentials(); |
| 264 | 270 | if( !g.perm.Chat ) return; |
| 265 | 271 | chat_create_tables(); |
| 266 | 272 | cgi_set_content_type("text/json"); |
| 267 | 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 | + } | |
| 268 | 279 | db_prepare(&q1, |
| 269 | 280 | "SELECT msgid, datetime(mtime), xfrom, xmsg, length(file)," |
| 270 | 281 | " fname, fmime, mdel" |
| 271 | 282 | " FROM chat" |
| 272 | 283 | " WHERE msgid>%d" |
| 273 | 284 |
| --- 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 @@ | ||
| 1 | 1 | (function(){ |
| 2 | 2 | const form = document.querySelector('#chat-form'); |
| 3 | - let mxMsg = 0; | |
| 3 | + let mxMsg = -50; | |
| 4 | 4 | const F = window.fossil, D = F.dom; |
| 5 | 5 | const _me = F.user.name; |
| 6 | 6 | /* State for paste and drag/drop */ |
| 7 | 7 | const BlobXferState = { |
| 8 | 8 | dropDetails: document.querySelector('#chat-drop-details'), |
| 9 | 9 |
| --- 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 |