mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 10:30:56 +00:00
Trust button in user show-info
This commit is contained in:
parent
5b0716c583
commit
ea9d070fba
@ -1,5 +1,6 @@
|
||||
(ns more-speech.nostr.trust-updater
|
||||
(:require
|
||||
[more-speech.bech32 :as bech32]
|
||||
[more-speech.config :as config]
|
||||
[more-speech.config :refer [get-db]]
|
||||
[more-speech.db.gateway :as gateway]
|
||||
@ -7,7 +8,7 @@
|
||||
[more-speech.nostr.event-composers :as composers]
|
||||
[more-speech.nostr.util :as util]
|
||||
[more-speech.ui.formatter-util :as f-util]
|
||||
)
|
||||
[more-speech.ui.formatters :as formatters])
|
||||
(:use [seesaw.core]))
|
||||
|
||||
(defn untrust [his-pubkey]
|
||||
@ -15,7 +16,8 @@
|
||||
my-contacts (gateway/get-contacts (get-db) my-pubkey)
|
||||
reduced-contacts (remove #(= his-pubkey (:pubkey %)) my-contacts)]
|
||||
(gateway/add-contacts (get-db) my-pubkey reduced-contacts)
|
||||
(gateway/sync-db (get-db)))
|
||||
(gateway/sync-db (get-db))
|
||||
reduced-contacts)
|
||||
)
|
||||
|
||||
(defn entrust [his-pubkey his-petname]
|
||||
@ -35,6 +37,10 @@
|
||||
(let [my-contact-list (entrust his-pubkey his-petname)]
|
||||
(composers/compose-and-send-contact-list my-contact-list)))
|
||||
|
||||
(defn untrust-and-send [his-pubkey]
|
||||
(let [my-contact-list (untrust his-pubkey)]
|
||||
(composers/compose-and-send-contact-list my-contact-list)))
|
||||
|
||||
(defn ask-for-petname [pubkey]
|
||||
(loop [profile (gateway/get-profile (get-db) pubkey)]
|
||||
(let [petname (input "Name this author"
|
||||
@ -51,6 +57,15 @@
|
||||
(do (alert (str "Invalid pet-name: " petname))
|
||||
(recur profile))))))
|
||||
|
||||
(defn verify-untrust [id]
|
||||
(let [untrusted-name (formatters/format-user-id id)
|
||||
question (dialog :content
|
||||
(str "Are you sure you want to untrust " untrusted-name
|
||||
"\nID: " (util/hexify id)
|
||||
"\n" (bech32/encode "npub" id))
|
||||
:option-type :ok-cancel)]
|
||||
(show! (pack! question))))
|
||||
|
||||
(defn trust-this-author [id]
|
||||
(let [petname (ask-for-petname id)]
|
||||
(when (some? petname)
|
||||
|
@ -51,16 +51,28 @@
|
||||
(protocol/request-note id)
|
||||
(swing-util/select-event id))))
|
||||
|
||||
(defn- trust [id]
|
||||
(let [petname (trust-updater/ask-for-petname id)]
|
||||
(when (some? petname)
|
||||
(trust-updater/entrust-and-send id petname))))
|
||||
|
||||
(defn- untrust [id]
|
||||
(when (= :success (trust-updater/verify-untrust id))
|
||||
(trust-updater/untrust-and-send id)))
|
||||
|
||||
(defn make-html-document [style body]
|
||||
(str "<head>" style "</head>"
|
||||
"<body>" body "</body>"))
|
||||
|
||||
(declare show-user-profile)
|
||||
|
||||
(defn show-profile [id profile]
|
||||
(let [created-at (:created-at profile)
|
||||
petname (contact-list/get-petname id)
|
||||
html-doc (make-html-document
|
||||
config/editor-pane-stylesheet
|
||||
(str "<h2> Name:</h2>" (:name profile)
|
||||
"<h2> Petname:</h2>" (contact-list/get-petname id)
|
||||
"<h2> Petname:</h2>" petname
|
||||
"<h2> Pubkey:</h2>" (util/hexify id)
|
||||
"<h2> About: </h2>" (:about profile)
|
||||
"<h2> Display name: </h2>" (:display-name profile)
|
||||
@ -78,13 +90,23 @@
|
||||
:editable? false
|
||||
:id :article-area
|
||||
:text html-doc)
|
||||
trust-button (button :text (if (some? petname) "Untrust" "Trust"))
|
||||
button-panel (flow-panel :items [trust-button])
|
||||
profile-panel (vertical-panel :items [button-panel (scrollable profile-pane)])
|
||||
profile-frame (frame :title (str "User Profile for " (:name profile))
|
||||
:content (scrollable profile-pane)
|
||||
:size [500 :by 600])]
|
||||
:content profile-panel)]
|
||||
(listen profile-pane :hyperlink open-link)
|
||||
|
||||
(show! profile-frame)))
|
||||
|
||||
(listen trust-button :mouse-pressed (if (some? petname)
|
||||
(fn [_e]
|
||||
(untrust id)
|
||||
(dispose! profile-frame)
|
||||
(future (show-user-profile id)))
|
||||
(fn [_e]
|
||||
(trust id)
|
||||
(dispose! profile-frame)
|
||||
(future (show-user-profile id))))
|
||||
(pack! profile-frame)
|
||||
(show! profile-frame))))
|
||||
|
||||
(defn show-user-profile [id]
|
||||
(when-let [profile (gateway/get-profile (get-db) id)]
|
||||
|
@ -1,7 +1,6 @@
|
||||
(ns more-speech.ui.swing.users-window
|
||||
(:require
|
||||
[clojure.set :as set]
|
||||
[more-speech.bech32 :as bech32]
|
||||
[more-speech.config :as config]
|
||||
[more-speech.config :refer [get-db]]
|
||||
[more-speech.db.gateway :as gateway]
|
||||
@ -140,15 +139,9 @@
|
||||
(let [untrusted-user (second selected-item)
|
||||
recent-button (select frame [:#recent-button])
|
||||
selected-listbox (select frame [:#selected-users])
|
||||
untrusted-name (formatters/format-user-id untrusted-user)
|
||||
question (dialog :content
|
||||
(str "Are you sure you want to untrust " untrusted-name
|
||||
"\nID: " (util/hexify untrusted-user)
|
||||
"\n" (bech32/encode "npub" untrusted-user))
|
||||
:option-type :ok-cancel)
|
||||
answer (show! (pack! question))]
|
||||
answer (trust-updater/verify-untrust untrusted-user)]
|
||||
(when (= answer :success)
|
||||
(trust-updater/untrust untrusted-user)
|
||||
(trust-updater/untrust-and-send untrusted-user)
|
||||
(load-trusted-users)
|
||||
(config! trusted-listbox :model (get-mem [:user-window :trusted-user-items]))
|
||||
(config! recent-button :selected? true)
|
||||
|
Loading…
Reference in New Issue
Block a user