diff --git a/src/more_speech/nostr/contact_list.clj b/src/more_speech/nostr/contact_list.clj index 5f4793c..51f22ae 100644 --- a/src/more_speech/nostr/contact_list.clj +++ b/src/more_speech/nostr/contact_list.clj @@ -1,11 +1,11 @@ (ns more-speech.nostr.contact-list - (:require [more-speech.nostr.util :as util] + (:require [more-speech.bech32 :as bech32] + [more-speech.config :refer [get-db]] + [more-speech.config :as config] + [more-speech.db.gateway :as gateway] [more-speech.logger.default :refer [log-pr]] [more-speech.mem :refer :all] - [more-speech.db.gateway :as gateway] - [more-speech.bech32 :as bech32] - [more-speech.config :refer [get-db]] - [more-speech.config :as config])) + [more-speech.nostr.util :as util])) (defn make-contact-from-tag [[_p pubkey relay petname]] @@ -39,18 +39,22 @@ (or (= candidate-pubkey my-pubkey) (contains? my-contact-pubkeys candidate-pubkey)))) -(defn which-contact-trusts [candidate-pubkey] +(defn- my-contact-trusts-candidate? [my-contact candidate-id] + (let [his-contacts (gateway/get-contacts (get-db) my-contact) + his-contact-ids (set (map :pubkey his-contacts))] + (contains? his-contact-ids candidate-id))) + +(defn which-contact-trusts [candidate-id] (let [my-pubkey (get-mem :pubkey) my-contacts (gateway/get-contacts (get-db) my-pubkey)] (loop [my-contact-ids (map :pubkey my-contacts)] - (if (empty? my-contact-ids) + (cond + (empty? my-contact-ids) nil - (let [my-contact (first my-contact-ids) - his-contacts (gateway/get-contacts (get-db) my-contact) - his-contact-ids (set (map :pubkey his-contacts))] - (if (contains? his-contact-ids candidate-pubkey) - my-contact - (recur (rest my-contact-ids)))))))) + (my-contact-trusts-candidate? (first my-contact-ids) candidate-id) + (first my-contact-ids) + :else + (recur (rest my-contact-ids)))))) (defn get-petname [his-pubkey] (let [my-pubkey (get-mem :pubkey) @@ -72,7 +76,7 @@ ([id] (let [contacts (gateway/get-contacts (get-db) id)] (set (concat [(get-mem :pubkey)] - (map :pubkey contacts)))))) + (map :pubkey contacts)))))) (defn get-web-of-trust ([] diff --git a/src/more_speech/nostr/event_dispatcher.clj b/src/more_speech/nostr/event_dispatcher.clj index 44078c2..65e7036 100644 --- a/src/more_speech/nostr/event_dispatcher.clj +++ b/src/more_speech/nostr/event_dispatcher.clj @@ -43,14 +43,9 @@ (set-mem :refresh-main-window true) (try (let [profile (json/read-str content) - name (get profile "name") + {:strs [name lud16 nip05 lud06 website banner]} profile about (get profile "about" "") picture (get profile "picture" "") - lud16 (get profile "lud16") - nip05 (get profile "nip05") - lud06 (get profile "lud06") - website (get profile "website") - banner (get profile "banner") display-name (get profile "display_name") possible-alias (if (empty? display-name) "" @@ -223,13 +218,15 @@ ;nip-42 authorization challenge. (defn handle-authorization-challenge [envelope url] (let [response-event (event-composers/body->event - {:kind 22242 - :tags [["relay" url] - ["challenge" (second envelope)]] - :content ""}) + {:kind 22242 + :tags [["relay" url] + ["challenge" (second envelope)]] + :content ""}) auth-event ["AUTH" (second response-event)] relay (relays/get-relay-for url)] - (relay/send relay auth-event))) + (if (nil? relay) + (log-pr 2 'handle-authorization-challenge 'nil-relay-for url) + (relay/send relay auth-event)))) (defn handle-unknown-notice-type [_envelope _url] ) @@ -281,11 +278,15 @@ (try (validate-and-process-event url envelope) (catch Exception e - (do (log-pr 1 'handle-event url (.getMessage e)) + (do (log-pr 1 'validate-and-process-event url (.getMessage e)) (log-pr 1 "--on event: " envelope))))) (defn handle-event [_agent envelope url] - (count-event url) - (if (not= "EVENT" (first envelope)) - (handle-notification envelope url) - (try-validate-and-process-event url envelope))) + (try + (count-event url) + (if (not= "EVENT" (first envelope)) + (handle-notification envelope url) + (try-validate-and-process-event url envelope)) + (catch Exception e + (do (log-pr 1 'handle-event url (.getMessage e)) + (log-pr 1 "--on event: " envelope))))) diff --git a/src/more_speech/nostr/protocol.clj b/src/more_speech/nostr/protocol.clj index 3009b31..2a4155e 100644 --- a/src/more_speech/nostr/protocol.clj +++ b/src/more_speech/nostr/protocol.clj @@ -233,7 +233,7 @@ [type id event] message] (cond - (= type "EVENT") ;nobody uses this right now... + (= type "EVENT") (update-mem [:active-subscriptions url id] count-event event) (= type "EOSE")