mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 10:30:56 +00:00
Add a numerical suffix to names that are duplicates for existing pubkeys. Print longer names in the article window and article tree, and don't trim the names in the profiles file.
This commit is contained in:
parent
fa4acece82
commit
64a823e214
@ -122,7 +122,7 @@
|
||||
(with-redefs [rand-int (fn [_n] 12)]
|
||||
(let [bad-nicknames {1 "good-name"
|
||||
2 "bad name"
|
||||
3 "long-name0123456"
|
||||
3 "long-name0123456789"
|
||||
4 ""
|
||||
5 nil
|
||||
6 "洛奇安"}]
|
||||
@ -131,7 +131,7 @@
|
||||
(let [nicknames (read-string (slurp @config/nicknames-filename))]
|
||||
(should= {1 "good-name"
|
||||
2 "badname"
|
||||
3 "long-name012345"
|
||||
3 "long-name0123456789"
|
||||
4 "dud-12"
|
||||
5 "dud-12"
|
||||
6 "dudx-12"}
|
||||
|
@ -3,8 +3,7 @@
|
||||
[more-speech.nostr.events :refer :all]
|
||||
[more-speech.nostr.elliptic-signature :refer :all]
|
||||
[more-speech.nostr.util :refer :all]
|
||||
[more-speech.ui.swing.ui-context :refer :all]
|
||||
[more-speech.config :as config]))
|
||||
[more-speech.ui.swing.ui-context :refer :all]))
|
||||
|
||||
(defrecord event-handler-dummy []
|
||||
event-handler
|
||||
@ -398,17 +397,24 @@
|
||||
(should= "badname" (fix-name "bad name"))
|
||||
(should= "badname" (fix-name "bad.name")))
|
||||
|
||||
(it "should trim names to max length"
|
||||
(let [bad-name (apply str (repeat (inc config/user-name-max-length) \x))
|
||||
expected-name (apply str (repeat config/user-name-max-length \x))]
|
||||
(should= expected-name (fix-name bad-name)))
|
||||
)
|
||||
|
||||
(it "should create a random name for nils and empties"
|
||||
(with-redefs [rand-int (fn [_n] 12)]
|
||||
(should= "dud-12" (fix-name ""))
|
||||
)
|
||||
)
|
||||
(should= "dud-12" (fix-name ""))))
|
||||
|
||||
(it "should put a suffix on duplicate names."
|
||||
(let [profiles {1 {:name "unclebob"}}
|
||||
event-context (atom {:profiles profiles})]
|
||||
(reset! ui-context {:event-context event-context})
|
||||
(let [new-name (add-suffix-for-duplicate 2 "unclebob")]
|
||||
(prn new-name)
|
||||
(should (re-matches #"unclebob\d+" new-name)))))
|
||||
|
||||
(it "should put not put a suffix on previously existing names."
|
||||
(let [profiles {1 {:name "unclebob"}}
|
||||
event-context (atom {:profiles profiles})]
|
||||
(reset! ui-context {:event-context event-context})
|
||||
(let [new-name (add-suffix-for-duplicate 1 "unclebob")]
|
||||
(should= "unclebob" new-name))))
|
||||
)
|
||||
|
||||
(describe "process-name-event"
|
||||
|
@ -27,4 +27,3 @@
|
||||
|
||||
(def user-name-pattern #"\@[\w\-]+")
|
||||
(def user-name-chars #"[\w\-]+")
|
||||
(def user-name-max-length 15)
|
||||
|
@ -120,14 +120,14 @@
|
||||
(defn process-like [event-state _event]
|
||||
event-state)
|
||||
|
||||
(declare fix-name)
|
||||
(declare fix-name add-suffix-for-duplicate)
|
||||
(defn process-name-event [event-state {:keys [_id pubkey _created-at _kind _tags content _sig] :as event}]
|
||||
(try
|
||||
(let [profile (json/read-str content)
|
||||
name (get profile "name" "tilt")
|
||||
about (get profile "about" "")
|
||||
picture (get profile "picture" "")
|
||||
name (fix-name name)]
|
||||
name (add-suffix-for-duplicate pubkey (fix-name name))]
|
||||
(-> event-state
|
||||
(update-in [:profiles] assoc pubkey {:name name
|
||||
:about about
|
||||
@ -410,16 +410,22 @@
|
||||
(first pair)
|
||||
(recur (rest pairs))))))))
|
||||
|
||||
(defn add-suffix-for-duplicate [pubkey name]
|
||||
(let [profiles (:profiles @(:event-context @ui-context))
|
||||
others-profiles (dissoc profiles pubkey)
|
||||
profile-vals (vals others-profiles)
|
||||
dups (filter #(= name (:name %)) profile-vals)]
|
||||
(if (empty? dups)
|
||||
name
|
||||
(str name (rand-int 1000)))))
|
||||
|
||||
(defn fix-name [name]
|
||||
(if (empty? name)
|
||||
(str "dud-" (rand-int 100000))
|
||||
(str "dud-" (rand-int 1000000))
|
||||
(let [fixed-name (apply str
|
||||
(filter
|
||||
#(re-matches config/user-name-chars (str %))
|
||||
name))
|
||||
fixed-name (if (> (count fixed-name) config/user-name-max-length)
|
||||
(subs fixed-name 0 config/user-name-max-length)
|
||||
fixed-name)]
|
||||
name))]
|
||||
(if (empty? fixed-name)
|
||||
(str "dudx-" (rand-int 100000))
|
||||
fixed-name))))
|
@ -28,32 +28,16 @@
|
||||
lines (map #(str ">" %) lines)]
|
||||
(string/join "\n" lines)))
|
||||
|
||||
;(defn reformat-article [article width]
|
||||
; (let [first-line-end (.indexOf article "\n")
|
||||
; reply-line? (and (> first-line-end 0) (= \> (first article)))
|
||||
; blank-line (.lastIndexOf article "\n\n" width)
|
||||
; indentation (.indexOf article "\n ")
|
||||
; breakable-space (.lastIndexOf article " " width)
|
||||
; [break-point break-string skip]
|
||||
; (cond
|
||||
; reply-line? [first-line-end "\n" 1]
|
||||
; (< -1 indentation width) [indentation "\n " 2]
|
||||
; (>= blank-line 0) [blank-line "\n\n" 2]
|
||||
; (<= (count article) width) [(count article) "" 0]
|
||||
; (>= breakable-space 0) [breakable-space "\n" 1]
|
||||
; :else [width "\n" 0])]
|
||||
; (let [head (.substring article 0 break-point)
|
||||
; head (.replaceAll head "\n" " ")
|
||||
; tail (.substring article (+ skip break-point))]
|
||||
; (if (empty? tail)
|
||||
; head
|
||||
; (str head break-string (reformat-article tail width))))))
|
||||
(defn format-user-id
|
||||
([user-id]
|
||||
(format-user-id user-id 20))
|
||||
|
||||
(defn format-user-id [user-id]
|
||||
(let [profiles (:profiles @(:event-context @ui-context))]
|
||||
(if (nil? user-id)
|
||||
""
|
||||
(abbreviate (get-in profiles [user-id :name] (util/num32->hex-string user-id)) 20))))
|
||||
([user-id length]
|
||||
(let [profiles (:profiles @(:event-context @ui-context))]
|
||||
(if (nil? user-id)
|
||||
""
|
||||
(abbreviate (get-in profiles [user-id :name] (util/num32->hex-string user-id)) length))))
|
||||
)
|
||||
|
||||
(declare get-subject
|
||||
replace-references)
|
||||
@ -136,7 +120,7 @@
|
||||
(def url-pattern #"(?i)\b(?:(?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(?:(?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))*\))+(?:\(?:(?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))")
|
||||
|
||||
(defn linkify [url]
|
||||
(str "<a href=\"" url "\">" url "</a>"))
|
||||
(str "<a href=\"" url "\">" url "</a>"))
|
||||
|
||||
(defn segment-text-url [content]
|
||||
(let [url (re-find url-pattern content)]
|
||||
@ -159,11 +143,11 @@
|
||||
(let [segments (segment-text-url article)]
|
||||
(reduce
|
||||
(fn [formatted-content [seg-type seg]]
|
||||
(cond
|
||||
(= seg-type :text)
|
||||
(str formatted-content
|
||||
((comp break-newlines html-escape format-replies) seg))
|
||||
(= seg-type :url)
|
||||
(str formatted-content (linkify seg))))
|
||||
(cond
|
||||
(= seg-type :text)
|
||||
(str formatted-content
|
||||
((comp break-newlines html-escape format-replies) seg))
|
||||
(= seg-type :url)
|
||||
(str formatted-content (linkify seg))))
|
||||
""
|
||||
segments)))
|
||||
|
@ -107,7 +107,7 @@
|
||||
(text! article-area (formatters/reformat-article
|
||||
(formatters/replace-references event)))
|
||||
(text! (select main-frame [:#author-name-label])
|
||||
(formatters/format-user-id (:pubkey event)))
|
||||
(formatters/format-user-id (:pubkey event) 50))
|
||||
(text! (select main-frame [:#author-id-label])
|
||||
(util/num32->hex-string (:pubkey event)))
|
||||
(text! (select main-frame [:#created-time-label])
|
||||
|
Loading…
Reference in New Issue
Block a user