mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-17 05:54:19 +01:00
43 lines
864 B
TypeScript
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;
|