fix #1518 and #1573 - removed potentially offensive words, made username generation deterministic, updated unit tests

This commit is contained in:
Goran Jovic 2017-08-01 17:52:08 +03:00 committed by Roman Volosovskyi
parent 8e22ce9466
commit 1ca35db17c
16 changed files with 263 additions and 285 deletions

View File

@ -305,9 +305,10 @@
(dispatch [::clear-chat-loaded-callbacks chat-id]))))) (dispatch [::clear-chat-loaded-callbacks chat-id])))))
(defn prepare-chat [{:contacts/keys [contacts]} chat-id chat] (defn prepare-chat [{:contacts/keys [contacts]} chat-id chat]
(let [name (get-in contacts [chat-id :name])] (let [name (get-in contacts [chat-id :name])
whisper-identity (get-in contacts [chat-id :whisper-identity])]
(merge {:chat-id chat-id (merge {:chat-id chat-id
:name (or name (generate-gfy)) :name (or name (generate-gfy whisper-identity))
:color default-chat-color :color default-chat-color
:group-chat false :group-chat false
:is-active true :is-active true

View File

@ -58,6 +58,7 @@
group-chat [:chat :group-id] group-chat [:chat :group-id]
name [:chat :name] name [:chat :name]
color [:chat :color] color [:chat :color]
public-key [:chat :public-key]
members [:current-chat-contacts]] members [:current-chat-contacts]]
(let [{:keys [status]} (if group-chat (let [{:keys [status]} (if group-chat
{:photo-path nil {:photo-path nil
@ -70,7 +71,7 @@
:font :default :font :default
:number-of-lines 1} :number-of-lines 1}
(if (str/blank? name) (if (str/blank? name)
(generate-gfy) (generate-gfy public-key)
(or (get-contact-translated chat-id :name name) (or (get-contact-translated chat-id :name name)
(label :t/chat-name)))] (label :t/chat-name)))]
(when (or status content) (when (or status content)

View File

@ -67,6 +67,7 @@
chat-id [:chat :chat-id] chat-id [:chat :chat-id]
contacts [:chat :contacts] contacts [:chat :contacts]
public? [:chat :public?] public? [:chat :public?]
public-key [:chat :public-key]
show-actions? [:chat-ui-props :show-actions?] show-actions? [:chat-ui-props :show-actions?]
accounts [:get :accounts] accounts [:get :accounts]
contact [:get-in [:contacts/contacts @chat-id]] contact [:get-in [:contacts/contacts @chat-id]]
@ -76,7 +77,7 @@
show-actions? show-actions?
creating?)) creating?))
(let [chat-name (if (str/blank? name) (let [chat-name (if (str/blank? name)
(generate-gfy) (generate-gfy public-key)
(or (get-contact-translated chat-id :name name) (or (get-contact-translated chat-id :name name)
(label :t/chat-name)))] (label :t/chat-name)))]
[text {:style st/chat-name-text [text {:style st/chat-name-text

View File

@ -21,7 +21,7 @@
(if (pos? (count (:name contact))) (if (pos? (count (:name contact)))
(get-contact-translated whisper-identity :name name) (get-contact-translated whisper-identity :name name)
;;TODO is this correct behaviour? ;;TODO is this correct behaviour?
(generate-gfy))] (generate-gfy whisper-identity))]
(when info (when info
[text {:style st/info-text} [text {:style st/info-text}
info])]])) info])]]))

View File

@ -47,13 +47,14 @@
[view [view
[ci/chat-icon (:photo-path account) {:size 52}]]]) [ci/chat-icon (:photo-path account) {:size 52}]]])
(defview name-input [placeholder] (defview name-input []
[account [:get-current-account] [account [:get-current-account]
new-name [:get-in [:profile-edit :name]]] new-name [:get-in [:profile-edit :name]]]
(let [current-name (:name account)] (let [current-name (:name account)
public-key (:public-key account)]
[view {:style st/name-input-wrapper} [view {:style st/name-input-wrapper}
[text-input [text-input
{:placeholder placeholder {:placeholder (gfycat/generate-gfy public-key)
:style (st/name-input-text (s/valid? ::profile.db/name (or new-name current-name))) :style (st/name-input-text (s/valid? ::profile.db/name (or new-name current-name)))
:font :medium :font :medium
:default-value (or new-name current-name) :default-value (or new-name current-name)
@ -169,20 +170,19 @@
(i18n/label :t/switch-users)]]]]) (i18n/label :t/switch-users)]]]])
(defn drawer [] (defn drawer []
(let [placeholder (gfycat/generate-gfy)] (fn []
(fn [] [touchable-without-feedback {:on-press #(dismiss-keyboard!)}
[touchable-without-feedback {:on-press #(dismiss-keyboard!)} [view st/drawer
[view st/drawer [view st/upper-container
[view st/upper-container [view st/profile-container
[view st/profile-container [profile-picture]
[profile-picture] [name-input]
[name-input placeholder] [status-input]
[status-input] [options-btn]]
[options-btn]] [current-network]]
[current-network]] [view
[view [unsigned-transactions]
[unsigned-transactions] [switch-account]]]]))
[switch-account]]]])))
(defn drawer-view [items] (defn drawer-view [items]
[drawer-layout {:drawerWidth 300 [drawer-layout {:drawerWidth 300

View File

@ -44,7 +44,7 @@
{:keys [public private]} (protocol/new-keypair!) {:keys [public private]} (protocol/new-keypair!)
account {:public-key public-key account {:public-key public-key
:address address :address address
:name (generate-gfy) :name (generate-gfy public-key)
:status (rand-nth statuses/data) :status (rand-nth statuses/data)
:signed-up? true :signed-up? true
:updates-public-key public :updates-public-key public

View File

@ -17,7 +17,7 @@
{:keys [public private]} (protocol/new-keypair!) {:keys [public private]} (protocol/new-keypair!)
account {:public-key public-key account {:public-key public-key
:address address :address address
:name (generate-gfy) :name (generate-gfy public-key)
:photo-path (identicon public-key) :photo-path (identicon public-key)
:updates-public-key public :updates-public-key public
:updates-private-key private :updates-private-key private

View File

@ -97,11 +97,11 @@
nil nil
st/opts-btn]])) st/opts-btn]]))
(defn chat-list-item-name [name group-chat? public?] (defn chat-list-item-name [name group-chat? public? public-key]
(let [private-group? (and group-chat? (not public?)) (let [private-group? (and group-chat? (not public?))
public-group? (and group-chat? public?) public-group? (and group-chat? public?)
chat-name (if (str/blank? name) chat-name (if (str/blank? name)
(generate-gfy) (generate-gfy public-key)
(truncate-str name 30))] (truncate-str name 30))]
[view st/name-view [view st/name-view
(when public-group? (when public-group?
@ -119,17 +119,17 @@
(defn chat-list-item-inner-view [{:keys [chat-id name color online (defn chat-list-item-inner-view [{:keys [chat-id name color online
group-chat contacts public? group-chat contacts public?
unremovable?] :as chat} public-key unremovable?] :as chat}
edit?] edit?]
(let [last-message (subscribe [:get-last-message chat-id]) (let [last-message (subscribe [:get-last-message chat-id])
name (or (get-contact-translated chat-id :name name) name (or (get-contact-translated chat-id :name name)
(generate-gfy))] (generate-gfy public-key))]
[view st/chat-container [view st/chat-container
[view st/chat-icon-container [view st/chat-icon-container
[chat-icon-view-chat-list chat-id group-chat name color online]] [chat-icon-view-chat-list chat-id group-chat name color online]]
[view st/chat-info-container [view st/chat-info-container
[view st/item-upper-container [view st/item-upper-container
[chat-list-item-name name group-chat public?] [chat-list-item-name name group-chat public? public-key]
(when (and (not edit?) @last-message) (when (and (not edit?) @last-message)
[view st/message-status-container [view st/message-status-container
[message-status chat @last-message] [message-status chat @last-message]

View File

@ -144,7 +144,7 @@
(fn [{:keys [contacts]}] (fn [{:keys [contacts]}]
(if (> (count contacts) 0) (if (> (count contacts) 0)
(let [{:keys [whisper-identity]} (first contacts) (let [{:keys [whisper-identity]} (first contacts)
contact {:name (generate-gfy) contact {:name (generate-gfy whisper-identity)
:address id :address id
:photo-path (identicon whisper-identity) :photo-path (identicon whisper-identity)
:whisper-identity whisper-identity}] :whisper-identity whisper-identity}]
@ -441,6 +441,6 @@
{::request-contacts-by-address id} {::request-contacts-by-address id}
{:dispatch (if (get-in db [:contacts/contacts id]) {:dispatch (if (get-in db [:contacts/contacts id])
[:add-pending-contact id] [:add-pending-contact id]
[:add-new-contact-and-open-chat {:name (generate-gfy) [:add-new-contact-and-open-chat {:name (generate-gfy id)
:photo-path (identicon id) :photo-path (identicon id)
:whisper-identity id}])}))) :whisper-identity id}])})))

View File

@ -1,9 +1,13 @@
(ns status-im.utils.gfycat.adjectives) (ns status-im.utils.gfycat.adjectives)
;Names are only deterministic as long as word lists do not change!
;If you change this list, please also update the tests at:
;
; - cljs/status_im/test/utils/gfycat/core.cljs
(def data (def data
["abandoned" ["able"
"able"
"absolute" "absolute"
"academic" "academic"
"acceptable" "acceptable"
@ -17,14 +21,13 @@
"adventurous" "adventurous"
"babyish" "babyish"
"back" "back"
"bad"
"baggy" "baggy"
"bare" "bare"
"barren"
"basic" "basic"
"beautiful" "beautiful"
"belated" "belated"
"beloved" "beloved"
"bitter"
"calculating" "calculating"
"calm" "calm"
"candid" "candid"
@ -38,7 +41,6 @@
"cavernous" "cavernous"
"celebrated" "celebrated"
"charming" "charming"
"damaged"
"damp" "damp"
"dangerous" "dangerous"
"dapper" "dapper"
@ -46,7 +48,6 @@
"dark" "dark"
"darling" "darling"
"dazzling" "dazzling"
"dead"
"deadly" "deadly"
"deafening" "deafening"
"dear" "dear"
@ -60,12 +61,12 @@
"ecstatic" "ecstatic"
"edible" "edible"
"educated" "educated"
"elderly"
"fabulous" "fabulous"
"failing" "failing"
"faint" "faint"
"fair" "fair"
"faithful" "faithful"
"fake"
"familiar" "familiar"
"famous" "famous"
"fancy" "fancy"
@ -96,42 +97,31 @@
"ideal" "ideal"
"idealistic" "idealistic"
"identical" "identical"
"idiotic"
"idle" "idle"
"idolized" "idolized"
"ignorant"
"ill" "ill"
"illegal"
"jaded" "jaded"
"jagged" "jagged"
"jampacked" "jampacked"
"kaleidoscopic" "kaleidoscopic"
"keen" "keen"
"lame"
"lanky" "lanky"
"large" "large"
"last" "last"
"lasting" "lasting"
"late"
"lavish" "lavish"
"lawful" "lawful"
"mad"
"madeup" "madeup"
"magnificent" "magnificent"
"majestic" "majestic"
"major" "major"
"male"
"mammoth" "mammoth"
"married"
"marvelous" "marvelous"
"married"
"naive" "naive"
"narrow" "narrow"
"nasty" "nasty"
"natural" "natural"
"naughty"
"obedient"
"obese"
"oblong"
"oblong" "oblong"
"obvious" "obvious"
"occasional" "occasional"
@ -160,7 +150,6 @@
"recent" "recent"
"reckless" "reckless"
"rectangular" "rectangular"
"sad"
"safe" "safe"
"salty" "salty"
"same" "same"
@ -171,7 +160,6 @@
"satisfied" "satisfied"
"scaly" "scaly"
"scarce" "scarce"
"scared"
"scary" "scary"
"scented" "scented"
"scholarly" "scholarly"
@ -181,12 +169,11 @@
"scrawny" "scrawny"
"second" "second"
"secondary" "secondary"
"secondhand"
"secret" "secret"
"selfassured" "selfassured"
"selfish"
"selfreliant" "selfreliant"
"sentimental" "sentimental"
"single"
"talkative" "talkative"
"tall" "tall"
"tame" "tame"
@ -198,11 +185,8 @@
"taut" "taut"
"tedious" "tedious"
"teeming" "teeming"
"ugly"
"ultimate" "ultimate"
"unacceptable"
"unaware" "unaware"
"uncomfortable"
"uncommon" "uncommon"
"unconscious" "unconscious"
"understated" "understated"
@ -222,10 +206,11 @@
"waterlogged" "waterlogged"
"watery" "watery"
"wavy" "wavy"
"weak"
"weird"
"yawning" "yawning"
"yearly" "yearly"
"zany" "zany"
"false"
"active" "active"
"actual" "actual"
"adept" "adept"
@ -247,9 +232,6 @@
"bighearted" "bighearted"
"biodegradable" "biodegradable"
"bitesized" "bitesized"
"bitter"
"black"
"cheap"
"cheerful" "cheerful"
"cheery" "cheery"
"chief" "chief"
@ -279,24 +261,17 @@
"elaborate" "elaborate"
"elastic" "elastic"
"elated" "elated"
"elderly"
"electric" "electric"
"elegant" "elegant"
"elementary" "elementary"
"elliptical" "elliptical"
"embarrassed"
"fast" "fast"
"fat"
"fatal" "fatal"
"fatherly"
"favorable" "favorable"
"favorite" "favorite"
"fearful"
"fearless" "fearless"
"feisty" "feisty"
"feline" "feline"
"female"
"feminine"
"few" "few"
"fickle" "fickle"
"gifted" "gifted"
@ -308,17 +283,14 @@
"gleeful" "gleeful"
"glistening" "glistening"
"glittering" "glittering"
"gross"
"hardtofind" "hardtofind"
"harmful" "harmful"
"harmless" "harmless"
"harmonious" "harmonious"
"harsh" "harsh"
"hasty" "hasty"
"hateful"
"haunting" "haunting"
"illfated"
"illinformed"
"illiterate"
"illustrious" "illustrious"
"imaginary" "imaginary"
"imaginative" "imaginative"
@ -332,7 +304,6 @@
"jittery" "jittery"
"key" "key"
"kind" "kind"
"lazy"
"leading" "leading"
"leafy" "leafy"
"lean" "lean"
@ -340,7 +311,6 @@
"legal" "legal"
"legitimate" "legitimate"
"light" "light"
"masculine"
"massive" "massive"
"mature" "mature"
"meager" "meager"
@ -358,7 +328,6 @@
"odd" "odd"
"oddball" "oddball"
"offbeat" "offbeat"
"offensive"
"official" "official"
"old" "old"
"periodic" "periodic"
@ -368,7 +337,6 @@
"pesky" "pesky"
"pessimistic" "pessimistic"
"petty" "petty"
"phony"
"physical" "physical"
"piercing" "piercing"
"pink" "pink"
@ -394,8 +362,6 @@
"shadowy" "shadowy"
"shady" "shady"
"shallow" "shallow"
"shameful"
"shameless"
"sharp" "sharp"
"shimmering" "shimmering"
"shiny" "shiny"
@ -407,35 +373,28 @@
"showy" "showy"
"shrill" "shrill"
"shy" "shy"
"sick"
"silent" "silent"
"silky" "silky"
"tempting" "tempting"
"tender" "tender"
"tense" "tense"
"tepid" "tepid"
"terrible"
"terrific" "terrific"
"testy" "testy"
"thankful" "thankful"
"that" "that"
"these" "these"
"tremendous"
"uneven" "uneven"
"unfinished" "unfinished"
"unfit"
"unfolded" "unfolded"
"unfortunate"
"unhappy"
"unhealthy"
"uniform" "uniform"
"unimportant"
"unique" "unique"
"valuable" "valuable"
"vapid" "vapid"
"variable" "variable"
"vast" "vast"
"velvety" "velvety"
"weak"
"wealthy" "wealthy"
"weary" "weary"
"webbed" "webbed"
@ -443,7 +402,6 @@
"weekly" "weekly"
"weepy" "weepy"
"weighty" "weighty"
"weird"
"welcome" "welcome"
"welldocumented" "welldocumented"
"yellow" "yellow"
@ -461,7 +419,6 @@
"alive" "alive"
"all" "all"
"altruistic" "altruistic"
"blackandwhite"
"bland" "bland"
"blank" "blank"
"blaring" "blaring"
@ -486,7 +443,6 @@
"competent" "competent"
"complete" "complete"
"delightful" "delightful"
"delirious"
"demanding" "demanding"
"dense" "dense"
"dental" "dental"
@ -507,7 +463,6 @@
"energetic" "energetic"
"enlightened" "enlightened"
"enormous" "enormous"
"filthy"
"fine" "fine"
"finished" "finished"
"firm" "firm"
@ -519,7 +474,6 @@
"flamboyant" "flamboyant"
"flashy" "flashy"
"flat" "flat"
"flawed"
"flawless" "flawless"
"flickering" "flickering"
"gloomy" "gloomy"
@ -538,13 +492,11 @@
"heavy" "heavy"
"hefty" "hefty"
"helpful" "helpful"
"helpless" "humongous"
"impartial" "impartial"
"impeccable" "impeccable"
"imperfect" "imperfect"
"imperturbable" "imperturbable"
"impish"
"impolite"
"important" "important"
"impossible" "impossible"
"impractical" "impractical"
@ -554,6 +506,7 @@
"joint" "joint"
"jolly" "jolly"
"jovial" "jovial"
"juvenile"
"kindhearted" "kindhearted"
"kindly" "kindly"
"lighthearted" "lighthearted"
@ -601,6 +554,7 @@
"polished" "polished"
"polite" "polite"
"political" "political"
"pungent"
"queasy" "queasy"
"querulous" "querulous"
"reliable" "reliable"
@ -617,8 +571,6 @@
"similar" "similar"
"simple" "simple"
"simplistic" "simplistic"
"sinful"
"single"
"sizzling" "sizzling"
"skeletal" "skeletal"
"skinny" "skinny"
@ -652,11 +604,8 @@
"united" "united"
"unkempt" "unkempt"
"unknown" "unknown"
"unlawful"
"unlined" "unlined"
"unlucky"
"unnatural" "unnatural"
"unpleasant"
"unrealistic" "unrealistic"
"venerated" "venerated"
"vengeful" "vengeful"
@ -675,6 +624,8 @@
"whimsical" "whimsical"
"whirlwind" "whirlwind"
"whispered" "whispered"
"worse"
"writhing"
"yellowish" "yellowish"
"zesty" "zesty"
"amazing" "amazing"
@ -722,13 +673,7 @@
"dimpled" "dimpled"
"dimwitted" "dimwitted"
"direct" "direct"
"disastrous"
"discrete" "discrete"
"disfigured"
"disgusting"
"disloyal"
"dismal"
"enraged"
"entire" "entire"
"envious" "envious"
"equal" "equal"
@ -762,14 +707,12 @@
"greedy" "greedy"
"green" "green"
"hidden" "hidden"
"hideous"
"high" "high"
"highlevel" "highlevel"
"hilarious" "hilarious"
"hoarse" "hoarse"
"hollow" "hollow"
"homely" "homely"
"impure"
"inborn" "inborn"
"incomparable" "incomparable"
"incompatible" "incompatible"
@ -790,17 +733,13 @@
"live" "live"
"lively" "lively"
"livid" "livid"
"loathsome"
"lone" "lone"
"lonely"
"long" "long"
"milky" "milky"
"mindless" "mindless"
"miniature" "miniature"
"minor" "minor"
"minty" "minty"
"miserable"
"miserly"
"misguided" "misguided"
"misty" "misty"
"mixed" "mixed"
@ -830,7 +769,6 @@
"prestigious" "prestigious"
"questionable" "questionable"
"quick" "quick"
"repulsive"
"revolving" "revolving"
"rewarding" "rewarding"
"rich" "rich"
@ -889,7 +827,6 @@
"vigorous" "vigorous"
"villainous" "villainous"
"violet" "violet"
"white"
"whole" "whole"
"whopping" "whopping"
"wicked" "wicked"
@ -912,7 +849,6 @@
"arid" "arid"
"aromatic" "aromatic"
"artistic" "artistic"
"ashamed"
"assured" "assured"
"astonishing" "astonishing"
"athletic" "athletic"
@ -937,12 +873,9 @@
"creamy" "creamy"
"creative" "creative"
"creepy" "creepy"
"criminal"
"crisp" "crisp"
"dirty" "dirty"
"disguised" "disguised"
"dishonest"
"dismal"
"distant" "distant"
"distant" "distant"
"distinct" "distinct"
@ -974,21 +907,17 @@
"friendly" "friendly"
"frightened" "frightened"
"frightening" "frightening"
"frigid"
"gregarious" "gregarious"
"grim" "grim"
"grimy" "grimy"
"gripping" "gripping"
"grizzled" "grizzled"
"gross"
"grotesque"
"grouchy" "grouchy"
"grounded" "grounded"
"honest" "honest"
"honorable" "honorable"
"honored" "honored"
"hopeful" "hopeful"
"horrible"
"hospitable" "hospitable"
"hot" "hot"
"huge" "huge"
@ -998,7 +927,6 @@
"informal" "informal"
"innocent" "innocent"
"insecure" "insecure"
"insidious"
"insignificant" "insignificant"
"insistent" "insistent"
"instructive" "instructive"
@ -1020,12 +948,10 @@
"modern" "modern"
"modest" "modest"
"moist" "moist"
"monstrous"
"monthly" "monthly"
"monumental" "monumental"
"moral" "moral"
"mortified" "mortified"
"motherly"
"motionless" "motionless"
"nocturnal" "nocturnal"
"noisy" "noisy"
@ -1081,7 +1007,6 @@
"stimulating" "stimulating"
"stingy" "stingy"
"stormy" "stormy"
"straight"
"strange" "strange"
"strict" "strict"
"strident" "strident"
@ -1093,10 +1018,8 @@
"tough" "tough"
"tragic" "tragic"
"trained" "trained"
"traumatic"
"treasured" "treasured"
"tremendous" "tremendous"
"tremendous"
"triangular" "triangular"
"tricky" "tricky"
"trifling" "trifling"
@ -1110,7 +1033,6 @@
"unwitting" "unwitting"
"unwritten" "unwritten"
"upbeat" "upbeat"
"violent"
"virtual" "virtual"
"virtuous" "virtuous"
"visible" "visible"
@ -1153,7 +1075,6 @@
"critical" "critical"
"crooked" "crooked"
"crowded" "crowded"
"cruel"
"crushing" "crushing"
"cuddly" "cuddly"
"cultivated" "cultivated"
@ -1169,11 +1090,8 @@
"drab" "drab"
"drafty" "drafty"
"dramatic" "dramatic"
"dreary"
"droopy"
"dry" "dry"
"dual" "dual"
"dull"
"dutiful" "dutiful"
"excited" "excited"
"exciting" "exciting"
@ -1203,17 +1121,13 @@
"growling" "growling"
"grown" "grown"
"grubby" "grubby"
"gruesome"
"grumpy" "grumpy"
"guilty" "guilty"
"gullible" "gullible"
"gummy" "gummy"
"humble" "humble"
"humiliating"
"humming" "humming"
"humongous"
"hungry" "hungry"
"hurtful"
"husky" "husky"
"intelligent" "intelligent"
"intent" "intent"
@ -1224,14 +1138,11 @@
"intrepid" "intrepid"
"ironclad" "ironclad"
"irresponsible" "irresponsible"
"irritating"
"itchy" "itchy"
"jumpy" "jumpy"
"junior" "junior"
"juvenile"
"known" "known"
"kooky" "kooky"
"kosher"
"low" "low"
"loyal" "loyal"
"lucky" "lucky"
@ -1243,12 +1154,10 @@
"mountainous" "mountainous"
"muddy" "muddy"
"muffled" "muffled"
"multicolored"
"mundane" "mundane"
"murky" "murky"
"mushy" "mushy"
"musty" "musty"
"muted"
"mysterious" "mysterious"
"noteworthy" "noteworthy"
"novel" "novel"
@ -1256,7 +1165,6 @@
"numb" "numb"
"nutritious" "nutritious"
"nutty" "nutty"
"onerlooked"
"outrageous" "outrageous"
"outstanding" "outstanding"
"oval" "oval"
@ -1268,12 +1176,10 @@
"proud" "proud"
"prudent" "prudent"
"punctual" "punctual"
"pungent"
"puny" "puny"
"pure" "pure"
"purple" "purple"
"pushy" "pushy"
"putrid"
"puzzled" "puzzled"
"puzzling" "puzzling"
"quirky" "quirky"
@ -1282,17 +1188,14 @@
"royal" "royal"
"rubbery" "rubbery"
"ruddy" "ruddy"
"rude"
"rundown" "rundown"
"runny" "runny"
"rural" "rural"
"rusty" "rusty"
"stupendous" "stupendous"
"stupid"
"sturdy" "sturdy"
"stylish" "stylish"
"subdued" "subdued"
"submissive"
"substantial" "substantial"
"subtle" "subtle"
"suburban" "suburban"
@ -1335,28 +1238,19 @@
"vivacious" "vivacious"
"vivid" "vivid"
"voluminous" "voluminous"
"worried"
"worrisome"
"worse"
"worst" "worst"
"worthless"
"worthwhile" "worthwhile"
"worthy" "worthy"
"wrathful" "wrathful"
"wretched"
"writhing"
"wrong"
"wry" "wry"
"yummy" "yummy"
"true" "true"
"aliceblue" "aliceblue"
"antiquewhite"
"aqua" "aqua"
"aquamarine" "aquamarine"
"azure" "azure"
"beige" "beige"
"bisque" "bisque"
"black"
"blanchedalmond" "blanchedalmond"
"blue" "blue"
"blueviolet" "blueviolet"
@ -1499,7 +1393,6 @@
"violet" "violet"
"violetred" "violetred"
"wheat" "wheat"
"white"
"whitesmoke" "whitesmoke"
"yellow" "yellow"
"yellowgreen"]) "yellowgreen"])

View File

@ -1,5 +1,11 @@
(ns status-im.utils.gfycat.animals) (ns status-im.utils.gfycat.animals)
;Names are only deterministic as long as word lists do not change!
;If you change this list, please also update the tests at:
;
; - cljs/status_im/test/utils/gfycat/core.cljs
(def data (def data
["aardvark" ["aardvark"
"aardwolf" "aardwolf"
@ -20,36 +26,36 @@
"adouri" "adouri"
"aegeancat" "aegeancat"
"affenpinscher" "affenpinscher"
"afghanhound" "hound"
"africanaugurbuzzard" "augurbuzzard"
"africanbushviper" "bushviper"
"africancivet" "civet"
"africanclawedfrog" "clawedfrog"
"africanelephant" "elephant"
"africanfisheagle" "fisheagle"
"africangoldencat" "goldencat"
"africangroundhornbill" "groundhornbill"
"africanharrierhawk" "harrierhawk"
"africanhornbill" "hornbill"
"africanjacana" "jacana"
"africanmolesnake" "molesnake"
"africanparadiseflycatcher" "paradiseflycatcher"
"africanpiedkingfisher" "piedkingfisher"
"africanporcupine" "porcupine"
"africanrockpython" "rockpython"
"africanwildcat" "wildcat"
"africanwilddog" "wilddog"
"agama" "agama"
"agouti" "agouti"
"aidi" "aidi"
"airedale" "airedale"
"airedaleterrier" "airedaleterrier"
"akitainu" "akitainu"
"alabamamapturtle" "mapturtle"
"alaskajingle" "jingle"
"alaskanhusky" "husky"
"alaskankleekai" "kleekai"
"alaskanmalamute" "malamute"
"albacoretuna" "albacoretuna"
"albatross" "albatross"
"albertosaurus" "albertosaurus"
@ -70,36 +76,36 @@
"amazontreeboa" "amazontreeboa"
"amberpenshell" "amberpenshell"
"ambushbug" "ambushbug"
"americanalligator" "alligator"
"americanavocet" "avocet"
"americanbadger" "badger"
"americanbittern" "bittern"
"americanblackvulture" "vulture"
"americanbobtail" "bobtail"
"americanbulldog" "bulldog"
"americancicada" "cicada"
"americancrayfish" "crayfish"
"americancreamdraft" "creamdraft"
"americancrocodile" "crocodile"
"americancrow" "crow"
"americancurl" "curl"
"americangoldfinch" "goldfinch"
"americanindianhorse" "indianhorse"
"americankestrel" "kestrel"
"americanlobster" "lobster"
"americanmarten" "marten"
"americanpainthorse" "painthorse"
"americanquarterhorse" "quarterhorse"
"americanratsnake" "ratsnake"
"americanredsquirrel" "redsquirrel"
"americanriverotter" "riverotter"
"americanrobin" "robin"
"americansaddlebred" "saddlebred"
"americanshorthair" "shorthair"
"americantoad" "toad"
"americanwarmblood" "warmblood"
"americanwigeon" "wigeon"
"americanwirehair" "wirehair"
"amethystgemclam" "amethystgemclam"
"amethystinepython" "amethystinepython"
"amethystsunbird" "amethystsunbird"
@ -114,7 +120,6 @@
"anchovy" "anchovy"
"andalusianhorse" "andalusianhorse"
"andeancat" "andeancat"
"andeancockoftherock"
"andeancondor" "andeancondor"
"anemone" "anemone"
"anemonecrab" "anemonecrab"
@ -181,21 +186,19 @@
"arrowworm" "arrowworm"
"arthropods" "arthropods"
"aruanas" "aruanas"
"asianconstablebutterfly" "constablebutterfly"
"asiandamselfly" "damselfly"
"asianelephant" "elephant"
"asianlion" "lion"
"asianpiedstarling" "piedstarling"
"asianporcupine" "porcupine"
"asiansmallclawedotter" "smallclawedotter"
"asiantrumpetfish" "trumpetfish"
"asianwaterbuffalo" "waterbuffalo"
"asiaticgreaterfreshwaterclam" "greaterfreshwaterclam"
"asiaticlesserfreshwaterclam" "lesserfreshwaterclam"
"asiaticmouflon" "mouflon"
"asiaticwildass"
"asp" "asp"
"ass"
"assassinbug" "assassinbug"
"astarte" "astarte"
"astrangiacoral" "astrangiacoral"
@ -282,17 +285,14 @@
"bighornsheep" "bighornsheep"
"bigmouthbass" "bigmouthbass"
"bilby" "bilby"
"billygoat"
"binturong" "binturong"
"bird" "bird"
"birdofparadise" "birdofparadise"
"bison" "bison"
"bittern" "bittern"
"blackandtancoonhound"
"blackbear" "blackbear"
"blackbird" "blackbird"
"blackbuck" "blackbuck"
"blackcrappie"
"blackfish" "blackfish"
"blackfly" "blackfly"
"blackfootedferret" "blackfootedferret"
@ -311,12 +311,10 @@
"bluebird" "bluebird"
"bluebottle" "bluebottle"
"bluebottlejellyfish" "bluebottlejellyfish"
"bluebreastedkookaburra"
"bluefintuna" "bluefintuna"
"bluefish" "bluefish"
"bluegill" "bluegill"
"bluejay" "bluejay"
"bluemorphobutterfly"
"blueshark" "blueshark"
"bluet" "bluet"
"bluetickcoonhound" "bluetickcoonhound"
@ -427,11 +425,7 @@
"coati" "coati"
"cob" "cob"
"cobra" "cobra"
"cock"
"cockatiel"
"cockatoo"
"cockerspaniel" "cockerspaniel"
"cockroach"
"cod" "cod"
"coelacanth" "coelacanth"
"collardlizard" "collardlizard"
@ -457,7 +451,6 @@
"corydorascatfish" "corydorascatfish"
"cottonmouth" "cottonmouth"
"cottontail" "cottontail"
"cougar"
"cow" "cow"
"cowbird" "cowbird"
"cowrie" "cowrie"
@ -486,8 +479,6 @@
"cutworm" "cutworm"
"cygnet" "cygnet"
"dachshund" "dachshund"
"daddylonglegs"
"dairycow"
"dalmatian" "dalmatian"
"damselfly" "damselfly"
"danishswedishfarmdog" "danishswedishfarmdog"
@ -520,8 +511,6 @@
"doe" "doe"
"dog" "dog"
"dogfish" "dogfish"
"dogwoodclubgall"
"dogwoodtwigborer"
"dolphin" "dolphin"
"donkey" "donkey"
"dorado" "dorado"
@ -529,7 +518,6 @@
"dorking" "dorking"
"dormouse" "dormouse"
"dotterel" "dotterel"
"douglasfirbarkbeetle"
"dove" "dove"
"dowitcher" "dowitcher"
"drafthorse" "drafthorse"
@ -546,22 +534,15 @@
"duckling" "duckling"
"dugong" "dugong"
"duiker" "duiker"
"dungbeetle"
"dungenesscrab"
"dunlin" "dunlin"
"dunnart" "dunnart"
"dutchshepherddog" "dutchshepherddog"
"dutchsmoushond" "dutchsmoushond"
"dwarfmongoose"
"dwarfrabbit"
"eagle" "eagle"
"earthworm" "earthworm"
"earwig" "earwig"
"easternglasslizard" "easternglasslizard"
"easternnewt" "easternnewt"
"easteuropeanshepherd"
"eastrussiancoursinghounds"
"eastsiberianlaika"
"echidna" "echidna"
"eel" "eel"
"eelelephant" "eelelephant"
@ -761,7 +742,6 @@
"guineapig" "guineapig"
"gull" "gull"
"guppy" "guppy"
"gypsymoth"
"gyrfalcon" "gyrfalcon"
"hackee" "hackee"
"haddock" "haddock"
@ -807,7 +787,6 @@
"hermitcrab" "hermitcrab"
"heron" "heron"
"herring" "herring"
"heterodontosaurus"
"hind" "hind"
"hippopotamus" "hippopotamus"
"hoatzin" "hoatzin"
@ -1013,7 +992,6 @@
"leopardseal" "leopardseal"
"leveret" "leveret"
"lhasaapso" "lhasaapso"
"lice"
"liger" "liger"
"lightningbug" "lightningbug"
"limpet" "limpet"
@ -1040,12 +1018,9 @@
"lunamoth" "lunamoth"
"lungfish" "lungfish"
"lynx" "lynx"
"lynxÂ"
"macaque" "macaque"
"macaw" "macaw"
"macropod" "macropod"
"madagascarhissingroach"
"maggot"
"magpie" "magpie"
"maiasaura" "maiasaura"
"majungatholus" "majungatholus"
@ -1084,13 +1059,11 @@
"mealworm" "mealworm"
"meerkat" "meerkat"
"megalosaurus" "megalosaurus"
"megalotomusquinquespinosus"
"megaraptor" "megaraptor"
"merganser" "merganser"
"merlin" "merlin"
"metalmarkbutterfly" "metalmarkbutterfly"
"metamorphosis" "metamorphosis"
"mice"
"microvenator" "microvenator"
"midge" "midge"
"milksnake" "milksnake"
@ -1108,9 +1081,8 @@
"molly" "molly"
"monarch" "monarch"
"mongoose" "mongoose"
"mongrel"
"monkey" "monkey"
"monkfishÂ" "monkfish"
"monoclonius" "monoclonius"
"montanoceratops" "montanoceratops"
"moorhen" "moorhen"
@ -1126,7 +1098,6 @@
"mountaincat" "mountaincat"
"mountainlion" "mountainlion"
"mouse" "mouse"
"mouse/mice"
"mousebird" "mousebird"
"mudpuppy" "mudpuppy"
"mule" "mule"
@ -1141,12 +1112,11 @@
"mutt" "mutt"
"myna" "myna"
"mynah" "mynah"
"myotisÂ" "myotis"
"nabarlek" "nabarlek"
"nag" "nag"
"naga" "naga"
"nagapies" "nagapies"
"nakedmolerat"
"nandine" "nandine"
"nandoo" "nandoo"
"nandu" "nandu"
@ -1175,9 +1145,8 @@
"nightheron" "nightheron"
"nightingale" "nightingale"
"nightjar" "nightjar"
"nijssenissdwarfchihlid"
"nilgai" "nilgai"
"ninebandedarmadillo" "armadillo"
"noctilio" "noctilio"
"noctule" "noctule"
"noddy" "noddy"
@ -1186,7 +1155,6 @@
"northernelephantseal" "northernelephantseal"
"northernflyingsquirrel" "northernflyingsquirrel"
"northernfurseal" "northernfurseal"
"northernhairynosedwombat"
"northernpike" "northernpike"
"northernseahorse" "northernseahorse"
"northernspottedowl" "northernspottedowl"
@ -1200,7 +1168,6 @@
"nuthatch" "nuthatch"
"nutria" "nutria"
"nyala" "nyala"
"nymph"
"ocelot" "ocelot"
"octopus" "octopus"
"okapi" "okapi"
@ -1226,7 +1193,7 @@
"oxpecker" "oxpecker"
"oyster" "oyster"
"ozarkbigearedbat" "ozarkbigearedbat"
"pacaÂ" "paca"
"pachyderm" "pachyderm"
"pacificparrotlet" "pacificparrotlet"
"paddlefish" "paddlefish"
@ -1254,12 +1221,11 @@
"pheasant" "pheasant"
"phoebe" "phoebe"
"phoenix" "phoenix"
"pig"
"pigeon" "pigeon"
"piglet" "piglet"
"pika" "pika"
"pike" "pike"
"pikeperchÂ" "pikeperch"
"pilchard" "pilchard"
"pinemarten" "pinemarten"
"pinkriverdolphin" "pinkriverdolphin"
@ -1277,7 +1243,6 @@
"plover" "plover"
"polarbear" "polarbear"
"polecat" "polecat"
"polliwog"
"polyp" "polyp"
"polyturator" "polyturator"
"pomeranian" "pomeranian"
@ -1309,7 +1274,6 @@
"pupfish" "pupfish"
"puppy" "puppy"
"purplemarten" "purplemarten"
"pussycat"
"pygmy" "pygmy"
"python" "python"
"quadrisectus" "quadrisectus"
@ -1381,7 +1345,7 @@
"rottweiler" "rottweiler"
"sable" "sable"
"sableantelope" "sableantelope"
"sablefishÂ" "sablefish"
"saiga" "saiga"
"sakimonkey" "sakimonkey"
"salamander" "salamander"
@ -1442,10 +1406,8 @@
"silversidefish" "silversidefish"
"siskin" "siskin"
"skimmer" "skimmer"
"skink"
"skipper" "skipper"
"skua" "skua"
"skunk"
"skylark" "skylark"
"sloth" "sloth"
"slothbear" "slothbear"
@ -1560,7 +1522,7 @@
"titmouse" "titmouse"
"toad" "toad"
"toadfish" "toadfish"
"tomtitÂ" "tomtit"
"topi" "topi"
"tortoise" "tortoise"
"toucan" "toucan"
@ -1676,7 +1638,6 @@
"wombat" "wombat"
"woodborer" "woodborer"
"woodchuck" "woodchuck"
"woodcock"
"woodnymphbutterfly" "woodnymphbutterfly"
"woodpecker" "woodpecker"
"woodstorks" "woodstorks"
@ -1700,7 +1661,6 @@
"xenopterygii" "xenopterygii"
"xenopus" "xenopus"
"xenotarsosaurus" "xenotarsosaurus"
"xenurine"
"xenurusunicinctus" "xenurusunicinctus"
"xerus" "xerus"
"xiaosaurus" "xiaosaurus"

View File

@ -1,15 +1,19 @@
(ns status-im.utils.gfycat.core (ns status-im.utils.gfycat.core
(:require [status-im.utils.gfycat.animals :as animals] (:require [status-im.utils.gfycat.animals :as animals]
[status-im.utils.gfycat.adjectives :as adjectives] [status-im.utils.gfycat.adjectives :as adjectives]
[clojure.string :as str])) [clojure.string :as str]
[status-im.utils.random :as rnd]
[status-im.utils.datetime :refer [now-ms]]))
(defn- pick-random (defn- pick-random
[vector] [gen vector]
(str/capitalize (rand-nth vector))) (str/capitalize (rnd/seeded-rand-nth gen vector)))
(defn generate-gfy (defn generate-gfy
[] ([public-key]
(let [first-adjective (pick-random adjectives/data) (let [gen (rnd/rand-gen public-key)
second-adjective (pick-random adjectives/data) first-adjective (pick-random gen adjectives/data)
animal (pick-random animals/data)] second-adjective (pick-random gen adjectives/data)
animal (pick-random gen animals/data)]
(str first-adjective " " second-adjective " " animal))) (str first-adjective " " second-adjective " " animal)))
([] (generate-gfy (now-ms))))

View File

@ -8,3 +8,14 @@
(defn id [] (defn id []
(str (timestamp) "-" (.guid chance))) (str (timestamp) "-" (.guid chance)))
(defn rand-gen
[seed]
(dependencies/Chance. seed))
(defn seeded-rand-int
[gen n] (.integer gen #js {:min 0 :max (dec n)}))
(defn seeded-rand-nth
[gen coll]
(nth coll (seeded-rand-int gen (count coll))))

View File

@ -7,7 +7,9 @@
[status-im.test.utils.utils] [status-im.test.utils.utils]
[status-im.test.utils.money] [status-im.test.utils.money]
[status-im.test.utils.clocks] [status-im.test.utils.clocks]
[status-im.test.utils.erc20])) [status-im.test.utils.erc20]
[status-im.test.utils.random]
[status-im.test.utils.gfycat.core]))
(enable-console-print!) (enable-console-print!)
@ -24,4 +26,6 @@
'status-im.test.utils.utils 'status-im.test.utils.utils
'status-im.test.utils.money 'status-im.test.utils.money
'status-im.test.utils.clocks 'status-im.test.utils.clocks
'status-im.test.utils.erc20) 'status-im.test.utils.erc20
'status-im.test.utils.random
'status-im.test.utils.gfycat.core)

View File

@ -0,0 +1,12 @@
(ns status-im.test.utils.gfycat.core
(:require [cljs.test :refer-macros [deftest is]]
[status-im.utils.gfycat.core :as gfy]))
(def message "Names are only deterministic as long as word lists do not change!\nIf you change the lists, please change the tests as well.")
(deftest test-generate-gfy
(is (= (gfy/generate-gfy "57348975ff9199ca636207a396b915d6b6a675b4") "Winged Fitting Mosquito") message)
(is (= (gfy/generate-gfy "e63d083d2d7a13a14632983b5820529445ca8109") "Mediumvioletred Melodic Waterdogs") message)
(is (= (gfy/generate-gfy "57348975ff9199ca636207a396b915d6b6a675b4") "Winged Fitting Mosquito") message)
(is (= (gfy/generate-gfy "26cf649aebb252a75aebc588e0d9ce93789dbe0b") "Educated Upright Arcticseal") message)
(is (= (gfy/generate-gfy "e63d083d2d7a13a14632983b5820529445ca8109") "Mediumvioletred Melodic Waterdogs") message))

View File

@ -0,0 +1,91 @@
(ns status-im.test.utils.random
(:require [cljs.test :refer-macros [deftest is]]
[status-im.utils.random :as random]))
(deftest test-seeded-rand-int
;try with one seed
(let [seed 0
gen (random/rand-gen seed)]
(is (= (random/seeded-rand-int gen 100) 54))
(is (= (random/seeded-rand-int gen 100) 59))
(is (= (random/seeded-rand-int gen 10) 7))
(is (= (random/seeded-rand-int gen 10) 8)))
;repeat with the same seed, but generator re-set
(let [seed 0
gen (random/rand-gen seed)]
(is (= (random/seeded-rand-int gen 100) 54))
(is (= (random/seeded-rand-int gen 100) 59))
(is (= (random/seeded-rand-int gen 10) 7))
(is (= (random/seeded-rand-int gen 10) 8)))
;a string seed
(let [seed "6ec565f4fec866a54761524f603cf037e20c2bfa"
gen (random/rand-gen seed)]
(is (= (random/seeded-rand-int gen 100) 7))
(is (= (random/seeded-rand-int gen 100) 4))
(is (= (random/seeded-rand-int gen 10) 5))
(is (= (random/seeded-rand-int gen 10) 7)))
;a string seed again
(let [seed "6ec565f4fec866a54761524f603cf037e20c2bfa"
gen (random/rand-gen seed)]
(is (= (random/seeded-rand-int gen 100) 7))
(is (= (random/seeded-rand-int gen 100) 4))
(is (= (random/seeded-rand-int gen 10) 5))
(is (= (random/seeded-rand-int gen 10) 7)))
;nil seed is the same as 0
(let [seed 0
gen (random/rand-gen seed)]
(is (= (random/seeded-rand-int gen 100) 54))
(is (= (random/seeded-rand-int gen 100) 59))
(is (= (random/seeded-rand-int gen 10) 7))
(is (= (random/seeded-rand-int gen 10) 8))))
(deftest test-seeded-rand-int-boundaries
(let [seed "6ec565f4fec866a54761524f603cf037e20c2bfa"
n 10
gen (random/rand-gen seed)
sample (into #{} (repeatedly 1000 #(random/seeded-rand-int gen n)))]
;no result should be negative
(is (empty? (filter #(< % 0) sample)))
;no result should be larger than n
(is (empty? (filter #(>= % n) sample)))
;and while there is a very small probability
;it is very unlikely and probably wrong if all 1000 calls
;got us the same number.
(is (> (count sample) 1))))
(deftest test-seeded-rand-nth
(let [seed "6ec565f4fec866a54761524f603cf037e20c2bfa"
gen (random/rand-gen seed)
coll [:a :b :c :d :e :f :g]]
(is (= (random/seeded-rand-nth gen coll) :a))
(is (= (random/seeded-rand-nth gen coll) :a))
(is (= (random/seeded-rand-nth gen coll) :e))
(is (= (random/seeded-rand-nth gen coll) :f))
(is (= (random/seeded-rand-nth gen coll) :c)))
;try again with the same seed but gen reset
(let [seed "6ec565f4fec866a54761524f603cf037e20c2bfa"
gen (random/rand-gen seed)
coll [:a :b :c :d :e :f :g]]
(is (= (random/seeded-rand-nth gen coll) :a))
(is (= (random/seeded-rand-nth gen coll) :a))
(is (= (random/seeded-rand-nth gen coll) :e))
(is (= (random/seeded-rand-nth gen coll) :f))
(is (= (random/seeded-rand-nth gen coll) :c)))
;try again with a different seed
(let [seed "57348975ff9199ca636207a396b915d6b6a675b4"
gen (random/rand-gen seed)
coll [:a :b :c :d :e :f :g]]
(is (= (random/seeded-rand-nth gen coll) :f))
(is (= (random/seeded-rand-nth gen coll) :c))
(is (= (random/seeded-rand-nth gen coll) :e))
(is (= (random/seeded-rand-nth gen coll) :e))
(is (= (random/seeded-rand-nth gen coll) :a)))
;and re-set
(let [seed "57348975ff9199ca636207a396b915d6b6a675b4"
gen (random/rand-gen seed)
coll [:a :b :c :d :e :f :g]]
(is (= (random/seeded-rand-nth gen coll) :f))
(is (= (random/seeded-rand-nth gen coll) :c))
(is (= (random/seeded-rand-nth gen coll) :e))
(is (= (random/seeded-rand-nth gen coll) :e))
(is (= (random/seeded-rand-nth gen coll) :a))))