fix copy profile raw data

This commit is contained in:
Martti Malmi 2023-03-14 11:57:51 +02:00
parent e99d30af8b
commit 3a5855979e
3 changed files with 20 additions and 6 deletions

View File

@ -160,6 +160,10 @@ const Events = {
if (existing && existing.created_at >= event.created_at) {
return;
}
if (existing) {
this.db.findAndRemove({ kind: 3, pubkey: event.pubkey });
}
this.insert(event);
SocialNetwork.followEventByUser.set(event.pubkey, event);
const myPub = Key.getPubKey();
@ -259,6 +263,9 @@ const Events = {
if (existing?.created_at >= event.created_at) {
return false;
}
if (existing) {
this.db.findAndRemove({ pubkey: event.pubkey, kind: 0 });
}
this.insert(event);
const profile = JSON.parse(event.content);
// if we have previously deleted our account, log out. appease app store.

View File

@ -20,8 +20,8 @@ export default {
],
followDistanceByUser: new Map<string, number>(),
usersByFollowDistance: new Map<number, Set<string>>(),
profileEventByUser: new Map<string, Event>(),
followEventByUser: new Map<string, Event>(),
profileEventByUser: new Map<string, Event>(), // TODO use Events.db instead
followEventByUser: new Map<string, Event>(), // TODO use Events.db instead
profiles: new Map<string, any>(),
followedByUser: new Map<string, Set<string>>(),
followersByUser: new Map<string, Set<string>>(),

View File

@ -21,6 +21,7 @@ import Key from '../nostr/Key';
import Relays from '../nostr/Relays';
import SocialNetwork from '../nostr/SocialNetwork';
import { translate as t } from '../translations/Translation';
import Events from '../nostr/Events';
import View from './View';
@ -110,10 +111,16 @@ class Profile extends View {
/>`;
}
let rawDataJson = [];
const profileEvent = SocialNetwork.profileEventByUser.get(this.state.hexPub);
const followEvent = SocialNetwork.followEventByUser.get(this.state.hexPub);
profileEvent && rawDataJson.push(profileEvent);
followEvent && rawDataJson.push(followEvent);
const profileEvent = Events.db.findOne({ kind: 0, pubkey: this.state.hexPub });
const followEvent = Events.db.findOne({ kind: 3, pubkey: this.state.hexPub });
if (profileEvent) {
delete profileEvent.$loki;
rawDataJson.push(profileEvent);
}
if (followEvent) {
delete followEvent.$loki;
rawDataJson.push(followEvent);
}
rawDataJson = JSON.stringify(rawDataJson, null, 2);
return html`
<div class="profile-top" key="${this.state.hexPub}details">