Fossil SCM

Basic chat functionality seems to be on-line again.

drh 2020-12-23 01:33 chatroom-dev
Commit 441ee6af06c98a280d5f86e66dba8a651068f2d0dac3127cc64bdfb5b5ce66ac
2 files changed +21 -5 +4 -2
+21 -5
--- src/chat.c
+++ src/chat.c
@@ -240,12 +240,14 @@
240240
while( db_step(&q1)==SQLITE_ROW ){
241241
int id = db_column_int(&q1, 0);
242242
const char *zDate = db_column_text(&q1, 1);
243243
const char *zFrom = db_column_text(&q1, 2);
244244
const char *zRawMsg = db_column_text(&q1, 3);
245
+ int nByte = db_column_bytes(&q1, 4);
246
+ const char *zFName = db_column_text(&q1, 5);
247
+ const char *zFMime = db_column_text(&q1, 6);
245248
char *zMsg;
246
- int nByte;
247249
cnt++;
248250
blob_append(&json, zSep, -1);
249251
zSep = ",\n";
250252
blob_appendf(&json, "{\"msgid\":%d,\"mtime\":\"%j\",", id, zDate);
251253
blob_appendf(&json, "\"xfrom\":\"%j\",", zFrom);
@@ -256,16 +258,13 @@
256258
** etc. */
257259
zMsg = mprintf("%h", zRawMsg);
258260
blob_appendf(&json, "\"xmsg\":\"%j\",", zMsg);
259261
fossil_free(zMsg);
260262
261
- nByte = db_column_bytes(&q1, 4);
262263
if( nByte==0 ){
263264
blob_appendf(&json, "\"fsize\":0}");
264265
}else{
265
- const char *zFName = db_column_text(&q1, 5);
266
- const char *zFMime = db_column_text(&q1, 6);
267266
blob_appendf(&json, "\"fsize\":%d,\"fname\":\"%j\",\"fmime\":\"%j\"}",
268267
nByte, zFName, zFMime);
269268
}
270269
}
271270
if( cnt ){
@@ -289,9 +288,26 @@
289288
** Download the CHAT.FILE attachment associated with a single chat
290289
** entry. The "name" query parameter begins with an integer that
291290
** identifies the particular chat message.
292291
*/
293292
void chat_download_webpage(void){
293
+ int msgid;
294
+ Blob r;
295
+ const char *zMime;
294296
login_check_credentials();
295
- if( !g.perm.Chat ) return;
297
+ if( !g.perm.Chat ){
298
+ style_header("Chat Not Authorized");
299
+ @ <h1>Not Authorized</h1>
300
+ @ <p>You do not have permission to use the chatroom on this
301
+ @ repository.</p>
302
+ style_finish_page();
303
+ return;
304
+ }
296305
chat_create_tables();
306
+ msgid = atoi(PD("name","0"));
307
+ blob_zero(&r);
308
+ zMime = db_text(0, "SELECT fmime FROM chat wHERE msgid=%d", msgid);
309
+ if( zMime==0 ) return;
310
+ db_blob(&r, "SELECT file FROM chat WHERE msgid=%d", msgid);
311
+ cgi_set_content_type(zMime);
312
+ cgi_set_content(&r);
297313
}
298314
--- src/chat.c
+++ src/chat.c
@@ -240,12 +240,14 @@
240 while( db_step(&q1)==SQLITE_ROW ){
241 int id = db_column_int(&q1, 0);
242 const char *zDate = db_column_text(&q1, 1);
243 const char *zFrom = db_column_text(&q1, 2);
244 const char *zRawMsg = db_column_text(&q1, 3);
 
 
 
245 char *zMsg;
246 int nByte;
247 cnt++;
248 blob_append(&json, zSep, -1);
249 zSep = ",\n";
250 blob_appendf(&json, "{\"msgid\":%d,\"mtime\":\"%j\",", id, zDate);
251 blob_appendf(&json, "\"xfrom\":\"%j\",", zFrom);
@@ -256,16 +258,13 @@
256 ** etc. */
257 zMsg = mprintf("%h", zRawMsg);
258 blob_appendf(&json, "\"xmsg\":\"%j\",", zMsg);
259 fossil_free(zMsg);
260
261 nByte = db_column_bytes(&q1, 4);
262 if( nByte==0 ){
263 blob_appendf(&json, "\"fsize\":0}");
264 }else{
265 const char *zFName = db_column_text(&q1, 5);
266 const char *zFMime = db_column_text(&q1, 6);
267 blob_appendf(&json, "\"fsize\":%d,\"fname\":\"%j\",\"fmime\":\"%j\"}",
268 nByte, zFName, zFMime);
269 }
270 }
271 if( cnt ){
@@ -289,9 +288,26 @@
289 ** Download the CHAT.FILE attachment associated with a single chat
290 ** entry. The "name" query parameter begins with an integer that
291 ** identifies the particular chat message.
292 */
293 void chat_download_webpage(void){
 
 
 
294 login_check_credentials();
295 if( !g.perm.Chat ) return;
 
 
 
 
 
 
 
296 chat_create_tables();
 
 
 
 
 
 
 
297 }
298
--- src/chat.c
+++ src/chat.c
@@ -240,12 +240,14 @@
240 while( db_step(&q1)==SQLITE_ROW ){
241 int id = db_column_int(&q1, 0);
242 const char *zDate = db_column_text(&q1, 1);
243 const char *zFrom = db_column_text(&q1, 2);
244 const char *zRawMsg = db_column_text(&q1, 3);
245 int nByte = db_column_bytes(&q1, 4);
246 const char *zFName = db_column_text(&q1, 5);
247 const char *zFMime = db_column_text(&q1, 6);
248 char *zMsg;
 
249 cnt++;
250 blob_append(&json, zSep, -1);
251 zSep = ",\n";
252 blob_appendf(&json, "{\"msgid\":%d,\"mtime\":\"%j\",", id, zDate);
253 blob_appendf(&json, "\"xfrom\":\"%j\",", zFrom);
@@ -256,16 +258,13 @@
258 ** etc. */
259 zMsg = mprintf("%h", zRawMsg);
260 blob_appendf(&json, "\"xmsg\":\"%j\",", zMsg);
261 fossil_free(zMsg);
262
 
263 if( nByte==0 ){
264 blob_appendf(&json, "\"fsize\":0}");
265 }else{
 
 
266 blob_appendf(&json, "\"fsize\":%d,\"fname\":\"%j\",\"fmime\":\"%j\"}",
267 nByte, zFName, zFMime);
268 }
269 }
270 if( cnt ){
@@ -289,9 +288,26 @@
288 ** Download the CHAT.FILE attachment associated with a single chat
289 ** entry. The "name" query parameter begins with an integer that
290 ** identifies the particular chat message.
291 */
292 void chat_download_webpage(void){
293 int msgid;
294 Blob r;
295 const char *zMime;
296 login_check_credentials();
297 if( !g.perm.Chat ){
298 style_header("Chat Not Authorized");
299 @ <h1>Not Authorized</h1>
300 @ <p>You do not have permission to use the chatroom on this
301 @ repository.</p>
302 style_finish_page();
303 return;
304 }
305 chat_create_tables();
306 msgid = atoi(PD("name","0"));
307 blob_zero(&r);
308 zMime = db_text(0, "SELECT fmime FROM chat wHERE msgid=%d", msgid);
309 if( zMime==0 ) return;
310 db_blob(&r, "SELECT file FROM chat WHERE msgid=%d", msgid);
311 cgi_set_content_type(zMime);
312 cgi_set_content(&r);
313 }
314
+4 -2
--- src/chat.js
+++ src/chat.js
@@ -38,10 +38,11 @@
3838
'-',ff.pad(d.getDate()),
3939
' ',ff.pad(d.getHours()),':',ff.pad(d.getMinutes()),
4040
':',ff.pad(d.getSeconds())
4141
].join('');
4242
};
43
+ const textNode = (T)=>document.createTextNode(T);
4344
function newcontent(jx){
4445
var i;
4546
for(i=0; i<jx.msgs.length; ++i){
4647
let m = jx.msgs[i];
4748
let row = document.createElement("fieldset");
@@ -67,11 +68,11 @@
6768
span.classList.add('message-content');
6869
row.appendChild(span);
6970
if( m.fsize>0 ){
7071
if( m.fmime && m.fmime.startsWith("image/") ){
7172
let img = document.createElement("img");
72
- img.src = "%string($downloadurl)/" + m.msgid;
73
+ img.src = "chat-download/" + m.msgid;
7374
span.appendChild(img);
7475
}else{
7576
let a = document.createElement("a");
7677
let txt = "(" + m.fname + " " + m.fsize + " bytes)";
7778
a.href = "%string($downloadurl)/" + m.msgid;
@@ -99,7 +100,8 @@
99100
fetch("chat-poll/" + mxMsg)
100101
.then(x=>x.json())
101102
.then(y=>newcontent(y))
102103
.finally(()=>poll.running=false)
103104
}
104
- // setInterval(poll, 1000);
105
+ poll();
106
+ setInterval(poll, 1000);
105107
})();
106108
--- src/chat.js
+++ src/chat.js
@@ -38,10 +38,11 @@
38 '-',ff.pad(d.getDate()),
39 ' ',ff.pad(d.getHours()),':',ff.pad(d.getMinutes()),
40 ':',ff.pad(d.getSeconds())
41 ].join('');
42 };
 
