222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
** to ask for new chat content. The "name" argument should begin with
** an integer which is the largest "msgid" that the chat page currently
** holds. If newer content is available, this routine returns that
** content straight away. If no new content is available, this webpage
** blocks until the new content becomes available. In this way, the
** system implements "hanging-GET" or "long-poll" style event notification.
**
** The reply from this webpage is JSON that describes the new content.
** Format of the json:
**
** | {
** | "msg":[
** | {
** | "msgid": integer // message id
|
>
>
>
>
>
>
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
** to ask for new chat content. The "name" argument should begin with
** an integer which is the largest "msgid" that the chat page currently
** holds. If newer content is available, this routine returns that
** content straight away. If no new content is available, this webpage
** blocks until the new content becomes available. In this way, the
** system implements "hanging-GET" or "long-poll" style event notification.
**
** /chat-poll/N
**
** If N is negative, then the return value is the N most recent messages.
** Hence a request like /chat-poll/-100 can be used to initialize a new
** chat session to just the most recent messages.
**
** The reply from this webpage is JSON that describes the new content.
** Format of the json:
**
** | {
** | "msg":[
** | {
** | "msgid": integer // message id
|
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
int msgid = atoi(PD("name","0"));
Stmt q1;
login_check_credentials();
if( !g.perm.Chat ) return;
chat_create_tables();
cgi_set_content_type("text/json");
dataVersion = db_int64(0, "PRAGMA data_version");
db_prepare(&q1,
"SELECT msgid, datetime(mtime), xfrom, xmsg, length(file),"
" fname, fmime, mdel"
" FROM chat"
" WHERE msgid>%d"
" ORDER BY msgid",
msgid
|
>
>
>
>
>
|
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
int msgid = atoi(PD("name","0"));
Stmt q1;
login_check_credentials();
if( !g.perm.Chat ) return;
chat_create_tables();
cgi_set_content_type("text/json");
dataVersion = db_int64(0, "PRAGMA data_version");
if( msgid<0 ){
msgid = db_int(0,
"SELECT msgid FROM chat WHERE mdel IS NOT true"
" ORDER BY msgid DESC LIMIT 1 OFFSET %d", -msgid);
}
db_prepare(&q1,
"SELECT msgid, datetime(mtime), xfrom, xmsg, length(file),"
" fname, fmime, mdel"
" FROM chat"
" WHERE msgid>%d"
" ORDER BY msgid",
msgid
|