Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions web/src/lib/Author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import {
replaceableKinds
} from './Constants';
import { bookmarkEvent, legacyBookmarkEvent } from './author/Bookmark';
import {
isAddressableEventDeleted,
isDeletedLegacyBookmarkEvent,
restoreLegacyBookmarkDeletionState
} from './author/Delete';
import { legacyProfileBadgesKey, setProfileBadgesEvent } from './author/ProfileBadges';
import { profileBadgesKind } from './ProfileBadgesEvent';
import { contactsOfFolloweesReqEmit } from './author/MuteAutomatically';
Expand Down Expand Up @@ -121,8 +126,13 @@ export class Author {
}

bookmarkEvent.set(replaceableEvents.get(Kind.BookmarkList));
const legacyBookmark = parameterizedReplaceableEvents.get(
`${Kind.Genericlists}:${legacyBookmarkIdentifier}`
);
legacyBookmarkEvent.set(
parameterizedReplaceableEvents.get(`${Kind.Genericlists}:${legacyBookmarkIdentifier}`)
legacyBookmark !== undefined && isAddressableEventDeleted(legacyBookmark)
? undefined
: legacyBookmark
);
setProfileBadgesEvent(
replaceableEvents.get(profileBadgesKind),
Expand Down Expand Up @@ -196,6 +206,7 @@ export class Author {
parameterizedReplaceableEvents: Map<string, Event>;
}> {
const storage = new WebStorage(localStorage);
await restoreLegacyBookmarkDeletionState(pubkey, storage);
const cachedAt = storage.getCachedAt();
if (cachedAt !== null) {
console.log('[cached at]', new Date(cachedAt * 1000));
Expand Down Expand Up @@ -232,7 +243,9 @@ export class Author {
storage.setReplaceableEvent(event);
}
for (const [, event] of [...parameterizedReplaceableEvents]) {
storage.setParameterizedReplaceableEvent(event);
if (!isDeletedLegacyBookmarkEvent(event)) {
storage.setParameterizedReplaceableEvent(event);
}
}
return { replaceableEvents, parameterizedReplaceableEvents };
}
Expand Down
25 changes: 16 additions & 9 deletions web/src/lib/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,29 @@ export async function decryptListContent(
pubkey: string,
content: string
): Promise<[tags: string[][], legacy: boolean]> {
if (content === '') {
return [[], false];
}

try {
const legacy = isLegacyEncryption(content);
const json = await (legacy
? Signer.decrypt(pubkey, content)
: Signer.decryptNip44(pubkey, content));
return [JSON.parse(json), legacy];
return await decryptListContentStrict(pubkey, content);
} catch (error) {
console.warn('[list parse error]', error);
return [[], false];
}
}

export async function decryptListContentStrict(
pubkey: string,
content: string
): Promise<[tags: string[][], legacy: boolean]> {
if (content === '') {
return [[], false];
}

const legacy = isLegacyEncryption(content);
const json = await (legacy
? Signer.decrypt(pubkey, content)
: Signer.decryptNip44(pubkey, content));
return [JSON.parse(json), legacy];
}

export async function encryptListContent(
tags: string[][],
legacy: boolean = false
Expand Down
4 changes: 4 additions & 0 deletions web/src/lib/WebStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class WebStorage {
}
}

public removeParameterizedReplaceableEvent(kind: number, identifier: string): void {
this.remove(`kind:${kind}:${identifier}`);
}

public getCachedAt(): number | null {
const cachedAt = this.get('cached_at');
return cachedAt === null ? null : Number(cachedAt);
Expand Down
Loading