forked from cory/tildefriends
Decrypt messages in the ssb app.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4299 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
5b8bdbb3e4
commit
10d4ae7dcc
@ -85,6 +85,9 @@ tfrpc.register(async function store_message(message) {
|
|||||||
tfrpc.register(function apps() {
|
tfrpc.register(function apps() {
|
||||||
return core.apps();
|
return core.apps();
|
||||||
});
|
});
|
||||||
|
tfrpc.register(async function try_decrypt(id, content) {
|
||||||
|
return await ssb.privateMessageDecrypt(id, content);
|
||||||
|
});
|
||||||
ssb.addEventListener('broadcasts', async function() {
|
ssb.addEventListener('broadcasts', async function() {
|
||||||
await tfrpc.rpc.set('broadcasts', await ssb.getBroadcasts());
|
await tfrpc.rpc.set('broadcasts', await ssb.getBroadcasts());
|
||||||
});
|
});
|
||||||
|
@ -14,6 +14,7 @@ class TfMessageElement extends LitElement {
|
|||||||
raw: {type: Boolean},
|
raw: {type: Boolean},
|
||||||
blog_data: {type: String},
|
blog_data: {type: String},
|
||||||
expanded: {type: Object},
|
expanded: {type: Object},
|
||||||
|
decrypted: {type: Object},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ class TfMessageElement extends LitElement {
|
|||||||
this.drafts = {};
|
this.drafts = {};
|
||||||
this.raw = false;
|
this.raw = false;
|
||||||
this.expanded = {};
|
this.expanded = {};
|
||||||
|
this.decrypted = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
show_reply() {
|
show_reply() {
|
||||||
@ -218,8 +220,15 @@ class TfMessageElement extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async try_decrypt(content) {
|
||||||
|
this.decrypted = JSON.parse(await tfrpc.rpc.try_decrypt(this.whoami, content));
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let content = this.message?.content;
|
let content = this.message?.content;
|
||||||
|
if (this.decrypted?.type == 'post') {
|
||||||
|
content = this.decrypted;
|
||||||
|
}
|
||||||
let self = this;
|
let self = this;
|
||||||
let raw_button = this.raw ?
|
let raw_button = this.raw ?
|
||||||
html`<input type="button" value="Message" @click=${() => self.raw = false}></input>` :
|
html`<input type="button" value="Message" @click=${() => self.raw = false}></input>` :
|
||||||
@ -328,6 +337,8 @@ class TfMessageElement extends LitElement {
|
|||||||
` :
|
` :
|
||||||
content_warning :
|
content_warning :
|
||||||
content_html;
|
content_html;
|
||||||
|
let is_encrypted = this.decrypted ? html`<span style="align-self: center">🔓</span>` : undefined;
|
||||||
|
let style_background = this.decrypted ? 'rgba(255, 0, 0, 0.2)' : 'rgba(255, 255, 255, 0.1)';
|
||||||
return html`
|
return html`
|
||||||
<style>
|
<style>
|
||||||
code {
|
code {
|
||||||
@ -343,9 +354,10 @@ class TfMessageElement extends LitElement {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<div style="border: 1px solid black; background-color: rgba(255, 255, 255, 0.1); margin-top: 8px; padding: 16px">
|
<div style="border: 1px solid black; background-color: ${style_background}; margin-top: 8px; padding: 16px">
|
||||||
<div style="display: flex; flex-direction: row">
|
<div style="display: flex; flex-direction: row">
|
||||||
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
||||||
|
${is_encrypted}
|
||||||
<span style="flex: 1"></span>
|
<span style="flex: 1"></span>
|
||||||
<span style="padding-right: 8px"><a target="_top" href=${'#' + self.message.id}>%</a> ${new Date(this.message.timestamp).toLocaleString()}</span>
|
<span style="padding-right: 8px"><a target="_top" href=${'#' + self.message.id}>%</a> ${new Date(this.message.timestamp).toLocaleString()}</span>
|
||||||
<span>${raw_button}</span>
|
<span>${raw_button}</span>
|
||||||
@ -430,7 +442,12 @@ class TfMessageElement extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
} else if (typeof(this.message.content) == 'string') {
|
} else if (typeof(this.message.content) == 'string') {
|
||||||
return small_frame(html`<span>🔒</span>`);
|
if (this.decrypted !== undefined) {
|
||||||
|
return small_frame(html`<span>🔓</span><pre>${JSON.stringify(this.decrypted, null, 2)}</pre>`);
|
||||||
|
} else {
|
||||||
|
this.try_decrypt(content);
|
||||||
|
return small_frame(html`<span>🔐</span>`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return small_frame(html`<div><b>type</b>: ${content.type}</div>`);
|
return small_frame(html`<div><b>type</b>: ${content.type}</div>`);
|
||||||
}
|
}
|
||||||
|
@ -759,7 +759,7 @@ async function blobHandler(request, response, blobId, uri) {
|
|||||||
sendData(response, data, type, headers);
|
sendData(response, data, type, headers);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sendData(response, data, type, {});
|
sendData(response, data, undefined, {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user