More reliable addition of encrypted messages. There's something I'm not understanding with lit.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4440 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-09-02 02:06:29 +00:00
parent 088b44cc2c
commit e0110203e7
3 changed files with 42 additions and 29 deletions

View File

@ -124,7 +124,38 @@ class TfTabNewsFeedElement extends LitElement {
this.start_time,
last_start_time,
]);
this.messages = [...more, ...this.messages];
this.messages = await this.decrypt([...more, ...this.messages]);
}
async decrypt(messages) {
let result = [];
for (let message of messages) {
let content;
try {
content = JSON.parse(message?.content);
} catch {
}
if (typeof(content) === 'string') {
let decrypted;
try {
decrypted = await tfrpc.rpc.try_decrypt(this.whoami, content);
} catch {
}
if (decrypted) {
try {
message.decrypted = JSON.parse(decrypted);
} catch {
message.decrypted = decrypted;
}
}
}
result.push(message);
}
return result;
}
async add_messages(messages) {
this.messages = await this.decrypt([...messages, ...this.messages]);
}
render() {
@ -136,7 +167,7 @@ class TfTabNewsFeedElement extends LitElement {
this.messages = [];
this._messages_hash = this.hash;
this._messages_following = this.following;
this.fetch_messages().then(function(messages) {
this.fetch_messages().then(this.decrypt.bind(this)).then(function(messages) {
self.messages = messages;
console.log(`loading mesages done for ${self.whoami}`);
}).catch(function(error) {