Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Implemented paste image into chat from clipboard. Fixed posted file download link but the files download with the same name as their message ID, which isn't very friendly. Not sure how to resolve that bit. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | chatroom-dev |
| Files: | files | file ages | folders |
| SHA3-256: |
eb7845f33982b3f14836db15d149d84c |
| User & Date: | stephan 2020-12-23 07:09:07.865 |
Context
|
2020-12-23
| ||
| 07:12 | Seem to have resolved the broken download names for chat-posted files. ... (check-in: b604154c38 user: stephan tags: chatroom-dev) | |
| 07:09 | Implemented paste image into chat from clipboard. Fixed posted file download link but the files download with the same name as their message ID, which isn't very friendly. Not sure how to resolve that bit. ... (check-in: eb7845f339 user: stephan tags: chatroom-dev) | |
| 06:26 | Chat message precise timestamps are now shown via a tap/click popup, rather than hoverhelp, for mobile compatibility. ... (check-in: 0101325f9d user: stephan tags: chatroom-dev) | |
Changes
Changes to src/chat.c.
| ︙ | ︙ | |||
103 104 105 106 107 108 109 110 111 112 113 114 115 116 | @ <input type="text" name="msg" id="sbox"\ @ placeholder="Type message here."> @ <input type="submit" value="Send"> @ </div> @ <div id='chat-input-file'> @ <span>File:</span> @ <input type="file" name="file"> @ </div> @ </div> @ </form> @ <hr> /* New chat messages get inserted immediately after this element */ @ <span id='message-inject-point'></span> | > > > > | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | @ <input type="text" name="msg" id="sbox"\ @ placeholder="Type message here."> @ <input type="submit" value="Send"> @ </div> @ <div id='chat-input-file'> @ <span>File:</span> @ <input type="file" name="file"> @ <div id='chat-pasted-image'> @ Or paste an image from clipboard, if supported by your @ environment.<br><img> @ </div> @ </div> @ </div> @ </form> @ <hr> /* New chat messages get inserted immediately after this element */ @ <span id='message-inject-point'></span> |
| ︙ | ︙ |
Changes to src/chat.js.
1 2 3 4 5 6 7 |
(function(){
const form = document.querySelector('#chat-form');
let mxMsg = 0;
const F = window.fossil;
const _me = F.user.name;
form.addEventListener('submit',(e)=>{
e.preventDefault();
| > > > > > > > > > | | > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
(function(){
const form = document.querySelector('#chat-form');
let mxMsg = 0;
const F = window.fossil;
const _me = F.user.name;
/* State for pasting an image from the clipboard */
const ImagePasteState = {
imgTag: document.querySelector('#chat-pasted-image img'),
blob: undefined
};
form.addEventListener('submit',(e)=>{
e.preventDefault();
const fd = new FormData(form);
if(ImagePasteState.blob/*replace file content with this*/){
fd.set("file", ImagePasteState.blob);
}
if( form.msg.value.length>0 || form.file.value.length>0 || ImagePasteState.blob ){
fetch("chat-send",{
method: 'POST',
body: fd
});
}
ImagePasteState.blob = undefined;
ImagePasteState.imgTag.removeAttribute('src');
form.msg.value = "";
form.file.value = "";
form.msg.focus();
});
/* Handle image paste from clipboard. TODO: confirm that we only
paste images here (silently ignore non-image data), or change the
related code to support non-image pasting/posting. */
document.onpaste = function(event){
const items = event.clipboardData.items;
ImagePasteState.blob = items[0].getAsFile();
const reader = new FileReader();
reader.onload = function(event){
ImagePasteState.imgTag.setAttribute('src', event.target.result);
};
reader.readAsDataURL(ImagePasteState.blob);
};
/* Injects element e as a new row in the chat, at the top of the list */
const injectMessage = function f(e){
if(!f.injectPoint){
f.injectPoint = document.querySelector('#message-inject-point');
}
if(f.injectPoint.nextSibling){
f.injectPoint.parentNode.insertBefore(e, f.injectPoint.nextSibling);
}else{
f.injectPoint.parentNode.appendChild(e);
}
};
/* Returns a new TEXT node with the given text content. */
const textNode = (T)=>document.createTextNode(T);
/** Returns the local time string of Date object d, defaulting
to the current time. */
const localTimeString = function ff(d){
if(!ff.pad){
ff.pad = (x)=>(''+x).length>1 ? x : '0'+x;
}
|
| ︙ | ︙ | |||
124 125 126 127 128 129 130 |
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)";
| | | | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
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 = window.fossil.rootPath+'chat-download/' + m.msgid;
a.appendChild(textNode(txt));
span.appendChild(a);
}
let br = document.createElement("br");
br.style.clear = "both";
span.appendChild(br);
}
if(m.xmsg){
|
| ︙ | ︙ |