kibit suggestion (in progress)

This commit is contained in:
Roman Volosovskyi 2016-12-27 19:45:54 +02:00
parent 81257b815a
commit 9f4fd79586
44 changed files with 173 additions and 194 deletions

View File

@ -94,7 +94,7 @@
(not= status old-status))] (not= status old-status))]
(when status-updated? (when status-updated?
(let [hashtags (get-hashtags status)] (let [hashtags (get-hashtags status)]
(when-not (empty? hashtags) (when (seq hashtags)
(dispatch [:broadcast-status status hashtags])))))))) (dispatch [:broadcast-status status hashtags]))))))))
(register-handler (register-handler

View File

@ -23,18 +23,17 @@
:updates-private-key private :updates-private-key private
:signed-up? true}] :signed-up? true}]
(log/debug "account-recovered") (log/debug "account-recovered")
(when (not (str/blank? public-key)) (when-not (str/blank? public-key)
(do (dispatch [:set-in [:recover :passphrase] ""])
(dispatch [:set-in [:recover :passphrase] ""]) (dispatch [:set-in [:recover :password] ""])
(dispatch [:set-in [:recover :password] ""]) (dispatch [:add-account account])
(dispatch [:add-account account]) (dispatch [:navigate-back]))))
(dispatch [:navigate-back])))))
(defn recover-account (defn recover-account
[_ [_ passphrase password]] [_ [_ passphrase password]]
(status/recover-account (status/recover-account
passphrase passphrase
password password
(fn [result] (account-recovered result)))) account-recovered))
(register-handler :recover-account (u/side-effect! recover-account)) (register-handler :recover-account (u/side-effect! recover-account))

View File

