Files
rabbit/src/nostr/builder/createReaction.ts
Shusui MOYATANI 3d4eba023d feat: send zap
2024-01-13 18:09:01 +09:00

43 lines
864 B
TypeScript

import * as Kind from 'nostr-tools/kinds';
import { type UnsignedEvent } from 'nostr-tools/pure';
import { ReactionTypes } from '@/nostr/event/Reaction';
import epoch from '@/utils/epoch';
export type CreateReactionParams = {
pubkey: string;
eventId: string;
kind: number;
reactionTypes: ReactionTypes;
notifyPubkey: string;
};
// NIP-25
const createReaction = ({
pubkey,
eventId,
kind,
reactionTypes,
notifyPubkey,
}: CreateReactionParams): UnsignedEvent => {
const tags = [
['e', eventId, ''],
['p', notifyPubkey],
['k', kind.toString()],
];
if (reactionTypes.type === 'CustomEmoji') {
tags.push(['emoji', reactionTypes.shortcode, reactionTypes.url]);
}
return {
kind: Kind.Reaction,
pubkey,
created_at: epoch(),
tags,
content: reactionTypes.content,
};
};
export default createReaction;