43 function newcontent(jx){
44 var i;
45 for(i=0; i<jx.msgs.length; ++i){
46 let m = jx.msgs[i];
47 let row = document.createElement("fieldset");
@@ -67,11 +68,11 @@
67 span.classList.add('message-content');
68 row.appendChild(span);
69 if( m.fsize>0 ){
70 if( m.fmime && m.fmime.startsWith("image/") ){
71 let img = document.createElement("img");
72 img.src = "%string($downloadurl)/" + m.msgid;
73 span.appendChild(img);
74 }else{
75 let a = document.createElement("a");
76 let txt = "(" + m.fname + " " + m.fsize + " bytes)";
77 a.href = "%string($downloadurl)/" + m.msgid;
@@ -99,7 +100,8 @@
99 fetch("chat-poll/" + mxMsg)
100 .then(x=>x.json())
101 .then(y=>newcontent(y))
102 .finally(()=>poll.running=false)
103 }
104 // setInterval(poll, 1000);
 
105 })();
106
--- src/chat.js
+++ src/chat.js
@@ -38,10 +38,11 @@
38 '-',ff.pad(d.getDate()),
39 ' ',ff.pad(d.getHours()),':',ff.pad(d.getMinutes()),
40 ':',ff.pad(d.getSeconds())
41 ].join('');
42 };
43 const textNode = (T)=>document.createTextNode(T);
44 function newcontent(jx){
45 var i;
46 for(i=0; i<jx.msgs.length; ++i){
47 let m = jx.msgs[i];
48 let row = document.createElement("fieldset");
@@ -67,11 +68,11 @@
68 span.classList.add('message-content');
69 row.appendChild(span);
70 if( m.fsize>0 ){
71 if( m.fmime && m.fmime.startsWith("image/") ){
72 let img = document.createElement("img");
73 img.src = "chat-download/" + m.msgid;
74 span.appendChild(img);
75 }else{
76 let a = document.createElement("a");
77 let txt = "(" + m.fname + " " + m.fsize + " bytes)";
78 a.href = "%string($downloadurl)/" + m.msgid;
@@ -99,7 +100,8 @@
100 fetch("chat-poll/" + mxMsg)
101 .then(x=>x.json())
102 .then(y=>newcontent(y))
103 .finally(()=>poll.running=false)
104 }
105 poll();
106 setInterval(poll, 1000);
107 })();
108

Keyboard Shortcuts

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