applesauce-common 7.1.0 → 7.1.1
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,9 +1,15 @@
|
|
|
1
1
|
import { EventFactory } from "applesauce-core/factories";
|
|
2
2
|
import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { type TextContentOptions } from "applesauce-core/operations/content";
|
|
3
4
|
export type LegacyMessageTemplate = KnownEventTemplate<kinds.EncryptedDirectMessage>;
|
|
4
5
|
export declare class LegacyMessageFactory extends EventFactory<kinds.EncryptedDirectMessage, LegacyMessageTemplate> {
|
|
5
|
-
|
|
6
|
-
static
|
|
6
|
+
/** Creates an encrypted message with optional public emoji tags */
|
|
7
|
+
static create(recipient: string, message: string, options?: Pick<TextContentOptions, "emojis">): LegacyMessageFactory;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an encrypted reply with optional public emoji tags
|
|
10
|
+
* @throws if the parent is not a legacy message
|
|
11
|
+
*/
|
|
12
|
+
static reply(parent: NostrEvent, recipient: string, message: string, options?: Pick<TextContentOptions, "emojis">): LegacyMessageFactory;
|
|
7
13
|
/** Sets the "p" tag of the user the message is addressed to */
|
|
8
14
|
recipient(pubkey: string): this;
|
|
9
15
|
/** Sets the parent message "e" tag for NIP-04 reply threading */
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
2
|
import { kinds } from "applesauce-core/helpers";
|
|
3
|
+
import { includeEmojis, setContent } from "applesauce-core/operations/content";
|
|
3
4
|
import { setMessageAddress, setMessageParent } from "../operations/legacy-message.js";
|
|
4
5
|
export class LegacyMessageFactory extends EventFactory {
|
|
5
|
-
|
|
6
|
+
/** Creates an encrypted message with optional public emoji tags */
|
|
7
|
+
static create(recipient, message, options) {
|
|
6
8
|
return new LegacyMessageFactory((res) => res(blankEventTemplate(kinds.EncryptedDirectMessage)))
|
|
7
9
|
.recipient(recipient)
|
|
10
|
+
.chain(setContent(message))
|
|
11
|
+
.chain(includeEmojis(options?.emojis))
|
|
8
12
|
.encryptedContent(recipient, message, "nip04");
|
|
9
13
|
}
|
|
10
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Creates an encrypted reply with optional public emoji tags
|
|
16
|
+
* @throws if the parent is not a legacy message
|
|
17
|
+
*/
|
|
18
|
+
static reply(parent, recipient, message, options) {
|
|
11
19
|
if (parent.kind !== kinds.EncryptedDirectMessage)
|
|
12
20
|
throw new Error("Parent must be a legacy message (kind 4)");
|
|
13
|
-
return
|
|
14
|
-
.recipient(recipient)
|
|
15
|
-
.encryptedContent(recipient, message, "nip04")
|
|
16
|
-
.replyTo(parent);
|
|
21
|
+
return LegacyMessageFactory.create(recipient, message, options).replyTo(parent);
|
|
17
22
|
}
|
|
18
23
|
/** Sets the "p" tag of the user the message is addressed to */
|
|
19
24
|
recipient(pubkey) {
|