mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
feat(views): render and return zap notification
This commit is contained in:
parent
729471d692
commit
96e99f38c4
1 changed files with 33 additions and 2 deletions
|
|
@ -1,13 +1,19 @@
|
||||||
import { NostrEvent } from '@nostrify/nostrify';
|
import { NostrEvent } from '@nostrify/nostrify';
|
||||||
|
|
||||||
|
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
import { nostrDate } from '@/utils.ts';
|
import { nostrDate } from '@/utils.ts';
|
||||||
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
|
||||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||||
|
|
||||||
interface RenderNotificationOpts {
|
export interface RenderNotificationOpts {
|
||||||
viewerPubkey: string;
|
viewerPubkey: string;
|
||||||
|
zap?: {
|
||||||
|
zapSender?: NostrEvent | NostrEvent['pubkey']; // kind 0 or pubkey
|
||||||
|
zappedPost?: NostrEvent;
|
||||||
|
amount?: number;
|
||||||
|
message?: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderNotification(event: DittoEvent, opts: RenderNotificationOpts) {
|
function renderNotification(event: DittoEvent, opts: RenderNotificationOpts) {
|
||||||
|
|
@ -32,6 +38,10 @@ function renderNotification(event: DittoEvent, opts: RenderNotificationOpts) {
|
||||||
if (event.kind === 30360 && event.pubkey === Conf.pubkey) {
|
if (event.kind === 30360 && event.pubkey === Conf.pubkey) {
|
||||||
return renderNameGrant(event);
|
return renderNameGrant(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.kind === 9735) {
|
||||||
|
return renderZap(event, opts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function renderMention(event: DittoEvent, opts: RenderNotificationOpts) {
|
async function renderMention(event: DittoEvent, opts: RenderNotificationOpts) {
|
||||||
|
|
@ -109,6 +119,27 @@ async function renderNameGrant(event: DittoEvent) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function renderZap(event: DittoEvent, opts: RenderNotificationOpts) {
|
||||||
|
if (!opts.zap?.zapSender) return;
|
||||||
|
|
||||||
|
const { amount = 0, message = '' } = opts.zap;
|
||||||
|
if (amount < 1) return;
|
||||||
|
|
||||||
|
const account = typeof opts.zap.zapSender !== 'string'
|
||||||
|
? await renderAccount(opts.zap.zapSender)
|
||||||
|
: await accountFromPubkey(opts.zap.zapSender);
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: notificationId(event),
|
||||||
|
type: 'ditto:zap',
|
||||||
|
amount,
|
||||||
|
message,
|
||||||
|
created_at: nostrDate(event.created_at).toISOString(),
|
||||||
|
account,
|
||||||
|
...(opts.zap?.zappedPost ? { status: await renderStatus(opts.zap?.zappedPost, opts) } : {}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/** This helps notifications be sorted in the correct order. */
|
/** This helps notifications be sorted in the correct order. */
|
||||||
function notificationId({ id, created_at }: NostrEvent): string {
|
function notificationId({ id, created_at }: NostrEvent): string {
|
||||||
return `${created_at}-${id}`;
|
return `${created_at}-${id}`;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue