mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 10:30:56 +00:00
Add up/down buttons to article panel for sending reactions.
This commit is contained in:
parent
e4f59f50ab
commit
c96629c92f
@ -3,12 +3,10 @@
|
||||
[more-speech.db.gateway :as gateway]
|
||||
[more-speech.db.in-memory :as in-memory]
|
||||
[more-speech.nostr.contact-list :refer :all]
|
||||
[more-speech.nostr.util :as util]
|
||||
[more-speech.nostr.util :refer [hexify]]
|
||||
[more-speech.mem :refer :all]
|
||||
[more-speech.config :as config]))
|
||||
|
||||
(defn hexify [n] (util/num32->hex-string n))
|
||||
|
||||
(declare db)
|
||||
|
||||
(describe "contact-lists"
|
||||
|
@ -2,6 +2,7 @@
|
||||
(:require [speclj.core :refer :all]
|
||||
[more-speech.db.gateway :as gateway]
|
||||
[more-speech.db.in-memory :as in-memory]
|
||||
[more-speech.nostr.util :refer [hexify]]
|
||||
[more-speech.ui.formatters :refer :all]
|
||||
[more-speech.ui.formatter-util :refer :all]
|
||||
[more-speech.mem :refer :all]
|
||||
|
@ -1,8 +1,5 @@
|
||||
(ns more-speech.ui.swing.article-panel-spec
|
||||
(:require [speclj.core :refer :all]
|
||||
[more-speech.ui.swing.article-panel :refer :all]
|
||||
[more-speech.mem :refer :all]
|
||||
[more-speech.nostr.util :as util]))
|
||||
|
||||
(defn hexify [n] (util/num32->hex-string n))
|
||||
[more-speech.mem :refer :all]))
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
(:require [speclj.core :refer :all]
|
||||
[more-speech.ui.swing.article-tree :refer :all]
|
||||
[more-speech.ui.swing.article-tree-util :refer :all]
|
||||
[more-speech.nostr.util :as util]
|
||||
[more-speech.nostr.util :as util :refer [hexify]]
|
||||
[more-speech.mem :refer :all]
|
||||
[more-speech.ui.swing.article-panel :as article-panel]
|
||||
[more-speech.ui.swing.util :as swing-util]
|
||||
@ -12,8 +12,6 @@
|
||||
[more-speech.config :as config])
|
||||
(:import (javax.swing.tree DefaultMutableTreeNode)))
|
||||
|
||||
(defn hexify [n] (util/num32->hex-string n))
|
||||
|
||||
(declare db)
|
||||
|
||||
(describe "header tree"
|
||||
|
@ -42,7 +42,7 @@
|
||||
(defn make-contact-list-tag [contact-entry]
|
||||
(let [petname (get contact-entry :petname "")
|
||||
petname (if (nil? petname) "" petname)]
|
||||
[:p (events/hexify (:pubkey contact-entry)) "" petname]))
|
||||
[:p (hexify (:pubkey contact-entry)) "" petname]))
|
||||
|
||||
(defn make-contact-list-tags [contact-list]
|
||||
(map make-contact-list-tag contact-list))
|
||||
@ -58,12 +58,12 @@
|
||||
([reply-to root]
|
||||
(if (or (nil? root) (= root reply-to))
|
||||
(make-event-reference-tags reply-to)
|
||||
[[:e (events/hexify root) "" "root"] [:e (events/hexify reply-to) "" "reply"]]))
|
||||
[[:e (hexify root) "" "root"] [:e (hexify reply-to) "" "reply"]]))
|
||||
|
||||
([reply-to]
|
||||
(if (nil? reply-to)
|
||||
[]
|
||||
[[:e (events/hexify reply-to) "" "reply"]])))
|
||||
[[:e (hexify reply-to) "" "reply"]])))
|
||||
|
||||
(defn make-people-reference-tags [reply-to-or-nil]
|
||||
(if (nil? reply-to-or-nil)
|
||||
@ -73,11 +73,11 @@
|
||||
parent-tags (:tags parent-event)
|
||||
people-ids (map second (filter #(= :p (first %)) parent-tags))
|
||||
parent-author (:pubkey parent-event)
|
||||
people-ids (conj people-ids (events/hexify parent-author))
|
||||
people-ids (conj people-ids (hexify parent-author))
|
||||
my-pubkey (get-mem :pubkey)
|
||||
people-ids (if (= (:pubkey parent-event) my-pubkey)
|
||||
people-ids
|
||||
(remove #(= (events/hexify my-pubkey) %) people-ids))]
|
||||
(remove #(= (hexify my-pubkey) %) people-ids))]
|
||||
(map #(vector :p %) people-ids))))
|
||||
|
||||
(defn make-subject-tag [subject]
|
||||
@ -188,3 +188,12 @@
|
||||
|
||||
(defn compose-and-send-contact-list [contact-list]
|
||||
(send-event (compose-contact-list contact-list)))
|
||||
|
||||
(defn compose-and-send-reaction-event [subject-event polarity]
|
||||
(let [id (:id subject-event)
|
||||
pubkey (:pubkey subject-event)
|
||||
tags (concat (:tags subject-event) [[:e (hexify id)] [:p (hexify pubkey)]])
|
||||
body {:kind 7
|
||||
:tags tags
|
||||
:content polarity}]
|
||||
(send-event (body->event body))))
|
||||
|
@ -9,9 +9,6 @@
|
||||
|
||||
(def event-agent (agent nil))
|
||||
|
||||
(defn hexify [n]
|
||||
(util/num32->hex-string n))
|
||||
|
||||
(defn to-json [o]
|
||||
(json/write-str o :escape-slash false :escape-unicode false))
|
||||
|
||||
|
@ -44,6 +44,9 @@
|
||||
"converts a number to a 32 byte hex-string"
|
||||
(->> n (num->bytes 32) bytes->hex-string))
|
||||
|
||||
(defn hexify [n]
|
||||
(num32->hex-string n))
|
||||
|
||||
(defn bytes=
|
||||
"compares two byte arrays for equality."
|
||||
[^bytes b1 ^bytes b2]
|
||||
|
@ -1,6 +1,6 @@
|
||||
(ns more-speech.ui.formatters
|
||||
(:require [clojure.string :as string]
|
||||
[more-speech.nostr.util :as util]
|
||||
[more-speech.nostr.util :as util :refer [hexify]]
|
||||
[more-speech.mem :refer :all]
|
||||
[more-speech.nostr.events :as events]
|
||||
[more-speech.nostr.contact-list :as contact-list]
|
||||
@ -9,9 +9,6 @@
|
||||
[more-speech.db.gateway :as gateway])
|
||||
)
|
||||
|
||||
(defn hexify [bigint]
|
||||
(util/num32->hex-string bigint))
|
||||
|
||||
(defn format-user-id
|
||||
([user-id]
|
||||
(format-user-id user-id 20))
|
||||
|
@ -9,7 +9,8 @@
|
||||
[more-speech.mem :refer :all]
|
||||
[more-speech.ui.swing.util :as swing-util :refer [copy-to-clipboard]]
|
||||
[more-speech.db.gateway :as gateway]
|
||||
[more-speech.config :refer [get-db]])
|
||||
[more-speech.config :refer [get-db]]
|
||||
[more-speech.nostr.event-composers :as composers])
|
||||
(:use [seesaw core border]))
|
||||
|
||||
(defn bold-label [s]
|
||||
@ -28,6 +29,17 @@
|
||||
(copy-click e)
|
||||
(article-tree-util/id-click (config e :user-data))))
|
||||
|
||||
(defn reaction-click [polarity]
|
||||
(let [event-id (get-mem :selected-event)
|
||||
event (gateway/get-event (get-db) event-id)]
|
||||
(composers/compose-and-send-reaction-event event polarity)))
|
||||
|
||||
(defn up-click [_e]
|
||||
(reaction-click "+"))
|
||||
|
||||
(defn dn-click [_e]
|
||||
(reaction-click "-"))
|
||||
|
||||
(defn make-article-info-panel []
|
||||
(let [author-name-label (label :id :author-name-label)
|
||||
label-font (uconfig/get-small-font)
|
||||
@ -39,7 +51,9 @@
|
||||
subject-label (label :id :subject-label :font label-font)
|
||||
root-label (text :id :root-label :editable? false :font label-font)
|
||||
relays-popup (popup :enabled? false)
|
||||
relays-label (label :id :relays-label :user-data relays-popup)]
|
||||
relays-label (label :id :relays-label :user-data relays-popup)
|
||||
up-arrow (label :text "⬆" :id :up-arrow :font (uconfig/get-bold-font))
|
||||
dn-arrow (label :text "⬇" :id :dn-arrow :font (uconfig/get-bold-font))]
|
||||
(listen relays-label
|
||||
:mouse-entered (fn [e]
|
||||
(-> relays-popup
|
||||
@ -50,17 +64,22 @@
|
||||
(listen root-label :mouse-pressed id-click)
|
||||
(listen id-label :mouse-pressed copy-click)
|
||||
(listen author-id-label :mouse-pressed copy-click)
|
||||
(listen up-arrow :mouse-pressed up-click)
|
||||
(listen dn-arrow :mouse-pressed dn-click)
|
||||
(let [grid
|
||||
(grid-panel
|
||||
:columns 3
|
||||
:preferred-size [-1 :by 70] ;icky.
|
||||
:items [(flow-panel :align :left :items [(bold-label "Author:") author-name-label])
|
||||
:items [
|
||||
(flow-panel :align :left :items [up-arrow (bold-label "Author:") author-name-label])
|
||||
(flow-panel :align :left :items [(bold-label "Subject:") subject-label])
|
||||
(flow-panel :align :left :items [(bold-label "pubkey:") author-id-label])
|
||||
|
||||
(flow-panel :align :left :items [(bold-label "Created at:") created-time-label])
|
||||
(flow-panel :align :left :items [(bold-label "Reply to:") reply-to-label])
|
||||
(flow-panel :align :left :items [(bold-label "Relays:") relays-label])
|
||||
(flow-panel :align :left :items [(bold-label "id:") id-label])
|
||||
|
||||
(flow-panel :align :left :items [dn-arrow (bold-label "id:") id-label])
|
||||
(flow-panel :align :left :items [(bold-label "Citing:") citing-label])
|
||||
(flow-panel :align :left :items [(bold-label "Root:") root-label])])]
|
||||
grid)))
|
||||
|
Loading…
Reference in New Issue
Block a user