From 0abd5678247c319bf5e3aacb5b0aed897e8b0f22 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Sat, 19 Oct 2024 22:31:41 -0300 Subject: [PATCH] fix: duplicate pubkey of 'self' if zap tag --- src/controllers/api/statuses.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index e32509cc..3250fc19 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -205,12 +205,26 @@ const createStatusController: AppController = async (c) => { const lnurl = getLnurl(meta); const dittoZapSplit = await getZapSplits(store, Conf.pubkey); if (lnurl && dittoZapSplit) { - let totalSplit = 0; - for (const pubkey in dittoZapSplit) { - totalSplit += dittoZapSplit[pubkey].weight; - tags.push(['zap', pubkey, Conf.relay, dittoZapSplit[pubkey].weight.toString(), dittoZapSplit[pubkey].message]); + const totalSplit = Object.values(dittoZapSplit).reduce((total, { weight }) => total + weight, 0); + for (const zapPubkey in dittoZapSplit) { + if (zapPubkey === pubkey) { + tags.push([ + 'zap', + zapPubkey, + Conf.relay, + (Math.max(0, 100 - totalSplit) + dittoZapSplit[zapPubkey].weight).toString(), + ]); + continue; + } + tags.push([ + 'zap', + zapPubkey, + Conf.relay, + dittoZapSplit[zapPubkey].weight.toString(), + dittoZapSplit[zapPubkey].message, + ]); } - if (totalSplit) { + if (pubkey in dittoZapSplit === false) { tags.push(['zap', pubkey, Conf.relay, Math.max(0, 100 - totalSplit).toString()]); } }