Attaching files to posts sort of works. Whew.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3799 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-01-28 03:11:09 +00:00
parent e84ced6f79
commit d77c452120
6 changed files with 53 additions and 5 deletions

View File

@ -421,6 +421,8 @@ core.register('message', async function(m) {
if (g_ready) {
await refresh(g_selected);
}
} else if (m.event == 'storeBlobComplete') {
await app.postMessage({storeBlobComplete: m.path});
} else if (m.event == 'focus' || m.event == 'blur') {
/* Shh. */
} else {

View File

@ -73,6 +73,9 @@
</div>
</md-card-content>
<md-card-actions>
<md-button class="md-icon-button" @click="attach">
<md-icon>attach_file</md-icon>
</md-button>
<md-menu>
<md-button md-menu-trigger>Share App</md-button>
<md-menu-content>

View File

@ -143,6 +143,14 @@ function processMessages() {
if (g_data.selected == g_data.whoami) {
updateEditUser();
}
} else if (key == 'storeBlobComplete') {
var blob = event.data.storeBlobComplete;
g_data.post_text = (g_data.post_text || '') + `\n![${blob.name}](${blob.path.substring(1)})`;
Vue.set(g_data.mentions, blob.path.substring(1), {
link: blob.path.substring(1),
name: blob.name,
type: blob.type,
});
} else {
g_data[key] = event.data[key];
}
@ -229,6 +237,26 @@ window.addEventListener('load', function() {
set_hash(hash) {
window.parent.postMessage({action: 'setHash', hash: hash ? hash : '#'}, '*');
},
attach() {
var input = document.createElement('input');
input.type = 'file';
input.onchange = function(event) {
var file = event.target.files[0];
file.arrayBuffer().then(function(buffer) {
console.log(buffer);
window.parent.postMessage({action: 'storeBlob',
blob: {
name: file.name,
type: file.type,
buffer: buffer,
}
}, '*');
}).catch(function(e) {
console.log('error', e);
});
};
input.click();
},
}
});
window.parent.postMessage('ready', '*');