Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Basic chat functionality seems to be on-line again. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | chatroom-dev |
| Files: | files | file ages | folders |
| SHA3-256: |
441ee6af06c98a280d5f86e66dba8a65 |
| User & Date: | drh 2020-12-23 01:33:23.496 |
Context
|
2020-12-23
| ||
| 02:24 | Chat message background color determined by username. ... (check-in: adb93ca980 user: drh tags: chatroom-dev) | |
| 01:33 | Basic chat functionality seems to be on-line again. ... (check-in: 441ee6af06 user: drh tags: chatroom-dev) | |
| 00:58 | Get the /chat-send and /chat-poll interfaces working. ... (check-in: 25828eb581 user: drh tags: chatroom-dev) | |
Changes
Changes to src/chat.c.
| ︙ | ︙ | |||
238 239 240 241 242 243 244 245 |
while(1){
int cnt = 0;
while( db_step(&q1)==SQLITE_ROW ){
int id = db_column_int(&q1, 0);
const char *zDate = db_column_text(&q1, 1);
const char *zFrom = db_column_text(&q1, 2);
const char *zRawMsg = db_column_text(&q1, 3);
char *zMsg;
| > > > < < < < | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
while(1){
int cnt = 0;
while( db_step(&q1)==SQLITE_ROW ){
int id = db_column_int(&q1, 0);
const char *zDate = db_column_text(&q1, 1);
const char *zFrom = db_column_text(&q1, 2);
const char *zRawMsg = db_column_text(&q1, 3);
int nByte = db_column_bytes(&q1, 4);
const char *zFName = db_column_text(&q1, 5);
const char *zFMime = db_column_text(&q1, 6);
char *zMsg;
cnt++;
blob_append(&json, zSep, -1);
zSep = ",\n";
blob_appendf(&json, "{\"msgid\":%d,\"mtime\":\"%j\",", id, zDate);
blob_appendf(&json, "\"xfrom\":\"%j\",", zFrom);
blob_appendf(&json, "\"uclr\":\"%j\",", hash_color(zFrom));
/* TBD: Convert the raw message into HTML, perhaps by running it
** through a text formatter, or putting markup on @name phrases,
** etc. */
zMsg = mprintf("%h", zRawMsg);
blob_appendf(&json, "\"xmsg\":\"%j\",", zMsg);
fossil_free(zMsg);
if( nByte==0 ){
blob_appendf(&json, "\"fsize\":0}");
}else{
blob_appendf(&json, "\"fsize\":%d,\"fname\":\"%j\",\"fmime\":\"%j\"}",
nByte, zFName, zFMime);
}
}
if( cnt ){
blob_append(&json, "\n]}", 3);
cgi_set_content(&json);
|
| ︙ | ︙ | |||
287 288 289 290 291 292 293 294 |
** WEBPAGE: chat-download
**
** Download the CHAT.FILE attachment associated with a single chat
** entry. The "name" query parameter begins with an integer that
** identifies the particular chat message.
*/
void chat_download_webpage(void){
login_check_credentials();
| > > > | > > > > > > > > > > > > > > | 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
** WEBPAGE: chat-download
**
** Download the CHAT.FILE attachment associated with a single chat
** entry. The "name" query parameter begins with an integer that
** identifies the particular chat message.
*/
void chat_download_webpage(void){
int msgid;
Blob r;
const char *zMime;
login_check_credentials();
if( !g.perm.Chat ){
style_header("Chat Not Authorized");
@ <h1>Not Authorized</h1>
@ <p>You do not have permission to use the chatroom on this
@ repository.</p>
style_finish_page();
return;
}
chat_create_tables();
msgid = atoi(PD("name","0"));
blob_zero(&r);
zMime = db_text(0, "SELECT fmime FROM chat wHERE msgid=%d", msgid);
if( zMime==0 ) return;
db_blob(&r, "SELECT file FROM chat WHERE msgid=%d", msgid);
cgi_set_content_type(zMime);
cgi_set_content(&r);
}
|
Changes to src/chat.js.
| ︙ | ︙ | |||
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
return [
d.getFullYear(),'-',ff.pad(d.getMonth()+1/*sigh*/),
'-',ff.pad(d.getDate()),
' ',ff.pad(d.getHours()),':',ff.pad(d.getMinutes()),
':',ff.pad(d.getSeconds())
].join('');
};
function newcontent(jx){
var i;
for(i=0; i<jx.msgs.length; ++i){
let m = jx.msgs[i];
let row = document.createElement("fieldset");
if( m.msgid>mxMsg ) mxMsg = m.msgid;
row.classList.add('message-row');
| > | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
return [
d.getFullYear(),'-',ff.pad(d.getMonth()+1/*sigh*/),
'-',ff.pad(d.getDate()),
' ',ff.pad(d.getHours()),':',ff.pad(d.getMinutes()),
':',ff.pad(d.getSeconds())
].join('');
};
const textNode = (T)=>document.createTextNode(T);
function newcontent(jx){
var i;
for(i=0; i<jx.msgs.length; ++i){
let m = jx.msgs[i];
let row = document.createElement("fieldset");
if( m.msgid>mxMsg ) mxMsg = m.msgid;
row.classList.add('message-row');
|
| ︙ | ︙ | |||
65 66 67 68 69 70 71 |
);
let span = document.createElement("div");
span.classList.add('message-content');
row.appendChild(span);
if( m.fsize>0 ){
if( m.fmime && m.fmime.startsWith("image/") ){
let img = document.createElement("img");
| | | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
);
let span = document.createElement("div");
span.classList.add('message-content');
row.appendChild(span);
if( m.fsize>0 ){
if( m.fmime && m.fmime.startsWith("image/") ){
let img = document.createElement("img");
img.src = "chat-download/" + m.msgid;
span.appendChild(img);
}else{
let a = document.createElement("a");
let txt = "(" + m.fname + " " + m.fsize + " bytes)";
a.href = "%string($downloadurl)/" + m.msgid;
a.appendChild(document.createTextNode(txt));
span.appendChild(a);
|
| ︙ | ︙ | |||
97 98 99 100 101 102 103 |
if(poll.running) return;
poll.running = true;
fetch("chat-poll/" + mxMsg)
.then(x=>x.json())
.then(y=>newcontent(y))
.finally(()=>poll.running=false)
}
| > | | 98 99 100 101 102 103 104 105 106 107 |
if(poll.running) return;
poll.running = true;
fetch("chat-poll/" + mxMsg)
.then(x=>x.json())
.then(y=>newcontent(y))
.finally(()=>poll.running=false)
}
poll();
setInterval(poll, 1000);
})();
|