damus.io

damus.io website
git clone git://jb55.com/damus.io
Log | Files | Refs | README

commit 7c5fcc6dc570764b09b0c41dc7b9c7a9e3d2df49
parent c1531dc41cd8b52f0b708b441ed6d52266a1c50a
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 30 Oct 2022 10:09:11 -0700

convert emoji replies into reactions

simple way to do reactions

Diffstat:
Mwebv2/damus.js | 21++++++++++++++++++++-
Mwebv2/index.html | 2+-
2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/webv2/damus.js b/webv2/damus.js @@ -124,6 +124,9 @@ async function damus_web_init() function process_reaction_event(model, ev) { + if (!is_valid_reaction_content(ev.content)) + return + let last = {} for (const tag of ev.tags) { @@ -573,9 +576,21 @@ function render_pfp(pk, profile, size="normal") { return `<img class="pfp pfp-${size}" onerror="this.onerror=null;this.src='${robohash(pk)}';" src="${get_picture(pk, profile)}">` } +const REACTION_REGEX = /^(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])$/gi; +function is_emoji(str) +{ + return REACTION_REGEX.test(str) +} + +function is_valid_reaction_content(content) +{ + return content === "+" || content === "" || is_emoji(content) +} + function get_reaction_emoji(ev) { if (ev.content === "+" || ev.content === "") return "❤️" + return ev.content } @@ -657,7 +672,11 @@ function gather_reply_tags(pubkey, from) { async function create_reply(pubkey, content, from) { const tags = gather_reply_tags(pubkey, from) const created_at = Math.floor(new Date().getTime() / 1000) - const kind = from.kind + let kind = from.kind + + // convert emoji replies into reactions + if (is_valid_reaction_content(content)) + kind = 7 let reply = { pubkey, tags, content, created_at, kind } diff --git a/webv2/index.html b/webv2/index.html @@ -41,7 +41,7 @@ <script src="noble-secp256k1.js?v=1"></script> <script src="bech32.js?v=1"></script> <script src="nostr.js?v=5"></script> - <script src="damus.js?v=31"></script> + <script src="damus.js?v=32"></script> <script> // I have to delay loading to wait for nos2x const relay = setTimeout(damus_web_init, 100)