Fossil SCM
Basic chat functionality seems to be on-line again.
Commit
441ee6af06c98a280d5f86e66dba8a651068f2d0dac3127cc64bdfb5b5ce66ac
Parent
25828eb581d7599…
2 files changed
+21
-5
+4
-2
+21
-5
| --- src/chat.c | ||
| +++ src/chat.c | ||
| @@ -240,12 +240,14 @@ | ||
| 240 | 240 | while( db_step(&q1)==SQLITE_ROW ){ |
| 241 | 241 | int id = db_column_int(&q1, 0); |
| 242 | 242 | const char *zDate = db_column_text(&q1, 1); |
| 243 | 243 | const char *zFrom = db_column_text(&q1, 2); |
| 244 | 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); | |
| 245 | 248 | char *zMsg; |
| 246 | - int nByte; | |
| 247 | 249 | cnt++; |
| 248 | 250 | blob_append(&json, zSep, -1); |
| 249 | 251 | zSep = ",\n"; |
| 250 | 252 | blob_appendf(&json, "{\"msgid\":%d,\"mtime\":\"%j\",", id, zDate); |
| 251 | 253 | blob_appendf(&json, "\"xfrom\":\"%j\",", zFrom); |
| @@ -256,16 +258,13 @@ | ||
| 256 | 258 | ** etc. */ |
| 257 | 259 | zMsg = mprintf("%h", zRawMsg); |
| 258 | 260 | blob_appendf(&json, "\"xmsg\":\"%j\",", zMsg); |
| 259 | 261 | fossil_free(zMsg); |
| 260 | 262 | |
| 261 | - nByte = db_column_bytes(&q1, 4); | |
| 262 | 263 | if( nByte==0 ){ |
| 263 | 264 | blob_appendf(&json, "\"fsize\":0}"); |
| 264 | 265 | }else{ |
| 265 | - const char *zFName = db_column_text(&q1, 5); | |
| 266 | - const char *zFMime = db_column_text(&q1, 6); | |
| 267 | 266 | blob_appendf(&json, "\"fsize\":%d,\"fname\":\"%j\",\"fmime\":\"%j\"}", |
| 268 | 267 | nByte, zFName, zFMime); |
| 269 | 268 | } |
| 270 | 269 | } |
| 271 | 270 | if( cnt ){ |
| @@ -289,9 +288,26 @@ | ||
| 289 | 288 | ** Download the CHAT.FILE attachment associated with a single chat |
| 290 | 289 | ** entry. The "name" query parameter begins with an integer that |
| 291 | 290 | ** identifies the particular chat message. |
| 292 | 291 | */ |
| 293 | 292 | void chat_download_webpage(void){ |
| 293 | + int msgid; | |
| 294 | + Blob r; | |
| 295 | + const char *zMime; | |
| 294 | 296 | 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 | + } | |
| 296 | 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); | |
| 297 | 313 | } |
| 298 | 314 |
| --- 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 @@ | ||
| 38 | 38 | '-',ff.pad(d.getDate()), |
| 39 | 39 | ' ',ff.pad(d.getHours()),':',ff.pad(d.getMinutes()), |
| 40 | 40 | ':',ff.pad(d.getSeconds()) |
| 41 | 41 | ].join(''); |
| 42 | 42 | }; |
| 43 | + const textNode = (T)=>document.createTextNode(T); | |
| 43 | 44 | function newcontent(jx){ |
| 44 | 45 | var i; |
| 45 | 46 | for(i=0; i<jx.msgs.length; ++i){ |
| 46 | 47 | let m = jx.msgs[i]; |
| 47 | 48 | let row = document.createElement("fieldset"); |
| @@ -67,11 +68,11 @@ | ||
| 67 | 68 | span.classList.add('message-content'); |
| 68 | 69 | row.appendChild(span); |
| 69 | 70 | if( m.fsize>0 ){ |
| 70 | 71 | if( m.fmime && m.fmime.startsWith("image/") ){ |
| 71 | 72 | let img = document.createElement("img"); |
| 72 | - img.src = "%string($downloadurl)/" + m.msgid; | |
| 73 | + img.src = "chat-download/" + m.msgid; | |
| 73 | 74 | span.appendChild(img); |
| 74 | 75 | }else{ |
| 75 | 76 | let a = document.createElement("a"); |
| 76 | 77 | let txt = "(" + m.fname + " " + m.fsize + " bytes)"; |
| 77 | 78 | a.href = "%string($downloadurl)/" + m.msgid; |
| @@ -99,7 +100,8 @@ | ||
| 99 | 100 | fetch("chat-poll/" + mxMsg) |
| 100 | 101 | .then(x=>x.json()) |
| 101 | 102 | .then(y=>newcontent(y)) |
| 102 | 103 | .finally(()=>poll.running=false) |
| 103 | 104 | } |
| 104 | - // setInterval(poll, 1000); | |
| 105 | + poll(); | |
| 106 | + setInterval(poll, 1000); | |
| 105 | 107 | })(); |
| 106 | 108 |
| --- 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 |