summaryrefslogtreecommitdiff
path: root/app/lib/nostr
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-11-19 05:47:15 +0700
committerpolwex <polwex@sortug.com>2025-11-19 05:47:15 +0700
commite6e657be3a3b1dae426b46f3bc16f9a5cf4861c2 (patch)
tree8c04343c4b13861f2124b34f16652418e671e423 /app/lib/nostr
parent4bad4b5705144b6a537053c68c3c2c3f5984de85 (diff)
Improvements to handling nostr post on backend
Diffstat (limited to 'app/lib/nostr')
-rw-r--r--app/lib/nostr/client.hoon8
-rw-r--r--app/lib/nostr/events.hoon30
2 files changed, 31 insertions, 7 deletions
diff --git a/app/lib/nostr/client.hoon b/app/lib/nostr/client.hoon
index 259852e..2ed5b0a 100644
--- a/app/lib/nostr/client.hoon
+++ b/app/lib/nostr/client.hoon
@@ -47,9 +47,10 @@
++ get-user-feed
|= pubkey=@ux
=/ kinds (silt ~[1])
- :: =/ since (to-unix-secs:jikan:sr last-week)
+ :: =/ since (sub now.bowl ~d30)
+ =/ since (sub now.bowl ~d5)
=/ pubkeys (silt ~[pubkey])
- =/ =filter:nsur [~ `pubkeys `kinds ~ ~ ~ ~]
+ =/ =filter:nsur [~ `pubkeys `kinds ~ `since ~ ~]
(send-req ~[filter] `.n ~)
++ get-thread |= id=@ux
@@ -60,6 +61,7 @@
=/ tag ['e' ids]
=/ tags=(map @t (list @t)) (malt :~(tag))
=/ f2=filter:nsur [~ ~ `kinds `tags ~ ~ ~]
+ ~& >>> getting-thread=[f1 f2]
(send-req ~[f1 f2] `.n ~)
++ get-post |= id=@ux
@@ -139,7 +141,7 @@
++ send
|= [relay-url=@t req=client-msg:nsur] ^- card
- ~& >>> sendws=relay-url
+ ~& >>> sendws=[relay-url req]
=/ req-body=json (req:en:js req)
=/ octs (json-to-octs:server req-body)
=/ wmsg=websocket-message:eyre [1 `octs]
diff --git a/app/lib/nostr/events.hoon b/app/lib/nostr/events.hoon
index 16beabc..9182af3 100644
--- a/app/lib/nostr/events.hoon
+++ b/app/lib/nostr/events.hoon
@@ -14,13 +14,19 @@
== .y
$(fs t.fs)
+++ profs-req |= fs=(list filter:nsur) ^- ?
+ |- ?~ fs .n
+ =/ filter i.fs
+ ?~ kinds.filter .n
+ ?: (~(has in u.kinds.filter) 0) .y
+ $(fs t.fs)
+
++ user-req |= fs=(list filter:nsur) ^- (set @ux)
=| pubkeys=(set @ux)
|- ?~ fs pubkeys
=/ filter i.fs
?~ kinds.filter ~
?~ authors.filter ~
- ?: (~(has in u.kinds.filter) 0) ~
=? pubkeys
?& (~(has in u.kinds.filter) 1)
?=(%~ ids.filter)
@@ -100,6 +106,23 @@
=? ids ?=(^ ref) (~(put in ids) u.ref)
$(tags t.tags)
+++ build-event |= [=keys:nsur eny=@ time=@da content=@t] ^- event:nsur
+ =/ ts (to-unix-secs:jikan:sr time)
+ =/ raw=raw-event:nsur [pub.keys ts 1 ~ content]
+ =/ event-id (hash-event:nostr-keys raw)
+ =/ signature (sign-event:nostr-keys priv.keys event-id eny)
+ ~& hash-and-signed=[event-id signature]
+ =/ =event:nsur :*
+ event-id
+ pub.keys
+ created-at.raw
+ kind.raw
+ tags.raw
+ content.raw
+ signature
+ ==
+ event
+
++ post-to-event |= [=keys:nsur eny=@ p=post:post] ^- event:nsur
=/ cl (latest-post-content:trill contents.p)
=/ string (crip (content-list-to-md:trill cl))
@@ -122,11 +145,10 @@
++ event-to-post
|= [=event:nsur profile=(unit user-meta:nsur) relay=(unit @t)]
^- post-wrapper:sur
-
+ :: most people on nostr don't use markdown, they just spam links like retards
=/ cl (tokenize:trill content.event)
=/ ts (from-unix:jikan:sr created-at.event)
=/ cm=content-map:post (init-content-map:trill cl ts)
-
:: TODO more about @ps and stuff
=/ p=post:post :*
id=ts
@@ -139,7 +161,7 @@
read=*lock:gate
write=*lock:gate
*engagement:post
- 0v0
+ `@`id.event
*signature:post
tags=~
==