@ -254,7 +254,7 @@
(register-handler :account-generation-message (register-handler :account-generation-message
(u/side-effect! (u/side-effect!
(fn [_] (fn [_]
(when (not (messages/get-by-id sign-up-service/passphraze-message-id)) (when-not (messages/get-by-id sign-up-service/passphraze-message-id)
(sign-up-service/account-generation-message))))) (sign-up-service/account-generation-message)))))
(register-handler :show-mnemonic (register-handler :show-mnemonic
@ -449,12 +449,12 @@
(chats/save chat'))) (chats/save chat')))
(register-handler :update-chat! (register-handler :update-chat!
(-> (fn [db [_ {:keys [chat-id name] :as chat}]] (after update-chat!)
(let [chat' (if name chat (dissoc chat :name))] (fn [db [_ {:keys [chat-id name] :as chat}]]
(if (get-in db [:chats chat-id]) (let [chat' (if name chat (dissoc chat :name))]
(update-in db [:chats chat-id] merge chat') (if (get-in db [:chats chat-id])
db))) (update-in db [:chats chat-id] merge chat')
((after update-chat!)))) db))))
(register-handler :upsert-chat! (register-handler :upsert-chat!
(fn [db [_ {:keys [chat-id] :as opts}]] (fn [db [_ {:keys [chat-id] :as opts}]]

View File

@ -53,9 +53,7 @@
(let [{:keys [name]} command] (let [{:keys [name]} command]
(case name (case name
"js" (let [{:keys [err data messages]} handler-data "js" (let [{:keys [err data messages]} handler-data
content (if err content (or err data)]
err
data)]
(doseq [message messages] (doseq [message messages]
(let [{:keys [message type]} message] (let [{:keys [message type]} message]
(dispatch [:received-message (dispatch [:received-message

View File

@ -41,7 +41,7 @@
exists? (chats/exists? chat-id') exists? (chats/exists? chat-id')
active? (chats/is-active? chat-id') active? (chats/is-active? chat-id')
chat-clock-value (messages/get-last-clock-value chat-id') chat-clock-value (messages/get-last-clock-value chat-id')
clock-value (if (= clock-value 0) clock-value (if (zero? clock-value)
(inc chat-clock-value) (inc chat-clock-value)
clock-value)] clock-value)]
(when (and (not same-message) (when (and (not same-message)

View File

@ -228,9 +228,7 @@
(u/side-effect! (u/side-effect!
(fn [_ [_ chat-id {:keys [returned]}]] (fn [_ [_ chat-id {:keys [returned]}]]
(let [{:keys [data messages err]} returned (let [{:keys [data messages err]} returned
content (if err content (or err data)]
err
data)]
(doseq [message messages] (doseq [message messages]
(let [{:keys [message type]} message] (let [{:keys [message type]} message]
(dispatch [:received-message (dispatch [:received-message

View File

@ -47,7 +47,7 @@
(dispatch [:sign-up-confirm (second matches)]))) (dispatch [:sign-up-confirm (second matches)])))
(defn start-listening-confirmation-code-sms [db] (defn start-listening-confirmation-code-sms [db]
(if (not (:confirmation-code-sms-listener db)) (if-not (:confirmation-code-sms-listener db)
(assoc db :confirmation-code-sms-listener (add-sms-listener handle-sms)) (assoc db :confirmation-code-sms-listener (add-sms-listener handle-sms))
db)) db))
@ -83,11 +83,10 @@
:to "me"}]) :to "me"}])
(let [status (keyword (:status body))] (let [status (keyword (:status body))]
(when (= :confirmed status) (when (= :confirmed status)
(do (dispatch [:stop-listening-confirmation-code-sms])
(dispatch [:stop-listening-confirmation-code-sms]) (sync-contacts)
(sync-contacts) ;; TODO should be called after sync-contacts?
;; TODO should be called after sync-contacts? (dispatch [:set-signed-up true]))
(dispatch [:set-signed-up true])))
(when (= :failed status) (when (= :failed status)
(on-sign-up-response (label :t/incorrect-code))))) (on-sign-up-response (label :t/incorrect-code)))))

View File

@ -184,7 +184,7 @@
(register-sub :is-request-answered? (register-sub :is-request-answered?
(fn [_ [_ message-id]] (fn [_ [_ message-id]]
(let [requests (subscribe [:get-requests])] (let [requests (subscribe [:get-requests])]
(reaction (not (some #(= message-id (:message-id %)) @requests)))))) (reaction (not-any? #(= message-id (:message-id %)) @requests)))))
(register-sub :validation-errors (register-sub :validation-errors
(fn [db] (fn [db]
@ -211,7 +211,7 @@
(let [chat-id (subscribe [:get-current-chat-id])] (let [chat-id (subscribe [:get-current-chat-id])]
(reaction (reaction
(min (get-in @db [:animations :to-response-height @chat-id]) (min (get-in @db [:animations :to-response-height @chat-id])
(if (> (:layout-height @db) 0) (if (pos? (:layout-height @db))
(- (:layout-height @db) (- (:layout-height @db)
(get-in platform-specific [:component-styles :status-bar status-bar :height])) (get-in platform-specific [:component-styles :status-bar status-bar :height]))
0)))))) 0))))))

View File

@ -23,7 +23,7 @@
[chat-icon-view-menu-item chat-id group-chat name color true]) [chat-icon-view-menu-item chat-id group-chat name color true])
(defn- members-text [members] (defn- members-text [members]
(str (s/join ", " (map #(:name %) members)) (str (s/join ", " (map :name members))
" " " "
(label :t/and-you))) (label :t/and-you)))
@ -121,8 +121,9 @@
(when-let [actions (if @group-chat (when-let [actions (if @group-chat
(group-chat-items @members) (group-chat-items @members)
(user-chat-items @chat-id))] (user-chat-items @chat-id))]
[view (-> (st/actions-wrapper status-bar-height) [view (merge
(merge (get-in platform-specific [:component-styles :actions-list-view]))) (st/actions-wrapper status-bar-height)
(get-in platform-specific [:component-styles :actions-list-view]))
[view st/actions-separator] [view st/actions-separator]
[view st/actions-view [view st/actions-view
(for [action actions] (for [action actions]

View File

@ -185,7 +185,7 @@
[text [text
{:key (str idx "_" string) {:key (str idx "_" string)
:style style} :style style}
(subs string 1 (- (count string) 1))])) (subs string 1 (dec (count string)))]))
(re-seq regx string))) (re-seq regx string)))
styled-text' (if (> (count general-text) styled-text' (if (> (count general-text)
(count styled-text)) (count styled-text))
@ -331,7 +331,7 @@
(defn message-container-animation-logic [{:keys [to-value val callback]}] (defn message-container-animation-logic [{:keys [to-value val callback]}]
(fn [_] (fn [_]
(let [to-value @to-value] (let [to-value @to-value]
(when (< 0 to-value) (when (pos? to-value)
(anim/start (anim/start
(anim/timing val {:toValue to-value (anim/timing val {:toValue to-value
:duration 250}) :duration 250})

View File

@ -33,8 +33,7 @@
type [:command-type] type [:command-type]
suggestions [:get-suggestions] suggestions [:get-suggestions]
message-input-height [:get-message-input-view-height]] message-input-height [:get-message-input-view-height]]
(let [on-top? (or (and (not (empty? suggestions)) (let [on-top? (or (and (seq suggestions) (not command?))
(not command?))
(not= response-height input-height)) (not= response-height input-height))
style (get-in platform-specific [:component-styles :chat :new-message])] style (get-in platform-specific [:component-styles :chat :new-message])]
[view {:style (merge (st/new-message-container margin on-top?) style) [view {:style (merge (st/new-message-container margin on-top?) style)

View File

@ -20,7 +20,8 @@
(defn label [command] (defn label [command]
(when command (when command
(->> (name (:name command)) (->> (:name command)
name
(str "request-")))) (str "request-"))))
(def min-scale 1) (def min-scale 1)

View File

@ -22,7 +22,7 @@
contact (let [last-online (get contact :last-online) contact (let [last-online (get contact :last-online)
last-online-date (time/to-date last-online) last-online-date (time/to-date last-online)
now-date (t/now)] now-date (t/now)]
(if (and (> last-online 0) (if (and (pos? last-online)
(<= last-online-date now-date)) (<= last-online-date now-date))
(time/time-ago last-online-date) (time/time-ago last-online-date)
(label :t/active-unknown))) (label :t/active-unknown)))

View File

@ -93,7 +93,7 @@
registered-only))) registered-only)))
(remove (fn [[n]] (remove (fn [[n]]
(and (and
(not (= console-chat-id id)) (not= console-chat-id id)
(h/matches (name n) "password")))) (h/matches (name n) "password"))))
(into {}))) (into {})))

View File

@ -158,18 +158,11 @@
:default-chat-icon (st/default-chat-icon-profile color) :default-chat-icon (st/default-chat-icon-profile color)
:default-chat-icon-text st/default-chat-icon-text}] :default-chat-icon-text st/default-chat-icon-text}]
[view (:container styles) [view (:container styles)
(if (and photo-path (not (empty? photo-path))) (if (and photo-path (seq photo-path))
[chat-icon photo-path styles] [chat-icon photo-path styles]
[default-chat-icon name styles]) [default-chat-icon name styles])
[contact-badge badge-type styles]])) [contact-badge badge-type styles]]))
(defview profile-icon []
[contact [:contact]]
(let [;; TODO: stub
type :online
color default-chat-color]
[profile-icon-view (:photo-path @contact) (:name @contact) color type]))
(defn my-profile-icon [{{:keys [photo-path name]} :account (defn my-profile-icon [{{:keys [photo-path name]} :account
edit? :edit?}] edit? :edit?}]
(let [type (if edit? :edit :blank) (let [type (if edit? :edit :blank)

View File

@ -2,7 +2,7 @@
(:require [status-im.components.styles :refer [color-white]])) (:require [status-im.components.styles :refer [color-white]]))
(def tabs-height 56) (def tabs-height 56)
(def tab-height (- tabs-height 1)) (def tab-height (dec tabs-height))
(def bottom-gradient (def bottom-gradient
{:position :absolute {:position :absolute

View File

@ -48,8 +48,7 @@
(defn toolbar-actions-container [actions-count custom] (defn toolbar-actions-container [actions-count custom]
(merge {:flex-direction "row" (merge {:flex-direction "row"
:margin-left toolbar-icon-spacing} :margin-left toolbar-icon-spacing}
(when (and (= actions-count 0) (when (and (zero? actions-count) (not custom))
(not custom))
{:width (+ toolbar-icon-width toolbar-icon-spacing)}))) {:width (+ toolbar-icon-width toolbar-icon-spacing)})))
(def toolbar-action (def toolbar-action

View File

@ -25,7 +25,7 @@
[view {:style style} [view {:style style}
[view st/toolbar [view st/toolbar
[view (st/toolbar-nav-actions-container actions) [view (st/toolbar-nav-actions-container actions)
(when (not hide-nav?) (when-not hide-nav?
(if nav-action (if nav-action
[touchable-highlight {:on-press (:handler nav-action)} [touchable-highlight {:on-press (:handler nav-action)}
[view (get-in platform-specific [:component-styles :toolbar-nav-action]) [view (get-in platform-specific [:component-styles :toolbar-nav-action])

View File

@ -208,15 +208,16 @@
((after send-contact-request)))) ((after send-contact-request))))
(register-handler ::update-pending-contact (register-handler ::update-pending-contact
(-> add-new-contact (after save-contact)
((after save-contact)))) add-new-contact)
(register-handler :add-pending-contact (register-handler :add-pending-contact
(u/side-effect! (u/side-effect!
(fn [{:keys [chats contacts]} [_ chat-id]] (fn [{:keys [chats contacts]} [_ chat-id]]
(let [contact (if-let [contact-info (get-in chats [chat-id :contact-info])] (let [contact (if-let [contact-info (get-in chats [chat-id :contact-info])]
(read-string contact-info) (read-string contact-info)
(-> (get contacts chat-id) (-> contacts
(get chat-id)
(assoc :pending false)))] (assoc :pending false)))]
(dispatch [::prepare-contact contact]) (dispatch [::prepare-contact contact])
(dispatch [:update-chat! {:chat-id chat-id (dispatch [:update-chat! {:chat-id chat-id
@ -259,12 +260,12 @@
:last-online timestamp}])))))) :last-online timestamp}]))))))
(register-handler :remove-contact (register-handler :remove-contact
(-> (u/side-effect! (after stop-watching-contact)
(fn [_ [_ {:keys [whisper-identity] :as contact}]] (u/side-effect!
(dispatch [:update-chat! {:chat-id whisper-identity (fn [_ [_ {:keys [whisper-identity] :as contact}]]
:pending-contact? true}]) (dispatch [:update-chat! {:chat-id whisper-identity
(dispatch [:update-contact! (assoc contact :pending true)]))) :pending-contact? true}])
((after stop-watching-contact)))) (dispatch [:update-contact! (assoc contact :pending true)]))))
(register-handler :open-contact-menu (register-handler :open-contact-menu
(u/side-effect! (u/side-effect!

View File

@ -9,12 +9,12 @@
(reaction @contacts)))) (reaction @contacts))))
(defn sort-contacts [contacts] (defn sort-contacts [contacts]
(->> (vals contacts) (sort (fn [c1 c2]
(sort (fn [c1 c2] (let [name1 (or (:name c1) (:address c1) (:whisper-identity c1))
(let [name1 (or (:name c1) (:address c1) (:whisper-identity c1)) name2 (or (:name c2) (:address c2) (:whisper-identity c2))]
name2 (or (:name c2) (:address c2) (:whisper-identity c2))] (compare (clojure.string/lower-case name1)
(compare (clojure.string/lower-case name1) (clojure.string/lower-case name2))))
(clojure.string/lower-case name2))))))) (vals contacts)))
(register-sub :all-added-contacts (register-sub :all-added-contacts
(fn [db _] (fn [db _]
@ -112,16 +112,13 @@
chat (reaction (get-in @db [:chats chat-id])) chat (reaction (get-in @db [:chats chat-id]))
contacts (contacts-by-chat filter db chat-id)] contacts (contacts-by-chat filter db chat-id)]
(reaction (reaction
(when @chat (when (and @chat (not (:group-chat @chat)))
(if (:group-chat @chat) (cond
;; TODO return group chat icon (:photo-path @chat)
nil (:photo-path @chat)
(cond
(:photo-path @chat)
(:photo-path @chat)
(pos? (count @contacts)) (pos? (count @contacts))
(:photo-path (first @contacts)) (:photo-path (first @contacts))
:else :else
(identicon chat-id)))))))) (identicon chat-id)))))))

View File

@ -9,8 +9,7 @@
(defn contact-can-be-added? [identity] (defn contact-can-be-added? [identity]
(if (contacts/exists? identity) (if (contacts/exists? identity)
(-> (contacts/get-by-id identity) (:pending (contacts/get-by-id identity))
(get :pending))
true)) true))
(defn valid-length? [identity] (defn valid-length? [identity]

View File

@ -9,8 +9,7 @@
(defn get-all (defn get-all
[] []
(-> (data-store/get-all-active) (normalize-contacts (data-store/get-all-active)))
normalize-contacts))
(defn get-by-id (defn get-by-id
[id] [id]

View File

@ -4,8 +4,8 @@
(defn get-all (defn get-all
[ordering] [ordering]
(->> (data-store/get-all-as-list ordering) (mapv #(update % :tags vals)
(mapv #(update % :tags vals)))) (data-store/get-all-as-list ordering)))
(defn save (defn save
[discover] [discover]

View File

@ -5,8 +5,7 @@
(realm/get-all realm/base-realm :account)) (realm/get-all realm/base-realm :account))
(defn get-all-as-list [] (defn get-all-as-list []
(-> (get-all) (realm/realm-collection->list (get-all)))
realm/realm-collection->list))
(defn get-by-address [address] (defn get-by-address [address]
(realm/get-one-by-field-clj realm/base-realm :account :address address)) (realm/get-one-by-field-clj realm/base-realm :account :address address))
@ -18,4 +17,4 @@
(defn save-all [accounts update?] (defn save-all [accounts update?]
(realm/write realm/base-realm (realm/write realm/base-realm
(fn [] (fn []
(mapv #(realm/create realm/base-realm :account % update?) accounts)))) (mapv #(realm/create realm/base-realm :account % update?) accounts))))

View File

@ -5,13 +5,13 @@
(defn get-all (defn get-all
[] []
(-> (realm/get-all @realm/account-realm :chat) (-> @realm/account-realm
(realm/get-all :chat)
(realm/sorted :timestamp :desc))) (realm/sorted :timestamp :desc)))
(defn get-all-as-list (defn get-all-as-list
[] []
(-> (get-all) (realm/realm-collection->list (get-all)))
realm/realm-collection->list))
(defn get-all-active (defn get-all-active
[] []
@ -36,7 +36,8 @@
(defn get-by-id (defn get-by-id
[chat-id] [chat-id]
(-> (realm/get-one-by-field-clj @realm/account-realm :chat :chat-id chat-id) (-> @realm/account-realm
(realm/get-one-by-field-clj :chat :chat-id chat-id)
(realm/list->array :contacts))) (realm/list->array :contacts)))
(defn save (defn save
@ -58,7 +59,8 @@
(defn get-contacts (defn get-contacts
[chat-id] [chat-id]
(-> (realm/get-one-by-field @realm/account-realm :chat :chat-id chat-id) (-> @realm/account-realm
(realm/get-one-by-field :chat :chat-id chat-id)
(aget "contacts"))) (aget "contacts")))
(defn has-contact? (defn has-contact?
@ -102,7 +104,8 @@
[chat-id property-name value] [chat-id property-name value]
(realm/write @realm/account-realm (realm/write @realm/account-realm
(fn [] (fn []
(-> (realm/get-one-by-field @realm/account-realm :chat :chat-id chat-id) (-> @realm/account-realm
(realm/get-one-by-field :chat :chat-id chat-id)
(aset (name property-name) value))))) (aset (name property-name) value)))))
(defn get-property (defn get-property

View File

@ -4,13 +4,13 @@
(defn get-all (defn get-all
[] []
(-> (realm/get-all @realm/account-realm :contact) (-> @realm/account-realm
(realm/get-all :contact)
(realm/sorted :name :asc))) (realm/sorted :name :asc)))
(defn get-all-as-list (defn get-all-as-list
[] []
(-> (get-all) (realm/realm-collection->list (get-all)))
realm/realm-collection->list))
(defn get-by-id (defn get-by-id
[whisper-identity] [whisper-identity]

View File

@ -35,7 +35,6 @@
(open-realm (last schemas) file-name)) (open-realm (last schemas) file-name))
(def new-account-filename "new-account") (def new-account-filename "new-account")
(def new-accout-realm-file (str new-account-filename ".realm"))
(def base-realm (open-migrated-realm (.-defaultPath realm-class) base/schemas)) (def base-realm (open-migrated-realm (.-defaultPath realm-class) base/schemas))
@ -122,7 +121,8 @@
(.filtered results filter-query)) (.filtered results filter-query))
(defn realm-collection->list [collection] (defn realm-collection->list [collection]
(-> (.map collection (fn [object _ _] object)) (-> collection
(.map (fn [object _ _] object))
(js->clj :keywordize-keys true))) (js->clj :keywordize-keys true)))
(defn list->array [record list-field] (defn list->array [record list-field]
@ -136,7 +136,8 @@
(js->clj :keywordize-keys true))) (js->clj :keywordize-keys true)))
(defn get-by-filter [realm schema-name filter] (defn get-by-filter [realm schema-name filter]
(-> (.objects realm (name schema-name)) (-> realm
(.objects (name schema-name))
(.filtered filter))) (.filtered filter)))
(defn- get-schema-by-name [opts] (defn- get-schema-by-name [opts]

View File

@ -5,13 +5,13 @@
(defn get-all (defn get-all
[ordering] [ordering]
(-> (realm/get-all @realm/account-realm :discover) (-> @realm/account-realm
(realm/get-all :discover)
(realm/sorted :created-at ordering))) (realm/sorted :created-at ordering)))
(defn get-all-as-list (defn get-all-as-list
[ordering] [ordering]
(-> (get-all ordering) (realm/realm-collection->list (get-all ordering)))
realm/realm-collection->list))
(defn get-tag-by-name [tag] (defn get-tag-by-name [tag]
(log/debug "Getting tag: " tag) (log/debug "Getting tag: " tag)
@ -65,7 +65,8 @@
(let [discoveries (realm/get-all @realm/account-realm :discover) (let [discoveries (realm/get-all @realm/account-realm :discover)
count (realm/get-count discoveries)] count (realm/get-count discoveries)]
(if (> count critical-count) (if (> count critical-count)
(let [to-delete (-> (realm/sorted discoveries by ordering) (let [to-delete (-> discoveries
(realm/sorted by ordering)
(realm/page 0 to-delete-count))] (realm/page 0 to-delete-count))]
(realm/write @realm/account-realm (realm/write @realm/account-realm
(fn [] (fn []

View File

@ -9,8 +9,7 @@
(defn get-all-as-list (defn get-all-as-list
[] []
(-> (get-all) (realm/realm-collection->list (get-all)))
realm/realm-collection->list))
(defn get-by-id (defn get-by-id
[message-id] [message-id]
@ -29,8 +28,7 @@
(defn get-count-by-chat-id (defn get-count-by-chat-id
[chat-id] [chat-id]
(-> (get-by-chat-id chat-id) (realm/get-count (get-by-chat-id chat-id)))
(realm/get-count)))
(defn get-by-fields (defn get-by-fields
[fields from number-of-messages] [fields from number-of-messages]
@ -47,8 +45,9 @@
(defn get-unviewed (defn get-unviewed
[] []
(-> (realm/get-by-fields @realm/account-realm :message :and {:outgoing false (-> @realm/account-realm
:message-status nil}) (realm/get-by-fields :message :and {:outgoing false
:message-status nil})
(realm/realm-collection->list))) (realm/realm-collection->list)))
(defn exists? (defn exists?

View File

@ -4,7 +4,8 @@
(defn get-all (defn get-all
[] []
(-> (realm/get-all @realm/account-realm :processed-message) (-> @realm/account-realm
(realm/get-all :processed-message)
(realm/sorted :ttl :asc))) (realm/sorted :ttl :asc)))
(defn get-filtered (defn get-filtered
@ -13,8 +14,7 @@
(defn get-filtered-as-list (defn get-filtered-as-list
[condition] [condition]
(-> (get-filtered condition) (realm/realm-collection->list (get-filtered condition)))
realm/realm-collection->list))
(defn save (defn save
[processed-message] [processed-message]

View File

@ -7,8 +7,7 @@
(defn get-all-as-list (defn get-all-as-list
[] []
(-> (get-all) (realm/realm-collection->list (get-all)))
realm/realm-collection->list))
(defn get-open-by-chat-id (defn get-open-by-chat-id
[chat-id] [chat-id]
@ -27,8 +26,9 @@
(defn- get-by-message-id (defn- get-by-message-id
[chat-id message-id] [chat-id message-id]
(-> (realm/get-by-fields @realm/account-realm :request :and [[:chat-id chat-id] (-> @realm/account-realm
[:message-id message-id]]) (realm/get-by-fields :request :and [[:chat-id chat-id]
[:message-id message-id]])
(realm/single))) (realm/single)))
(defn mark-as-answered (defn mark-as-answered

View File

@ -18,7 +18,8 @@
(defn- get-discoveries-by-tags [discoveries current-tag tags] (defn- get-discoveries-by-tags [discoveries current-tag tags]
(let [tags' (or tags [current-tag])] (let [tags' (or tags [current-tag])]
(filter #(every? (->> (map :name (:tags %)) (filter #(every? (->> (:tags %)
(map :name)
(into (hash-set))) (into (hash-set)))
tags') tags')
(vals discoveries)))) (vals discoveries))))
@ -42,13 +43,11 @@
(register-sub :get-popular-tags (register-sub :get-popular-tags
(fn [db [_ limit]] (fn [db [_ limit]]
(-> (take limit (:tags @db)) (reaction (take limit (:tags @db)))))
(reaction))))
(register-sub :get-discover-search-results (register-sub :get-discover-search-results
(fn [db _] (fn [db _]
(let [discoveries (reaction (:discoveries @db)) (let [discoveries (reaction (:discoveries @db))
current-tag (reaction (:current-tag @db)) current-tag (reaction (:current-tag @db))
tags (reaction (:discover-search-tags @db))] tags (reaction (:discover-search-tags @db))]
(-> (get-discoveries-by-tags @discoveries @current-tag @tags) (reaction (get-discoveries-by-tags @discoveries @current-tag @tags)))))
(reaction)))))

View File

@ -31,14 +31,13 @@
(assoc-in db [:chats current-chat-id property-name] property)))) (assoc-in db [:chats current-chat-id property-name] property))))
(defn prepare-chat-settings (defn prepare-chat-settings
[{:keys [current-chat-id] :as db} _] [{:keys [current-chat-id] :as db}]
(let [{:keys [name color]} (-> db (let [{:keys [name color]} (-> db
(get-in [:chats current-chat-id]) (get-in [:chats current-chat-id])
(select-keys [:name :color]))] (select-keys [:name :color]))]
(-> db (assoc db :new-chat-name name
(assoc :new-chat-name name :new-chat-color color
:new-chat-color color :group-settings {})))
:group-settings {}))))
(register-handler :show-group-settings (register-handler :show-group-settings
(after (fn [_ _] (dispatch [:navigate-to :group-settings]))) (after (fn [_ _] (dispatch [:navigate-to :group-settings])))

View File

@ -42,13 +42,13 @@
([db type message-id command-key] ([db type message-id command-key]
(set-command-input db type message-id command-key nil)) (set-command-input db type message-id command-key nil))
([{:keys [current-chat-id] :as db} type message-id command-key params] ([{:keys [current-chat-id] :as db} type message-id command-key params]
(let [command (-> (get-response-or-command type db command-key) (let [command (get-response-or-command type db command-key)
(add-params params)) command' (add-params command params)
first-parameter (get (:params command) 0) first-parameter (get (:params command') 0)
value (:value first-parameter)] value (:value first-parameter)]
(update-in db [:chats current-chat-id :command-input] merge (update-in db [:chats current-chat-id :command-input] merge
{:content value {:content value
:command command :command command'
:parameter-idx 0 :parameter-idx 0
:params params :params params
:to-message-id message-id})))) :to-message-id message-id}))))

View File

@ -45,20 +45,18 @@
[{:keys [web3 message]}] [{:keys [web3 message]}]
(debug :send-clock-value-request message) (debug :send-clock-value-request message)
(d/add-pending-message! (d/add-pending-message!
web3 web3
(merge message-defaults (merge message-defaults
(-> message (assoc message
(assoc :type :clock-value-request
:type :clock-value-request :requires-ack? false))))
:requires-ack? false)))))
(defn send-clock-value! (defn send-clock-value!
[{:keys [web3 message]}] [{:keys [web3 message]}]
(debug :send-clock-value message) (debug :send-clock-value message)
(d/add-pending-message! (d/add-pending-message!
web3 web3
(merge message-defaults (merge message-defaults
(-> message (assoc message
(assoc :type :clock-value
:type :clock-value :requires-ack? false))))
:requires-ack? false)))))

View File

@ -115,9 +115,8 @@
(defn send-status! (defn send-status!
[{:keys [web3 message]}] [{:keys [web3 message]}]
(debug :broadcasting-status) (debug :broadcasting-status)
(let [message (-> message (let [message (assoc message :type :discover
(assoc :type :discover :topics [(make-discover-topic (:from message))])]
:topics [(make-discover-topic (:from message))]))]
(d/add-pending-message! web3 message))) (d/add-pending-message! web3 message)))
(defn send-discoveries-request! (defn send-discoveries-request!
@ -125,19 +124,18 @@
(debug :sending-discoveries-request) (debug :sending-discoveries-request)
(d/add-pending-message! (d/add-pending-message!
web3 web3
(-> message (assoc message :type :discoveries-request
(assoc :type :discoveries-request :topics [(make-discover-topic (:from message))])))
:topics [(make-discover-topic (:from message))]))))
(defn send-discoveries-response! (defn send-discoveries-response!
[{:keys [web3 discoveries message]}] [{:keys [web3 discoveries message]}]
(debug :sending-discoveries-response) (debug :sending-discoveries-response)
(doseq [portion (->> (take 100 discoveries) (doseq [portion (->> discoveries
(take 100)
(partition 10 10 nil))] (partition 10 10 nil))]
(d/add-pending-message! (d/add-pending-message!
web3 web3
(-> message (assoc message :type :discoveries-response
(assoc :type :discoveries-response :topics [(make-discover-topic (:from message))]
:topics [(make-discover-topic (:from message))] :message-id (random/id)
:message-id (random/id) :payload {:data (into [] portion)}))))
:payload {:data (into [] portion)})))))

View File

@ -8,7 +8,8 @@
"Returns {:private \"private key\" :public \"public key\"" "Returns {:private \"private key\" :public \"public key\""
[] []
(let [{:keys [enc dec]} (let [{:keys [enc dec]}
(-> (.generate ecc (.-ENC_DEC ecc) default-curve) (-> ecc
(.generate (.-ENC_DEC ecc) default-curve)
(js->clj :keywordize-keys true))] (js->clj :keywordize-keys true))]
{:private dec {:private dec
:public enc})) :public enc}))

View File

@ -16,7 +16,8 @@
[status-im.utils.datetime :as dt] [status-im.utils.datetime :as dt]
[taoensso.timbre :as log :refer-macros [debug]] [taoensso.timbre :as log :refer-macros [debug]]
[status-im.constants :as c] [status-im.constants :as c]
[status-im.components.status :as status])) [status-im.components.status :as status]
[clojure.string :refer [join]]))
(register-handler :initialize-protocol (register-handler :initialize-protocol
(fn [db [_ current-account-id]] (fn [db [_ current-account-id]]
@ -75,10 +76,11 @@
(register-handler :initialize-sync-listener (register-handler :initialize-sync-listener
(fn [{:keys [web3 sync-listener] :as db} _] (fn [{:keys [web3 sync-listener] :as db} _]
(if-not sync-listener (if-not sync-listener
(->> (.isSyncing (.-eth web3) (let [sync-listener (.isSyncing
(fn [error sync] (.-eth web3)
(dispatch [:update-sync-state error sync]))) (fn [error sync]
(assoc db :sync-listener)) (dispatch [:update-sync-state error sync])))]
(assoc db :sync-listener sync-listener))
db))) db)))
(register-handler :incoming-message (register-handler :incoming-message
@ -152,13 +154,15 @@
[identity from {:keys [message-id timestamp]}] [identity from {:keys [message-id timestamp]}]
(let [remover-name (:name (contacts/get-by-id from)) (let [remover-name (:name (contacts/get-by-id from))
removed-name (:name (contacts/get-by-id identity))] removed-name (:name (contacts/get-by-id identity))]
(->> (str (or remover-name from) " " (label :t/removed) " " (or removed-name identity)) (->> [(or remover-name from) (label :t/removed) (or removed-name identity)]
(join " ")
(system-message message-id timestamp)))) (system-message message-id timestamp))))
(defn you-removed-from-group-message (defn you-removed-from-group-message
[from {:keys [message-id timestamp]}] [from {:keys [message-id timestamp]}]
(let [remover-name (:name (contacts/get-by-id from))] (let [remover-name (:name (contacts/get-by-id from))]
(->> (str (or remover-name from) " " (label :t/removed-from-chat)) (->> [(or remover-name from) (label :t/removed-from-chat)]
(join " ")
(system-message message-id timestamp)))) (system-message message-id timestamp))))
(defn participant-left-group-message (defn participant-left-group-message
@ -198,10 +202,9 @@
[_ {:keys [from] [_ {:keys [from]
{:keys [group-id timestamp] :as payload} :payload}]] {:keys [group-id timestamp] :as payload} :payload}]]
(when (chats/new-update? timestamp group-id) (when (chats/new-update? timestamp group-id)
(let [message (let [message (you-removed-from-group-message from payload)
(-> (you-removed-from-group-message from payload) message' (assoc message :group-id group-id)]
(assoc :group-id group-id))] (dispatch [:received-message message']))
(dispatch [:received-message message]))
(protocol/stop-watching-group! {:web3 web3 (protocol/stop-watching-group! {:web3 web3
:group-id group-id}) :group-id group-id})
(dispatch [:update-chat! {:chat-id group-id (dispatch [:update-chat! {:chat-id group-id
@ -329,18 +332,18 @@
(register-handler :message-clock-value-request (register-handler :message-clock-value-request
(u/side-effect! (u/side-effect!
(fn [_ [_ {:keys [from] {:keys [message-id]} :payload}]] (fn [_ [_ {:keys [from] {:keys [message-id]} :payload}]]
(let [{:keys [chat-id]} (messages/get-by-id message-id) (let [{:keys [chat-id]} (messages/get-by-id message-id)
message-overhead (chats/get-message-overhead chat-id) message-overhead (chats/get-message-overhead chat-id)
last-clock-value (messages/get-last-clock-value chat-id)] last-clock-value (messages/get-last-clock-value chat-id)]
(if (> message-overhead 0) (if (pos? message-overhead)
(let [last-outgoing (->> (messages/get-last-outgoing chat-id message-overhead) (let [last-outgoing (->> (messages/get-last-outgoing chat-id message-overhead)
(reverse) (reverse)
(map-indexed vector))] (map-indexed vector))]
(chats/reset-message-overhead chat-id) (chats/reset-message-overhead chat-id)
(doseq [[i message] last-outgoing] (doseq [[i message] last-outgoing]
(dispatch [:update-clock-value! from i message (+ last-clock-value 100)]))) (dispatch [:update-clock-value! from i message (+ last-clock-value 100)])))
(dispatch [:send-clock-value! from message-id])))))) (dispatch [:send-clock-value! from message-id]))))))
(register-handler :message-clock-value (register-handler :message-clock-value
(after save-message-clock-value!) (after save-message-clock-value!)

View File

@ -6,7 +6,7 @@
(defn init! (defn init!
[messages] [messages]
(reset! messages-set (into #{} messages)) (reset! messages-set (set messages))
(reset! messages-map (->> messages (reset! messages-map (->> messages
(map (fn [{:keys [message-id type] :as message}] (map (fn [{:keys [message-id type] :as message}]
[[message-id type] message])) [[message-id type] message]))

View File

@ -4,8 +4,6 @@
(def web3 (js/require "web3")) (def web3 (js/require "web3"))
(def status-app-topic "status-app")
(defn from-utf8 [s] (defn from-utf8 [s]
(.fromUtf8 web3.prototype s)) (.fromUtf8 web3.prototype s))
@ -16,8 +14,9 @@
(.-shh web3)) (.-shh web3))
(defn make-web3 [rpc-url] (defn make-web3 [rpc-url]
(->> (web3.providers.HttpProvider. rpc-url) (->> rpc-url
(web3.))) web3.providers.HttpProvider.
web3.))
(defn timestamp [] (defn timestamp []
(to-long (now))) (to-long (now)))

View File

@ -35,7 +35,7 @@
:else (today-format-fn local))))) :else (today-format-fn local)))))
(defn day-relative [ms] (defn day-relative [ms]
(when (> ms 0) (when (pos? ms)
(to-short-str ms #(label :t/datetime-today)))) (to-short-str ms #(label :t/datetime-today))))
(defn format-time-ago [diff unit] (defn format-time-ago [diff unit]

View File

@ -4,8 +4,7 @@
(def Web3 (js/require "web3")) (def Web3 (js/require "web3"))
(defn web3 [] (defn web3 []
(->> (Web3.providers.HttpProvider. c/ethereum-rpc-url) (Web3. (Web3.providers.HttpProvider. c/ethereum-rpc-url)))
(Web3.)))
(def networks (def networks
{"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" :mainnet {"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" :mainnet

View File

@ -5,12 +5,11 @@
(defn- pick-random (defn- pick-random
[vector] [vector]
(-> (rand-nth vector) (str/capitalize (rand-nth vector)))
str/capitalize))
(defn generate-gfy (defn generate-gfy
[] []
(let [first-adjective (pick-random adjectives/data) (let [first-adjective (pick-random adjectives/data)
second-adjective (pick-random adjectives/data) second-adjective (pick-random adjectives/data)
animal (pick-random animals/data)] animal (pick-random animals/data)]
(str first-adjective " " second-adjective " " animal))) (str first-adjective " " second-adjective " " animal)))

View File

@ -12,11 +12,9 @@
(.catch on-error)))) (.catch on-error))))
(defn- image-base64-encode [path on-success on-error] (defn- image-base64-encode [path on-success on-error]
(let [on-encoded (fn [data] (let [on-error (fn [error]
(on-success data))
on-error (fn [error]
(on-error :base64 error))] (on-error :base64 error))]
(read-file path "base64" on-encoded on-error))) (read-file path "base64" on-success on-error)))
(defn img->base64 [path on-success on-error] (defn img->base64 [path on-success on-error]
(let [on-resized (fn [path] (let [on-resized (fn [path]