Reload article window every second to resolve references as they come in from the relays.

This commit is contained in:
Robert C. Martin 2023-05-08 16:11:36 -05:00
parent 6eae2c0a8d
commit 3f30ead8c9
6 changed files with 49 additions and 32 deletions

View File

@ -284,10 +284,10 @@
(it "returns a list of :text and :url and :namereference segments" (it "returns a list of :text and :url and :namereference segments"
(should= [[:text "Hey "] [:namereference "@bob"] [:text " Check this "] [:url "http://nostr.com"] [:text " It's cool"]] (should= [[:text "Hey "] [:namereference "@bob"] [:text " Check this "] [:url "http://nostr.com"] [:text " It's cool"]]
(segment-article "Hey @bob Check this http://nostr.com It's cool")) (segment-article "Hey @bob Check this http://nostr.com It's cool"))
(should= [[:nostrnpubreference "nostr:npub1qq"] [:text " "] [:nostrprofilereference "nostr:nprofile1qq"]] (should= [[:nostrnpubreference "nostr:npub1qq"]]
(segment-article "nostr:npub1qq nostr:nprofile1qq")) (segment-article "nostr:npub1qq"))
(should= [[:nostrnotereference "nostr:note1qq"] [:text " "] [:nostreventreference "nostr:nevent1qq"]] (should= [[:nostrnotereference "nostr:note1qq"]]
(segment-article "nostr:note1qq nostr:nevent1qq"))) (segment-article "nostr:note1qq")))
(it "extracts text from segments" (it "extracts text from segments"
(should= "name" (extract-reference "@name")) (should= "name" (extract-reference "@name"))
@ -341,12 +341,12 @@
(should= "<a href=\"ms-namereference://user1\">nostr:user1</a>" (should= "<a href=\"ms-namereference://user1\">nostr:user1</a>"
(reformat-article-into-html (str "nostr:" npub))))) (reformat-article-into-html (str "nostr:" npub)))))
(it "should replace nostr:nprofile with namereference link using user's name " ;(it "should replace nostr:nprofile with namereference link using user's name "
(let [user-id (rand-int 1000000000) ; (let [user-id (rand-int 1000000000)
npub (bech32/encode "nprofile" user-id)] ; npub (bech32/encode "nprofile" user-id)]
(gateway/add-profile @db user-id {:name "user1"}) ; (gateway/add-profile @db user-id {:name "user1"})
(should= "<a href=\"ms-namereference://user1\">nostr:user1</a>" ; (should= "<a href=\"ms-namereference://user1\">nostr:user1</a>"
(reformat-article-into-html (str "nostr:" npub))))) ; (reformat-article-into-html (str "nostr:" npub)))))
(it "should replace nostr:npub with namereference link using npub if user does not exist " (it "should replace nostr:npub with namereference link using npub if user does not exist "
(let [user-id (rand-int 1000000000) (let [user-id (rand-int 1000000000)
@ -355,12 +355,12 @@
npub "\">nostr:" npub "</a>") npub "\">nostr:" npub "</a>")
(reformat-article-into-html (str "nostr:" npub))))) (reformat-article-into-html (str "nostr:" npub)))))
(it "should replace nostr:nevent with notereference link" ;(it "should replace nostr:nevent with notereference link"
(let [user-id (rand-int 1000000000) ; (let [user-id (rand-int 1000000000)
npub (bech32/encode "nevent" user-id)] ; npub (bech32/encode "nevent" user-id)]
(should= (str "<a href=\"ms-notereference://" ; (should= (str "<a href=\"ms-notereference://"
npub "\">nostr:" npub "</a>") ; npub "\">nostr:" npub "</a>")
(reformat-article-into-html (str "nostr:" npub))))) ; (reformat-article-into-html (str "nostr:" npub)))))
(it "should replace nostr:note with notereference link" (it "should replace nostr:note with notereference link"
(let [user-id (rand-int 1000000000) (let [user-id (rand-int 1000000000)

View File

@ -46,6 +46,7 @@
(send-request request))) (send-request request)))
(defn request-profiles-and-contacts-for [authors] (defn request-profiles-and-contacts-for [authors]
(when (some? authors)
(let [authors (if (coll? authors) authors [authors]) (let [authors (if (coll? authors) authors [authors])
hexified-authors (map util/hexify authors) hexified-authors (map util/hexify authors)
trimmed-authors (if (<= (count hexified-authors) 100) trimmed-authors (if (<= (count hexified-authors) 100)
@ -55,8 +56,7 @@
request ["REQ" (str "ms-request-" r) request ["REQ" (str "ms-request-" r)
{"kinds" [0 3] {"kinds" [0 3]
"authors" trimmed-authors}]] "authors" trimmed-authors}]]
(send-request request) (send-request request))))
))
(defn request-batch [url id back-to filter] (defn request-batch [url id back-to filter]
(let [relay (get-in @relays [url :connection]) (let [relay (get-in @relays [url :connection])

View File

@ -225,9 +225,9 @@
([content segments] ([content segments]
(let [patterns [[:nostrnotereference config/nostr-note-reference-pattern] (let [patterns [[:nostrnotereference config/nostr-note-reference-pattern]
[:nostreventreference config/nostr-event-reference-pattern] ;[:nostreventreference config/nostr-event-reference-pattern]
[:nostrnpubreference config/nostr-npub-reference-pattern] [:nostrnpubreference config/nostr-npub-reference-pattern]
[:nostrprofilereference config/nostr-profile-reference-pattern] ;[:nostrprofilereference config/nostr-profile-reference-pattern]
[:nostrnamereference config/nostr-name-reference-pattern] [:nostrnamereference config/nostr-name-reference-pattern]
[:idreference config/id-reference-pattern] [:idreference config/id-reference-pattern]
[:namereference config/user-reference-pattern] [:namereference config/user-reference-pattern]
@ -287,6 +287,11 @@
(= seg-type :namereference) (= seg-type :namereference)
(str formatted-content (ms-linkify "ms-namereference" "@" (extract-reference seg))) (str formatted-content (ms-linkify "ms-namereference" "@" (extract-reference seg)))
(and (= seg-type :nostrnamereference)
(or (.startsWith seg ":nostr:nevent1")
(.startsWith seg ":nostr:nprofile1")))
seg
(= seg-type :nostrnamereference) (= seg-type :nostrnamereference)
(str formatted-content (ms-linkify "ms-namereference" "nostr:" (extract-reference seg))) (str formatted-content (ms-linkify "ms-namereference" "nostr:" (extract-reference seg)))

View File

@ -129,6 +129,13 @@
(defn dn-click [_e] (defn dn-click [_e]
(reaction-click "-")) (reaction-click "-"))
(declare load-article-info)
(defn reload-article []
(let [id (get-mem :article-window-event-id)]
(when (some? id)
(load-article-info id))))
(defn make-article-info-panel [] (defn make-article-info-panel []
(let [author-name-label (label :id :author-name-label) (let [author-name-label (label :id :author-name-label)
label-font (uconfig/get-small-font) label-font (uconfig/get-small-font)
@ -269,7 +276,9 @@
zap-items (map format-zap (:zaps event)) zap-items (map format-zap (:zaps event))
event-id (select main-frame [:#id-label]) event-id (select main-frame [:#id-label])
author-name-label (select main-frame [:#author-name-label])] author-name-label (select main-frame [:#author-name-label])]
(protocol/request-profiles-and-contacts-for (:pubkey event)) (when (not= (get-mem :article-window-event-id) selected-id)
(protocol/request-profiles-and-contacts-for (:pubkey event)))
(set-mem :article-window-event-id selected-id)
(text! reactions-label (str reactions)) (text! reactions-label (str reactions))
(if reacted? (if reacted?
(do (do

View File

@ -89,12 +89,15 @@
(run [] (tabs/prune-tabs))) (run [] (tabs/prune-tabs)))
repaint-task (proxy [TimerTask] [] repaint-task (proxy [TimerTask] []
(run [] (repaint-main-window))) (run [] (repaint-main-window)))
reload-article-task (proxy [TimerTask] []
(run [] (article-panel/reload-article)))
prune-tabs-frequency (* config/prune-tabs-frequency-in-minutes 60 1000)] prune-tabs-frequency (* config/prune-tabs-frequency-in-minutes 60 1000)]
(.schedule main-timer (.schedule main-timer
prune-tabs-task prune-tabs-task
(long prune-tabs-frequency) (long prune-tabs-frequency)
(long prune-tabs-frequency)) (long prune-tabs-frequency))
(.schedule main-timer repaint-task 1000 1000))) (.schedule main-timer repaint-task 1000 1000)
(.schedule main-timer reload-article-task 1000 1000)))
(defn setup-main-window [] (defn setup-main-window []
(setup-main-timer) (setup-main-timer)

View File

@ -223,7 +223,7 @@
selection-panel]) selection-panel])
user-window-timer (Timer. "User window timer") user-window-timer (Timer. "User window timer")
user-window-repaint-task (proxy [TimerTask] [] user-window-repaint-task (proxy [TimerTask] []
(run [] repaint-user-window users-frame))] (run [] (repaint-user-window users-frame)))]
(set-mem [:user-window :selection-group] :recent-user-items) (set-mem [:user-window :selection-group] :recent-user-items)
(load-user-window-data) (load-user-window-data)
(config! trusted-users-listbox :model (get-mem [:user-window :trusted-user-items])) (config! trusted-users-listbox :model (get-mem [:user-window :trusted-user-items]))