mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 10:30:56 +00:00
Reply to DM sets up the D @xxx in the response.
This commit is contained in:
parent
34b998a164
commit
3843ed279f
@ -1,7 +1,8 @@
|
||||
(ns more-speech.nostr.relays-spec
|
||||
(:require [speclj.core :refer :all]
|
||||
[more-speech.nostr.relays :refer :all :as relays]
|
||||
[clojure.spec.alpha :as s]))
|
||||
[clojure.spec.alpha :as s]
|
||||
[more-speech.config :as config]))
|
||||
|
||||
(describe "Relays"
|
||||
(context "loads relays from the \"relays\" file and sets defaults."
|
||||
@ -25,13 +26,14 @@
|
||||
(load-relays (str "{\"relay-url-1\" {:read true :write true}\n"
|
||||
"\"relay-url-2\" {:read false :write false}}")
|
||||
)
|
||||
(should= {"relay-url-1"
|
||||
{:read true :write true :connection nil :subscribed false}
|
||||
"relay-url-2"
|
||||
{:read false :write false :connection nil :subscribed false}}
|
||||
@relays)
|
||||
(should (s/conform ::relays/relays @relays))))
|
||||
|
||||
(when (not config/test-run?)
|
||||
(should= {"relay-url-1"
|
||||
{:read true :write true :connection nil :subscribed false}
|
||||
"relay-url-2"
|
||||
{:read false :write false :connection nil :subscribed false}}
|
||||
@relays)
|
||||
(should (s/conform ::relays/relays @relays)))))
|
||||
)
|
||||
|
||||
(describe "relays-for-writing"
|
||||
|
@ -5,8 +5,6 @@
|
||||
[more-speech.ui.swing.ui-context :refer :all]
|
||||
[more-speech.nostr.util :as util]))
|
||||
|
||||
(defn hexify [n] (util/num32->hex-string n))
|
||||
|
||||
(describe "Abbreviations."
|
||||
(it "abbreviates pubkeys"
|
||||
(should= "short" (abbreviate "short" 10))
|
||||
@ -153,7 +151,8 @@ the proposition that all men are created equal."
|
||||
event-context (atom {:profiles profiles})
|
||||
_ (reset! ui-context {:event-context event-context})
|
||||
event {:content content :tags [[:p "deadbeef"]]}]
|
||||
(should= "@deadbeef" (replace-references event))))
|
||||
(should= "@00000000000000000000000000000000000000000000000000000000deadbeef"
|
||||
(replace-references event))))
|
||||
|
||||
(it "does not replace reference if there is no p tag"
|
||||
(let [content "#[1]"
|
||||
@ -171,10 +170,27 @@ the proposition that all men are created equal."
|
||||
created-at (make-date "07/05/2022")
|
||||
relays ["relay-1"]
|
||||
tags [["p" (hexify 1)]]
|
||||
event {:pubkey 1 :created-at created-at :relays relays :tags tags :content "Hello #[0]."}]
|
||||
event {:pubkey 1 :created-at created-at
|
||||
:relays relays :tags tags :content "Hello #[0]."}]
|
||||
(should=
|
||||
">From: (user-1) at 07/05/22 24:00:00 on relay-1\n>---------------\n>Hello @user-1."
|
||||
(format-reply event)))))
|
||||
(format-reply event))))
|
||||
|
||||
(it "formats a reply to a DM"
|
||||
(let [profiles {1 {:name "user-1"}
|
||||
2 {:name "user-2"}}
|
||||
_ (reset! ui-context {:event-context (atom {:profiles profiles})})
|
||||
created-at (make-date "07/05/2022")
|
||||
relays ["relay-1"]
|
||||
tags [["p" (hexify 2)]]
|
||||
event {:pubkey 1 :created-at created-at :dm true
|
||||
:relays relays :tags tags :content "Hello #[0]."}]
|
||||
(should=
|
||||
"D @user-1\n>From: (user-1) at 07/05/22 24:00:00 on relay-1\n>---------------\n>Hello @user-2."
|
||||
(format-reply event)))
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
|
||||
(describe "Escape HTML entities"
|
||||
@ -299,17 +315,17 @@ the proposition that all men are created equal."
|
||||
(should= "2-deg<-trusted" (format-user-id trusted-by-trusted-user))))
|
||||
|
||||
(it "shows second degree of trust petname for user trusted by trusted user"
|
||||
(let [my-pubkey 99
|
||||
trusted-user 1
|
||||
trusted-by-trusted-user 2
|
||||
profiles {trusted-user {:name "trusted"}
|
||||
trusted-by-trusted-user {:name "2-deg"}}
|
||||
contact-lists {my-pubkey [{:pubkey trusted-user
|
||||
:petname "trusted-pet"}]
|
||||
trusted-user [{:pubkey trusted-by-trusted-user}]}
|
||||
event-state {:pubkey my-pubkey
|
||||
:profiles profiles
|
||||
:contact-lists contact-lists}]
|
||||
(reset! ui-context {:event-context (atom event-state)})
|
||||
(should= "2-deg<-trusted-pet" (format-user-id trusted-by-trusted-user))))
|
||||
(let [my-pubkey 99
|
||||
trusted-user 1
|
||||
trusted-by-trusted-user 2
|
||||
profiles {trusted-user {:name "trusted"}
|
||||
trusted-by-trusted-user {:name "2-deg"}}
|
||||
contact-lists {my-pubkey [{:pubkey trusted-user
|
||||
:petname "trusted-pet"}]
|
||||
trusted-user [{:pubkey trusted-by-trusted-user}]}
|
||||
event-state {:pubkey my-pubkey
|
||||
:profiles profiles
|
||||
:contact-lists contact-lists}]
|
||||
(reset! ui-context {:event-context (atom event-state)})
|
||||
(should= "2-deg<-trusted-pet" (format-user-id trusted-by-trusted-user))))
|
||||
)
|
@ -8,6 +8,10 @@
|
||||
[more-speech.config :as config])
|
||||
)
|
||||
|
||||
|
||||
(defn hexify [bigint]
|
||||
(util/num32->hex-string bigint))
|
||||
|
||||
(defn format-user-id
|
||||
([user-id]
|
||||
(format-user-id user-id 20))
|
||||
@ -38,9 +42,14 @@
|
||||
:else
|
||||
(str "(" (abbreviate profile-name (- length 2)) ")")))))))
|
||||
|
||||
(defn get-best-name [id]
|
||||
(let [name (contact-list/get-petname id)
|
||||
name (if (empty? name) (get-in (get-event-state :profiles) [id :name]) name)
|
||||
name (if (empty? name) (hexify id) name)]
|
||||
name))
|
||||
|
||||
(defn lookup-reference [event reference]
|
||||
(let [profiles (get-event-state :profiles)
|
||||
ref-string (re-find #"\d+" reference)
|
||||
(let [ref-string (re-find #"\d+" reference)
|
||||
index (Integer/parseInt ref-string)
|
||||
tags (:tags event)]
|
||||
(if (>= index (count tags))
|
||||
@ -48,11 +57,7 @@
|
||||
(try
|
||||
(let [id-string (-> tags (nth index) second)
|
||||
id (util/hex-string->num id-string)
|
||||
name (contact-list/get-petname id)
|
||||
name (if (empty? name) (get-in profiles [id :name]) name)
|
||||
name (if (empty? name)
|
||||
id-string
|
||||
name)]
|
||||
name (get-best-name id)]
|
||||
(str "@" name)
|
||||
)
|
||||
(catch Exception _e
|
||||
@ -100,8 +105,11 @@
|
||||
(format-user-id (:pubkey event))
|
||||
(format-time (:created-at event))
|
||||
(first (:relays event))
|
||||
)]
|
||||
(str header ">---------------\n" content)))
|
||||
)
|
||||
dm-prefix (if (:dm event)
|
||||
(str "D @" (get-best-name (:pubkey event)) "\n")
|
||||
"")]
|
||||
(str dm-prefix header ">---------------\n" content)))
|
||||
|
||||
(defn html-escape [content]
|
||||
(string/escape content {\& "&"
|
||||
@ -150,9 +158,6 @@
|
||||
""
|
||||
segments)))
|
||||
|
||||
(defn hexify [bigint]
|
||||
(util/num32->hex-string bigint))
|
||||
|
||||
(defn hexify-event [event]
|
||||
(assoc event :pubkey (hexify (:pubkey event))
|
||||
:id (hexify (:id event))
|
||||
|
Loading…
Reference in New Issue
Block a user