Fossil SCM

Simplified some JSON quoting in chat.c. Bypass the paste-from-clipboard handling if the paste target is the input text field, to avoid a console-level error when the text cannot be parsed as an image. TODO: figure out how to handle the paste-image case properly when the event target is the text input field.

stephan 2020-12-23 07:45 chatroom-dev
Commit 2fe8d7c4b1d271c58c756aa9a801c979f8f4f7c3ae3d7bb22ca52614570a7ce1
2 files changed +6 -6 +2
+6 -6
--- src/chat.c
+++ src/chat.c
@@ -106,11 +106,11 @@
106106
@ </div>
107107
@ <div id='chat-input-file'>
108108
@ <span>File:</span>
109109
@ <input type="file" name="file">
110110
@ <div id='chat-pasted-image'>
111
- @ Or paste an image from clipboard, if supported by your
111
+ @ Or paste an image from the clipboard, if supported by your
112112
@ environment.<br><img>
113113
@ </div>
114114
@ </div>
115115
@ </div>
116116
@ </form>
@@ -262,25 +262,25 @@
262262
const char *zFMime = db_column_text(&q1, 6);
263263
char *zMsg;
264264
cnt++;
265265
blob_append(&json, zSep, -1);
266266
zSep = ",\n";
267
- blob_appendf(&json, "{\"msgid\":%d,\"mtime\":\"%j\",", id, zDate);
268
- blob_appendf(&json, "\"xfrom\":\"%j\",", zFrom);
269
- blob_appendf(&json, "\"uclr\":\"%j\",", hash_color(zFrom));
267
+ blob_appendf(&json, "{\"msgid\":%d,\"mtime\":%!j,", id, zDate);
268
+ blob_appendf(&json, "\"xfrom\":%!j,", zFrom);
269
+ blob_appendf(&json, "\"uclr\":%!j,", hash_color(zFrom));
270270
271271
/* TBD: Convert the raw message into HTML, perhaps by running it
272272
** through a text formatter, or putting markup on @name phrases,
273273
** etc. */
274274
zMsg = mprintf("%h", zRawMsg);
275
- blob_appendf(&json, "\"xmsg\":\"%j\",", zMsg);
275
+ blob_appendf(&json, "\"xmsg\":%!j,", zMsg);
276276
fossil_free(zMsg);
277277
278278
if( nByte==0 ){
279279
blob_appendf(&json, "\"fsize\":0}");
280280
}else{
281
- blob_appendf(&json, "\"fsize\":%d,\"fname\":\"%j\",\"fmime\":\"%j\"}",
281
+ blob_appendf(&json, "\"fsize\":%d,\"fname\":%!j,\"fmime\":%!j}",
282282
nByte, zFName, zFMime);
283283
}
284284
}
285285
if( cnt ){
286286
blob_append(&json, "\n]}", 3);
287287
--- src/chat.c
+++ src/chat.c
@@ -106,11 +106,11 @@
106 @ </div>
107 @ <div id='chat-input-file'>
108 @ <span>File:</span>
109 @ <input type="file" name="file">
110 @ <div id='chat-pasted-image'>
111 @ Or paste an image from clipboard, if supported by your
112 @ environment.<br><img>
113 @ </div>
114 @ </div>
115 @ </div>
116 @ </form>
@@ -262,25 +262,25 @@
262 const char *zFMime = db_column_text(&q1, 6);
263 char *zMsg;
264 cnt++;
265 blob_append(&json, zSep, -1);
266 zSep = ",\n";
267 blob_appendf(&json, "{\"msgid\":%d,\"mtime\":\"%j\",", id, zDate);
268 blob_appendf(&json, "\"xfrom\":\"%j\",", zFrom);
269 blob_appendf(&json, "\"uclr\":\"%j\",", hash_color(zFrom));
270
271 /* TBD: Convert the raw message into HTML, perhaps by running it
272 ** through a text formatter, or putting markup on @name phrases,
273 ** etc. */
274 zMsg = mprintf("%h", zRawMsg);
275 blob_appendf(&json, "\"xmsg\":\"%j\",", zMsg);
276 fossil_free(zMsg);
277
278 if( nByte==0 ){
279 blob_appendf(&json, "\"fsize\":0}");
280 }else{
281 blob_appendf(&json, "\"fsize\":%d,\"fname\":\"%j\",\"fmime\":\"%j\"}",
282 nByte, zFName, zFMime);
283 }
284 }
285 if( cnt ){
286 blob_append(&json, "\n]}", 3);
287
--- src/chat.c
+++ src/chat.c
@@ -106,11 +106,11 @@
106 @ </div>
107 @ <div id='chat-input-file'>
108 @ <span>File:</span>
109 @ <input type="file" name="file">
110 @ <div id='chat-pasted-image'>
111 @ Or paste an image from the clipboard, if supported by your
112 @ environment.<br><img>
113 @ </div>
114 @ </div>
115 @ </div>
116 @ </form>
@@ -262,25 +262,25 @@
262 const char *zFMime = db_column_text(&q1, 6);
263 char *zMsg;
264 cnt++;
265 blob_append(&json, zSep, -1);
266 zSep = ",\n";
267 blob_appendf(&json, "{\"msgid\":%d,\"mtime\":%!j,", id, zDate);
268 blob_appendf(&json, "\"xfrom\":%!j,", zFrom);
269 blob_appendf(&json, "\"uclr\":%!j,", hash_color(zFrom));
270
271 /* TBD: Convert the raw message into HTML, perhaps by running it
272 ** through a text formatter, or putting markup on @name phrases,
273 ** etc. */
274 zMsg = mprintf("%h", zRawMsg);
275 blob_appendf(&json, "\"xmsg\":%!j,", zMsg);
276 fossil_free(zMsg);
277
278 if( nByte==0 ){
279 blob_appendf(&json, "\"fsize\":0}");
280 }else{
281 blob_appendf(&json, "\"fsize\":%d,\"fname\":%!j,\"fmime\":%!j}",
282 nByte, zFName, zFMime);
283 }
284 }
285 if( cnt ){
286 blob_append(&json, "\n]}", 3);
287
--- src/chat.js
+++ src/chat.js
@@ -28,10 +28,11 @@
2828
});
2929
/* Handle image paste from clipboard. TODO: confirm that we only
3030
paste images here (silently ignore non-image data), or change the
3131
related code to support non-image pasting/posting. */
3232
document.onpaste = function(event){
33
+ if(form.msg === event.target) return;
3334
const items = event.clipboardData.items;
3435
ImagePasteState.blob = items[0].getAsFile();
3536
const reader = new FileReader();
3637
reader.onload = function(event){
3738
ImagePasteState.imgTag.setAttribute('src', event.target.result);
@@ -177,10 +178,11 @@
177178
if(poll.running) return;
178179
poll.running = true;
179180
fetch("chat-poll/" + mxMsg)
180181
.then(x=>x.json())
181182
.then(y=>newcontent(y))
183
+ .catch(e=>console.error(e))
182184
.finally(()=>poll.running=false)
183185
}
184186
poll();
185187
setInterval(poll, 1000);
186188
})();
187189
--- src/chat.js
+++ src/chat.js
@@ -28,10 +28,11 @@
28 });
29 /* Handle image paste from clipboard. TODO: confirm that we only
30 paste images here (silently ignore non-image data), or change the
31 related code to support non-image pasting/posting. */
32 document.onpaste = function(event){
 
33 const items = event.clipboardData.items;
34 ImagePasteState.blob = items[0].getAsFile();
35 const reader = new FileReader();
36 reader.onload = function(event){
37 ImagePasteState.imgTag.setAttribute('src', event.target.result);
@@ -177,10 +178,11 @@
177 if(poll.running) return;
178 poll.running = true;
179 fetch("chat-poll/" + mxMsg)
180 .then(x=>x.json())
181 .then(y=>newcontent(y))
 
182 .finally(()=>poll.running=false)
183 }
184 poll();
185 setInterval(poll, 1000);
186 })();
187
--- src/chat.js
+++ src/chat.js
@@ -28,10 +28,11 @@
28 });
29 /* Handle image paste from clipboard. TODO: confirm that we only
30 paste images here (silently ignore non-image data), or change the
31 related code to support non-image pasting/posting. */
32 document.onpaste = function(event){
33 if(form.msg === event.target) return;
34 const items = event.clipboardData.items;
35 ImagePasteState.blob = items[0].getAsFile();
36 const reader = new FileReader();
37 reader.onload = function(event){
38 ImagePasteState.imgTag.setAttribute('src', event.target.result);
@@ -177,10 +178,11 @@
178 if(poll.running) return;
179 poll.running = true;
180 fetch("chat-poll/" + mxMsg)
181 .then(x=>x.json())
182 .then(y=>newcontent(y))
183 .catch(e=>console.error(e))
184 .finally(()=>poll.running=false)
185 }
186 poll();
187 setInterval(poll, 1000);
188 })();
189

Keyboard Shortcuts

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