ssb: Enough plumbing that if a blob is received, we will try to load the image again.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 32m24s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 32m24s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "tildefriends-app",
|
||||
"emoji": "🦀",
|
||||
"previous": "&x37oguxC9LPiOHrvaPmRGa2HNRDNB8QbulsKzdEefnE=.sha256"
|
||||
"previous": "&qtvUpu0Uh5EakeVlPgz9PZhDc9FY0TjWf5sAi1rX8SE=.sha256"
|
||||
}
|
||||
|
@@ -76,6 +76,9 @@ tfrpc.register(function setHash(hash) {
|
||||
core.register('onMessage', async function (id) {
|
||||
await tfrpc.rpc.notifyNewMessage(id);
|
||||
});
|
||||
core.register('onBlob', async function (id) {
|
||||
await tfrpc.rpc.notifyNewBlob(id);
|
||||
});
|
||||
tfrpc.register(async function store_blob(blob) {
|
||||
if (Array.isArray(blob)) {
|
||||
blob = Uint8Array.from(blob);
|
||||
|
@@ -65,6 +65,17 @@ class TfElement extends LitElement {
|
||||
tfrpc.register(async function notifyNewMessage(id) {
|
||||
await self.fetch_new_message(id);
|
||||
});
|
||||
tfrpc.register(async function notifyNewBlob(id) {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('blob-stored', {
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
detail: {
|
||||
id: id,
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
tfrpc.register(function set(name, value) {
|
||||
if (name === 'broadcasts') {
|
||||
self.broadcasts = value;
|
||||
|
@@ -45,11 +45,14 @@ class TfMessageElement extends LitElement {
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._click_callback = this.document_click.bind(this);
|
||||
this._blob_stored = this.blob_stored.bind(this);
|
||||
document.body.addEventListener('mouseup', this._click_callback);
|
||||
window.addEventListener('blob-stored', this._blob_stored);
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
window.removeEventListener('blob-stored', this._blob_stored);
|
||||
document.body.removeEventListener('mouseup', this._click_callback);
|
||||
}
|
||||
|
||||
@@ -61,6 +64,16 @@ class TfMessageElement extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
blob_stored(event) {
|
||||
let search = `/${event.detail.id}/view`;
|
||||
for (let img of this.shadowRoot.querySelectorAll('img')) {
|
||||
if (img.src.indexOf(search) != -1) {
|
||||
let src = img.src.split('?')[0];
|
||||
img.src = `${src}?${new Date().valueOf()}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
show_reply() {
|
||||
let event = new CustomEvent('tf-draft', {
|
||||
bubbles: true,
|
||||
|
@@ -693,6 +693,10 @@ ssb.addEventListener('message', function () {
|
||||
broadcastEvent('onMessage', [...arguments]);
|
||||
});
|
||||
|
||||
ssb.addEventListener('blob', function () {
|
||||
broadcastEvent('onBlob', [...arguments]);
|
||||
});
|
||||
|
||||
ssb.addEventListener('broadcasts', function () {
|
||||
broadcastEvent('onBroadcastsChanged', []);
|
||||
});
|
||||
|
@@ -976,7 +976,7 @@ static void _tf_ssb_db_blob_store_work(tf_ssb_t* ssb, void* user_data)
|
||||
static void _tf_ssb_db_blob_store_after_work(tf_ssb_t* ssb, int status, void* user_data)
|
||||
{
|
||||
blob_store_work_t* blob_work = user_data;
|
||||
if (status == 0 && *blob_work->id)
|
||||
if (status == 0 && *blob_work->id && blob_work->is_new)
|
||||
{
|
||||
tf_ssb_notify_blob_stored(ssb, blob_work->id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user