applesauce-core 0.0.0-next-20250628162548 → 0.0.0-next-20250630164258
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NostrEvent } from "nostr-tools";
|
|
1
2
|
import { Observable } from "rxjs";
|
|
2
3
|
import { IEventStoreStreams } from "../event-store/interface.js";
|
|
3
4
|
/** A symbol that is used to mark encrypted content as being from a cache */
|
|
@@ -11,5 +12,11 @@ export interface EncryptedContentCache {
|
|
|
11
12
|
export declare function markEncryptedContentFromCache<T extends object>(event: T): void;
|
|
12
13
|
/** Checks if the encrypted content is from a cache */
|
|
13
14
|
export declare function isEncryptedContentFromCache<T extends object>(event: T): boolean;
|
|
14
|
-
/**
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Starts a process that persists and restores all encrypted content
|
|
17
|
+
* @param eventStore - The event store to listen to
|
|
18
|
+
* @param storage - The storage to use
|
|
19
|
+
* @param fallback - A function that will be called when the encrypted content is not found in storage
|
|
20
|
+
* @returns A function that can be used to stop the process
|
|
21
|
+
*/
|
|
22
|
+
export declare function persistEncryptedContent(eventStore: IEventStoreStreams, storage: EncryptedContentCache | Observable<EncryptedContentCache>, fallback?: (event: NostrEvent) => any | Promise<any>): () => void;
|
|
@@ -15,9 +15,19 @@ export function isEncryptedContentFromCache(event) {
|
|
|
15
15
|
return Reflect.has(event, EncryptedContentFromCacheSymbol);
|
|
16
16
|
}
|
|
17
17
|
const log = logger.extend("EncryptedContentCache");
|
|
18
|
-
/**
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Starts a process that persists and restores all encrypted content
|
|
20
|
+
* @param eventStore - The event store to listen to
|
|
21
|
+
* @param storage - The storage to use
|
|
22
|
+
* @param fallback - A function that will be called when the encrypted content is not found in storage
|
|
23
|
+
* @returns A function that can be used to stop the process
|
|
24
|
+
*/
|
|
25
|
+
export function persistEncryptedContent(eventStore, storage, fallback) {
|
|
20
26
|
const storage$ = isObservable(storage) ? storage : of(storage);
|
|
27
|
+
// Get the encrypted content from storage or call the fallback
|
|
28
|
+
const getItem = async (storage, event) => {
|
|
29
|
+
return (await storage.getItem(event.id)) || (fallback ? await fallback(event) : null);
|
|
30
|
+
};
|
|
21
31
|
// Restore encrypted content when it is inserted
|
|
22
32
|
const restore = eventStore.insert$
|
|
23
33
|
.pipe(
|
|
@@ -26,7 +36,7 @@ export function persistEncryptedContent(eventStore, storage) {
|
|
|
26
36
|
// Get the encrypted content from storage
|
|
27
37
|
mergeMap((event) =>
|
|
28
38
|
// Wait for storage to be available
|
|
29
|
-
storage$.pipe(switchMap((storage) => combineLatest([of(event),
|
|
39
|
+
storage$.pipe(switchMap((storage) => combineLatest([of(event), getItem(storage, event)])), catchError((error) => {
|
|
30
40
|
log(`Failed to restore encrypted content for ${event.id}`, error);
|
|
31
41
|
return EMPTY;
|
|
32
42
|
}))))
|
|
@@ -52,7 +62,7 @@ export function persistEncryptedContent(eventStore, storage) {
|
|
|
52
62
|
// Get encrypted content from storage
|
|
53
63
|
mergeMap(([gift, seal]) =>
|
|
54
64
|
// Wait for storage to be available
|
|
55
|
-
storage$.pipe(switchMap((storage) => combineLatest([of(gift), of(seal),
|
|
65
|
+
storage$.pipe(switchMap((storage) => combineLatest([of(gift), of(seal), getItem(storage, seal)])), catchError((error) => {
|
|
56
66
|
log(`Failed to restore encrypted content for ${seal.id}`, error);
|
|
57
67
|
return EMPTY;
|
|
58
68
|
}))))
|
|
@@ -20,11 +20,18 @@ export function LegacyMessagesGroups(self) {
|
|
|
20
20
|
}
|
|
21
21
|
/** Returns all legacy direct messages in a group */
|
|
22
22
|
export function LegacyMessagesGroup(self, corraspondant) {
|
|
23
|
-
return (store) => store.timeline(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
return (store) => store.timeline([
|
|
24
|
+
{
|
|
25
|
+
kinds: [kinds.EncryptedDirectMessage],
|
|
26
|
+
"#p": [self],
|
|
27
|
+
authors: [corraspondant],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
kinds: [kinds.EncryptedDirectMessage],
|
|
31
|
+
"#p": [corraspondant],
|
|
32
|
+
authors: [self],
|
|
33
|
+
},
|
|
34
|
+
]);
|
|
28
35
|
}
|
|
29
36
|
/** Returns an array of legacy messages that have replies */
|
|
30
37
|
export function LegacyMessageThreads(self, corraspondant) {
|
|
@@ -37,10 +44,18 @@ export function LegacyMessageThreads(self, corraspondant) {
|
|
|
37
44
|
/** Returns all the legacy direct messages that are replies to a given message */
|
|
38
45
|
export function LegacyMessageReplies(self, message) {
|
|
39
46
|
const corraspondant = getLegacyMessageCorraspondant(message, self);
|
|
40
|
-
return (store) => store.timeline(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
return (store) => store.timeline([
|
|
48
|
+
{
|
|
49
|
+
kinds: [kinds.EncryptedDirectMessage],
|
|
50
|
+
"#p": [self],
|
|
51
|
+
authors: [corraspondant],
|
|
52
|
+
"#e": [message.id],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
kinds: [kinds.EncryptedDirectMessage],
|
|
56
|
+
"#p": [corraspondant],
|
|
57
|
+
authors: [self],
|
|
58
|
+
"#e": [message.id],
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
46
61
|
}
|
|
@@ -16,6 +16,7 @@ export function WrappedMessagesModel(self) {
|
|
|
16
16
|
map((rumors) => rumors
|
|
17
17
|
.map((gift) => getGiftWrapRumor(gift))
|
|
18
18
|
.filter((e) => !!e)
|
|
19
|
+
.filter((e) => e.kind === kinds.PrivateDirectMessage)
|
|
19
20
|
.sort((a, b) => b.created_at - a.created_at)));
|
|
20
21
|
}
|
|
21
22
|
/** A model that returns all conversations that a pubkey is participating in */
|