From 9f4fd79586c9a1c1c19c0e9e770bf547181b5a58 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 27 Dec 2016 19:45:54 +0200 Subject: [PATCH] kibit suggestion (in progress) --- src/status_im/accounts/handlers.cljs | 2 +- src/status_im/accounts/recover/handlers.cljs | 13 +++-- src/status_im/chat/handlers.cljs | 14 +++--- src/status_im/chat/handlers/console.cljs | 4 +- .../chat/handlers/receive_message.cljs | 2 +- src/status_im/chat/handlers/send_message.cljs | 4 +- src/status_im/chat/sign_up.cljs | 11 ++--- src/status_im/chat/subs.cljs | 4 +- src/status_im/chat/views/actions.cljs | 7 +-- src/status_im/chat/views/message.cljs | 4 +- src/status_im/chat/views/new_message.cljs | 3 +- src/status_im/chat/views/request_message.cljs | 3 +- src/status_im/chat/views/toolbar_content.cljs | 2 +- src/status_im/commands/handlers/loading.cljs | 2 +- .../components/chat_icon/screen.cljs | 9 +--- src/status_im/components/tabs/styles.cljs | 2 +- src/status_im/components/toolbar/styles.cljs | 3 +- src/status_im/components/toolbar/view.cljs | 2 +- src/status_im/contacts/handlers.cljs | 19 +++---- src/status_im/contacts/subs.cljs | 31 ++++++------ src/status_im/contacts/validations.cljs | 3 +- src/status_im/data_store/chats.cljs | 3 +- src/status_im/data_store/discover.cljs | 4 +- src/status_im/data_store/realm/accounts.cljs | 5 +- src/status_im/data_store/realm/chats.cljs | 15 +++--- src/status_im/data_store/realm/contacts.cljs | 6 +-- src/status_im/data_store/realm/core.cljs | 7 +-- src/status_im/data_store/realm/discover.cljs | 9 ++-- src/status_im/data_store/realm/messages.cljs | 11 ++--- .../data_store/realm/processed_messages.cljs | 6 +-- src/status_im/data_store/realm/requests.cljs | 8 +-- src/status_im/discover/subs.cljs | 9 ++-- src/status_im/group_settings/handlers.cljs | 9 ++-- src/status_im/models/commands.cljs | 10 ++-- src/status_im/protocol/chat.cljs | 22 ++++----- src/status_im/protocol/discoveries.cljs | 22 ++++----- src/status_im/protocol/encryption.cljs | 3 +- src/status_im/protocol/handlers.cljs | 49 ++++++++++--------- src/status_im/protocol/message_cache.cljs | 2 +- src/status_im/protocol/web3/utils.cljs | 7 ++- src/status_im/utils/datetime.cljs | 2 +- src/status_im/utils/ethereum_network.cljs | 3 +- src/status_im/utils/gfycat/core.cljs | 5 +- src/status_im/utils/image_processing.cljs | 6 +-- 44 files changed, 173 insertions(+), 194 deletions(-) diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 3cee34ce33..b671f2ef3b 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -94,7 +94,7 @@ (not= status old-status))] (when status-updated? (let [hashtags (get-hashtags status)] - (when-not (empty? hashtags) + (when (seq hashtags) (dispatch [:broadcast-status status hashtags])))))))) (register-handler diff --git a/src/status_im/accounts/recover/handlers.cljs b/src/status_im/accounts/recover/handlers.cljs index c98f70c8d0..d4cc7fd866 100644 --- a/src/status_im/accounts/recover/handlers.cljs +++ b/src/status_im/accounts/recover/handlers.cljs @@ -23,18 +23,17 @@ :updates-private-key private :signed-up? true}] (log/debug "account-recovered") - (when (not (str/blank? public-key)) - (do - (dispatch [:set-in [:recover :passphrase] ""]) - (dispatch [:set-in [:recover :password] ""]) - (dispatch [:add-account account]) - (dispatch [:navigate-back]))))) + (when-not (str/blank? public-key) + (dispatch [:set-in [:recover :passphrase] ""]) + (dispatch [:set-in [:recover :password] ""]) + (dispatch [:add-account account]) + (dispatch [:navigate-back])))) (defn recover-account [_ [_ passphrase password]] (status/recover-account passphrase password - (fn [result] (account-recovered result)))) + account-recovered)) (register-handler :recover-account (u/side-effect! recover-account)) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 8a3c4d2852..2f6c0561b2 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -254,7 +254,7 @@ (register-handler :account-generation-message (u/side-effect! (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))))) (register-handler :show-mnemonic @@ -449,12 +449,12 @@ (chats/save chat'))) (register-handler :update-chat! - (-> (fn [db [_ {:keys [chat-id name] :as chat}]] - (let [chat' (if name chat (dissoc chat :name))] - (if (get-in db [:chats chat-id]) - (update-in db [:chats chat-id] merge chat') - db))) - ((after update-chat!)))) + (after update-chat!) + (fn [db [_ {:keys [chat-id name] :as chat}]] + (let [chat' (if name chat (dissoc chat :name))] + (if (get-in db [:chats chat-id]) + (update-in db [:chats chat-id] merge chat') + db)))) (register-handler :upsert-chat! (fn [db [_ {:keys [chat-id] :as opts}]] diff --git a/src/status_im/chat/handlers/console.cljs b/src/status_im/chat/handlers/console.cljs index 851d98fdd0..858ffba427 100644 --- a/src/status_im/chat/handlers/console.cljs +++ b/src/status_im/chat/handlers/console.cljs @@ -53,9 +53,7 @@ (let [{:keys [name]} command] (case name "js" (let [{:keys [err data messages]} handler-data - content (if err - err - data)] + content (or err data)] (doseq [message messages] (let [{:keys [message type]} message] (dispatch [:received-message diff --git a/src/status_im/chat/handlers/receive_message.cljs b/src/status_im/chat/handlers/receive_message.cljs index 85f62ba427..a33f39fbd5 100644 --- a/src/status_im/chat/handlers/receive_message.cljs +++ b/src/status_im/chat/handlers/receive_message.cljs @@ -41,7 +41,7 @@ exists? (chats/exists? chat-id') active? (chats/is-active? 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) clock-value)] (when (and (not same-message) diff --git a/src/status_im/chat/handlers/send_message.cljs b/src/status_im/chat/handlers/send_message.cljs index cb4ea593b7..63652b9eae 100644 --- a/src/status_im/chat/handlers/send_message.cljs +++ b/src/status_im/chat/handlers/send_message.cljs @@ -228,9 +228,7 @@ (u/side-effect! (fn [_ [_ chat-id {:keys [returned]}]] (let [{:keys [data messages err]} returned - content (if err - err - data)] + content (or err data)] (doseq [message messages] (let [{:keys [message type]} message] (dispatch [:received-message diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index 960f189c94..344d5f2f15 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -47,7 +47,7 @@ (dispatch [:sign-up-confirm (second matches)]))) (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)) db)) @@ -83,11 +83,10 @@ :to "me"}]) (let [status (keyword (:status body))] (when (= :confirmed status) - (do - (dispatch [:stop-listening-confirmation-code-sms]) - (sync-contacts) - ;; TODO should be called after sync-contacts? - (dispatch [:set-signed-up true]))) + (dispatch [:stop-listening-confirmation-code-sms]) + (sync-contacts) + ;; TODO should be called after sync-contacts? + (dispatch [:set-signed-up true])) (when (= :failed status) (on-sign-up-response (label :t/incorrect-code))))) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index b921d42977..45fbd2881f 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -184,7 +184,7 @@ (register-sub :is-request-answered? (fn [_ [_ message-id]] (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 (fn [db] @@ -211,7 +211,7 @@ (let [chat-id (subscribe [:get-current-chat-id])] (reaction (min (get-in @db [:animations :to-response-height @chat-id]) - (if (> (:layout-height @db) 0) + (if (pos? (:layout-height @db)) (- (:layout-height @db) (get-in platform-specific [:component-styles :status-bar status-bar :height])) 0)))))) diff --git a/src/status_im/chat/views/actions.cljs b/src/status_im/chat/views/actions.cljs index 7e4ecd6664..a7907a68ca 100644 --- a/src/status_im/chat/views/actions.cljs +++ b/src/status_im/chat/views/actions.cljs @@ -23,7 +23,7 @@ [chat-icon-view-menu-item chat-id group-chat name color true]) (defn- members-text [members] - (str (s/join ", " (map #(:name %) members)) + (str (s/join ", " (map :name members)) " " (label :t/and-you))) @@ -121,8 +121,9 @@ (when-let [actions (if @group-chat (group-chat-items @members) (user-chat-items @chat-id))] - [view (-> (st/actions-wrapper status-bar-height) - (merge (get-in platform-specific [:component-styles :actions-list-view]))) + [view (merge + (st/actions-wrapper status-bar-height) + (get-in platform-specific [:component-styles :actions-list-view])) [view st/actions-separator] [view st/actions-view (for [action actions] diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index ee6a444aff..40e29ca4fb 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -185,7 +185,7 @@ [text {:key (str idx "_" string) :style style} - (subs string 1 (- (count string) 1))])) + (subs string 1 (dec (count string)))])) (re-seq regx string))) styled-text' (if (> (count general-text) (count styled-text)) @@ -331,7 +331,7 @@ (defn message-container-animation-logic [{:keys [to-value val callback]}] (fn [_] (let [to-value @to-value] - (when (< 0 to-value) + (when (pos? to-value) (anim/start (anim/timing val {:toValue to-value :duration 250}) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 07cdda5e8f..71ddf6c7a1 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -33,8 +33,7 @@ type [:command-type] suggestions [:get-suggestions] message-input-height [:get-message-input-view-height]] - (let [on-top? (or (and (not (empty? suggestions)) - (not command?)) + (let [on-top? (or (and (seq suggestions) (not command?)) (not= response-height input-height)) style (get-in platform-specific [:component-styles :chat :new-message])] [view {:style (merge (st/new-message-container margin on-top?) style) diff --git a/src/status_im/chat/views/request_message.cljs b/src/status_im/chat/views/request_message.cljs index 18cb9bb2bc..4e9f7be246 100644 --- a/src/status_im/chat/views/request_message.cljs +++ b/src/status_im/chat/views/request_message.cljs @@ -20,7 +20,8 @@ (defn label [command] (when command - (->> (name (:name command)) + (->> (:name command) + name (str "request-")))) (def min-scale 1) diff --git a/src/status_im/chat/views/toolbar_content.cljs b/src/status_im/chat/views/toolbar_content.cljs index bcabd4ea8d..312d67ec0e 100644 --- a/src/status_im/chat/views/toolbar_content.cljs +++ b/src/status_im/chat/views/toolbar_content.cljs @@ -22,7 +22,7 @@ contact (let [last-online (get contact :last-online) last-online-date (time/to-date last-online) now-date (t/now)] - (if (and (> last-online 0) + (if (and (pos? last-online) (<= last-online-date now-date)) (time/time-ago last-online-date) (label :t/active-unknown))) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 3db3ae0eae..18f1d146e7 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -93,7 +93,7 @@ registered-only))) (remove (fn [[n]] (and - (not (= console-chat-id id)) + (not= console-chat-id id) (h/matches (name n) "password")))) (into {}))) diff --git a/src/status_im/components/chat_icon/screen.cljs b/src/status_im/components/chat_icon/screen.cljs index ef811759bc..dc79e7c218 100644 --- a/src/status_im/components/chat_icon/screen.cljs +++ b/src/status_im/components/chat_icon/screen.cljs @@ -158,18 +158,11 @@ :default-chat-icon (st/default-chat-icon-profile color) :default-chat-icon-text st/default-chat-icon-text}] [view (:container styles) - (if (and photo-path (not (empty? photo-path))) + (if (and photo-path (seq photo-path)) [chat-icon photo-path styles] [default-chat-icon name 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 edit? :edit?}] (let [type (if edit? :edit :blank) diff --git a/src/status_im/components/tabs/styles.cljs b/src/status_im/components/tabs/styles.cljs index 0040b76099..9bcf0f2866 100644 --- a/src/status_im/components/tabs/styles.cljs +++ b/src/status_im/components/tabs/styles.cljs @@ -2,7 +2,7 @@ (:require [status-im.components.styles :refer [color-white]])) (def tabs-height 56) -(def tab-height (- tabs-height 1)) +(def tab-height (dec tabs-height)) (def bottom-gradient {:position :absolute diff --git a/src/status_im/components/toolbar/styles.cljs b/src/status_im/components/toolbar/styles.cljs index 0e4a57acc1..82a5f0db45 100644 --- a/src/status_im/components/toolbar/styles.cljs +++ b/src/status_im/components/toolbar/styles.cljs @@ -48,8 +48,7 @@ (defn toolbar-actions-container [actions-count custom] (merge {:flex-direction "row" :margin-left toolbar-icon-spacing} - (when (and (= actions-count 0) - (not custom)) + (when (and (zero? actions-count) (not custom)) {:width (+ toolbar-icon-width toolbar-icon-spacing)}))) (def toolbar-action diff --git a/src/status_im/components/toolbar/view.cljs b/src/status_im/components/toolbar/view.cljs index 8997450515..6eae85a743 100644 --- a/src/status_im/components/toolbar/view.cljs +++ b/src/status_im/components/toolbar/view.cljs @@ -25,7 +25,7 @@ [view {:style style} [view st/toolbar [view (st/toolbar-nav-actions-container actions) - (when (not hide-nav?) + (when-not hide-nav? (if nav-action [touchable-highlight {:on-press (:handler nav-action)} [view (get-in platform-specific [:component-styles :toolbar-nav-action]) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 10b8a5369b..e1a959a698 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -208,15 +208,16 @@ ((after send-contact-request)))) (register-handler ::update-pending-contact - (-> add-new-contact - ((after save-contact)))) + (after save-contact) + add-new-contact) (register-handler :add-pending-contact (u/side-effect! (fn [{:keys [chats contacts]} [_ chat-id]] (let [contact (if-let [contact-info (get-in chats [chat-id :contact-info])] (read-string contact-info) - (-> (get contacts chat-id) + (-> contacts + (get chat-id) (assoc :pending false)))] (dispatch [::prepare-contact contact]) (dispatch [:update-chat! {:chat-id chat-id @@ -259,12 +260,12 @@ :last-online timestamp}])))))) (register-handler :remove-contact - (-> (u/side-effect! - (fn [_ [_ {:keys [whisper-identity] :as contact}]] - (dispatch [:update-chat! {:chat-id whisper-identity - :pending-contact? true}]) - (dispatch [:update-contact! (assoc contact :pending true)]))) - ((after stop-watching-contact)))) + (after stop-watching-contact) + (u/side-effect! + (fn [_ [_ {:keys [whisper-identity] :as contact}]] + (dispatch [:update-chat! {:chat-id whisper-identity + :pending-contact? true}]) + (dispatch [:update-contact! (assoc contact :pending true)])))) (register-handler :open-contact-menu (u/side-effect! diff --git a/src/status_im/contacts/subs.cljs b/src/status_im/contacts/subs.cljs index 102d5f7528..e62ea1dba0 100644 --- a/src/status_im/contacts/subs.cljs +++ b/src/status_im/contacts/subs.cljs @@ -9,12 +9,12 @@ (reaction @contacts)))) (defn sort-contacts [contacts] - (->> (vals contacts) - (sort (fn [c1 c2] - (let [name1 (or (:name c1) (:address c1) (:whisper-identity c1)) - name2 (or (:name c2) (:address c2) (:whisper-identity c2))] - (compare (clojure.string/lower-case name1) - (clojure.string/lower-case name2))))))) + (sort (fn [c1 c2] + (let [name1 (or (:name c1) (:address c1) (:whisper-identity c1)) + name2 (or (:name c2) (:address c2) (:whisper-identity c2))] + (compare (clojure.string/lower-case name1) + (clojure.string/lower-case name2)))) + (vals contacts))) (register-sub :all-added-contacts (fn [db _] @@ -112,16 +112,13 @@ chat (reaction (get-in @db [:chats chat-id])) contacts (contacts-by-chat filter db chat-id)] (reaction - (when @chat - (if (:group-chat @chat) - ;; TODO return group chat icon - nil - (cond - (:photo-path @chat) - (:photo-path @chat) + (when (and @chat (not (:group-chat @chat))) + (cond + (:photo-path @chat) + (:photo-path @chat) - (pos? (count @contacts)) - (:photo-path (first @contacts)) + (pos? (count @contacts)) + (:photo-path (first @contacts)) - :else - (identicon chat-id)))))))) + :else + (identicon chat-id))))))) diff --git a/src/status_im/contacts/validations.cljs b/src/status_im/contacts/validations.cljs index ce256e057d..62bdb6a686 100644 --- a/src/status_im/contacts/validations.cljs +++ b/src/status_im/contacts/validations.cljs @@ -9,8 +9,7 @@ (defn contact-can-be-added? [identity] (if (contacts/exists? identity) - (-> (contacts/get-by-id identity) - (get :pending)) + (:pending (contacts/get-by-id identity)) true)) (defn valid-length? [identity] diff --git a/src/status_im/data_store/chats.cljs b/src/status_im/data_store/chats.cljs index 5845b2dc8c..58f73645b3 100644 --- a/src/status_im/data_store/chats.cljs +++ b/src/status_im/data_store/chats.cljs @@ -9,8 +9,7 @@ (defn get-all [] - (-> (data-store/get-all-active) - normalize-contacts)) + (normalize-contacts (data-store/get-all-active))) (defn get-by-id [id] diff --git a/src/status_im/data_store/discover.cljs b/src/status_im/data_store/discover.cljs index 23108fd516..fbd86e49f8 100644 --- a/src/status_im/data_store/discover.cljs +++ b/src/status_im/data_store/discover.cljs @@ -4,8 +4,8 @@ (defn get-all [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 [discover] diff --git a/src/status_im/data_store/realm/accounts.cljs b/src/status_im/data_store/realm/accounts.cljs index 44bd4ad0a3..4551da71a7 100644 --- a/src/status_im/data_store/realm/accounts.cljs +++ b/src/status_im/data_store/realm/accounts.cljs @@ -5,8 +5,7 @@ (realm/get-all realm/base-realm :account)) (defn get-all-as-list [] - (-> (get-all) - realm/realm-collection->list)) + (realm/realm-collection->list (get-all))) (defn get-by-address [address] (realm/get-one-by-field-clj realm/base-realm :account :address address)) @@ -18,4 +17,4 @@ (defn save-all [accounts update?] (realm/write realm/base-realm (fn [] - (mapv #(realm/create realm/base-realm :account % update?) accounts)))) \ No newline at end of file + (mapv #(realm/create realm/base-realm :account % update?) accounts)))) diff --git a/src/status_im/data_store/realm/chats.cljs b/src/status_im/data_store/realm/chats.cljs index 50a30047cc..ec24c5b70e 100644 --- a/src/status_im/data_store/realm/chats.cljs +++ b/src/status_im/data_store/realm/chats.cljs @@ -5,13 +5,13 @@ (defn get-all [] - (-> (realm/get-all @realm/account-realm :chat) + (-> @realm/account-realm + (realm/get-all :chat) (realm/sorted :timestamp :desc))) (defn get-all-as-list [] - (-> (get-all) - realm/realm-collection->list)) + (realm/realm-collection->list (get-all))) (defn get-all-active [] @@ -36,7 +36,8 @@ (defn get-by-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))) (defn save @@ -58,7 +59,8 @@ (defn get-contacts [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"))) (defn has-contact? @@ -102,7 +104,8 @@ [chat-id property-name value] (realm/write @realm/account-realm (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))))) (defn get-property diff --git a/src/status_im/data_store/realm/contacts.cljs b/src/status_im/data_store/realm/contacts.cljs index 7efe73eee4..ed51c675ed 100644 --- a/src/status_im/data_store/realm/contacts.cljs +++ b/src/status_im/data_store/realm/contacts.cljs @@ -4,13 +4,13 @@ (defn get-all [] - (-> (realm/get-all @realm/account-realm :contact) + (-> @realm/account-realm + (realm/get-all :contact) (realm/sorted :name :asc))) (defn get-all-as-list [] - (-> (get-all) - realm/realm-collection->list)) + (realm/realm-collection->list (get-all))) (defn get-by-id [whisper-identity] diff --git a/src/status_im/data_store/realm/core.cljs b/src/status_im/data_store/realm/core.cljs index 374b714ac0..760ed6f2c5 100644 --- a/src/status_im/data_store/realm/core.cljs +++ b/src/status_im/data_store/realm/core.cljs @@ -35,7 +35,6 @@ (open-realm (last schemas) file-name)) (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)) @@ -122,7 +121,8 @@ (.filtered results filter-query)) (defn realm-collection->list [collection] - (-> (.map collection (fn [object _ _] object)) + (-> collection + (.map (fn [object _ _] object)) (js->clj :keywordize-keys true))) (defn list->array [record list-field] @@ -136,7 +136,8 @@ (js->clj :keywordize-keys true))) (defn get-by-filter [realm schema-name filter] - (-> (.objects realm (name schema-name)) + (-> realm + (.objects (name schema-name)) (.filtered filter))) (defn- get-schema-by-name [opts] diff --git a/src/status_im/data_store/realm/discover.cljs b/src/status_im/data_store/realm/discover.cljs index 104477989c..14eab22977 100644 --- a/src/status_im/data_store/realm/discover.cljs +++ b/src/status_im/data_store/realm/discover.cljs @@ -5,13 +5,13 @@ (defn get-all [ordering] - (-> (realm/get-all @realm/account-realm :discover) + (-> @realm/account-realm + (realm/get-all :discover) (realm/sorted :created-at ordering))) (defn get-all-as-list [ordering] - (-> (get-all ordering) - realm/realm-collection->list)) + (realm/realm-collection->list (get-all ordering))) (defn get-tag-by-name [tag] (log/debug "Getting tag: " tag) @@ -65,7 +65,8 @@ (let [discoveries (realm/get-all @realm/account-realm :discover) count (realm/get-count discoveries)] (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/write @realm/account-realm (fn [] diff --git a/src/status_im/data_store/realm/messages.cljs b/src/status_im/data_store/realm/messages.cljs index 5e53ddcb6d..dc08d1bf84 100644 --- a/src/status_im/data_store/realm/messages.cljs +++ b/src/status_im/data_store/realm/messages.cljs @@ -9,8 +9,7 @@ (defn get-all-as-list [] - (-> (get-all) - realm/realm-collection->list)) + (realm/realm-collection->list (get-all))) (defn get-by-id [message-id] @@ -29,8 +28,7 @@ (defn get-count-by-chat-id [chat-id] - (-> (get-by-chat-id chat-id) - (realm/get-count))) + (realm/get-count (get-by-chat-id chat-id))) (defn get-by-fields [fields from number-of-messages] @@ -47,8 +45,9 @@ (defn get-unviewed [] - (-> (realm/get-by-fields @realm/account-realm :message :and {:outgoing false - :message-status nil}) + (-> @realm/account-realm + (realm/get-by-fields :message :and {:outgoing false + :message-status nil}) (realm/realm-collection->list))) (defn exists? diff --git a/src/status_im/data_store/realm/processed_messages.cljs b/src/status_im/data_store/realm/processed_messages.cljs index 917f807d29..d1245b381c 100644 --- a/src/status_im/data_store/realm/processed_messages.cljs +++ b/src/status_im/data_store/realm/processed_messages.cljs @@ -4,7 +4,8 @@ (defn get-all [] - (-> (realm/get-all @realm/account-realm :processed-message) + (-> @realm/account-realm + (realm/get-all :processed-message) (realm/sorted :ttl :asc))) (defn get-filtered @@ -13,8 +14,7 @@ (defn get-filtered-as-list [condition] - (-> (get-filtered condition) - realm/realm-collection->list)) + (realm/realm-collection->list (get-filtered condition))) (defn save [processed-message] diff --git a/src/status_im/data_store/realm/requests.cljs b/src/status_im/data_store/realm/requests.cljs index d87c1bbc77..75191f4f3e 100644 --- a/src/status_im/data_store/realm/requests.cljs +++ b/src/status_im/data_store/realm/requests.cljs @@ -7,8 +7,7 @@ (defn get-all-as-list [] - (-> (get-all) - realm/realm-collection->list)) + (realm/realm-collection->list (get-all))) (defn get-open-by-chat-id [chat-id] @@ -27,8 +26,9 @@ (defn- get-by-message-id [chat-id message-id] - (-> (realm/get-by-fields @realm/account-realm :request :and [[:chat-id chat-id] - [:message-id message-id]]) + (-> @realm/account-realm + (realm/get-by-fields :request :and [[:chat-id chat-id] + [:message-id message-id]]) (realm/single))) (defn mark-as-answered diff --git a/src/status_im/discover/subs.cljs b/src/status_im/discover/subs.cljs index 6849df82ec..734aa01eab 100644 --- a/src/status_im/discover/subs.cljs +++ b/src/status_im/discover/subs.cljs @@ -18,7 +18,8 @@ (defn- get-discoveries-by-tags [discoveries current-tag tags] (let [tags' (or tags [current-tag])] - (filter #(every? (->> (map :name (:tags %)) + (filter #(every? (->> (:tags %) + (map :name) (into (hash-set))) tags') (vals discoveries)))) @@ -42,13 +43,11 @@ (register-sub :get-popular-tags (fn [db [_ limit]] - (-> (take limit (:tags @db)) - (reaction)))) + (reaction (take limit (:tags @db))))) (register-sub :get-discover-search-results (fn [db _] (let [discoveries (reaction (:discoveries @db)) current-tag (reaction (:current-tag @db)) tags (reaction (:discover-search-tags @db))] - (-> (get-discoveries-by-tags @discoveries @current-tag @tags) - (reaction))))) + (reaction (get-discoveries-by-tags @discoveries @current-tag @tags))))) diff --git a/src/status_im/group_settings/handlers.cljs b/src/status_im/group_settings/handlers.cljs index bb6e411c00..6eb4ae4289 100644 --- a/src/status_im/group_settings/handlers.cljs +++ b/src/status_im/group_settings/handlers.cljs @@ -31,14 +31,13 @@ (assoc-in db [:chats current-chat-id property-name] property)))) (defn prepare-chat-settings - [{:keys [current-chat-id] :as db} _] + [{:keys [current-chat-id] :as db}] (let [{:keys [name color]} (-> db (get-in [:chats current-chat-id]) (select-keys [:name :color]))] - (-> db - (assoc :new-chat-name name - :new-chat-color color - :group-settings {})))) + (assoc db :new-chat-name name + :new-chat-color color + :group-settings {}))) (register-handler :show-group-settings (after (fn [_ _] (dispatch [:navigate-to :group-settings]))) diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index 9ac9fab2ee..e9595012e8 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -42,13 +42,13 @@ ([db type message-id command-key] (set-command-input db type message-id command-key nil)) ([{:keys [current-chat-id] :as db} type message-id command-key params] - (let [command (-> (get-response-or-command type db command-key) - (add-params params)) - first-parameter (get (:params command) 0) - value (:value first-parameter)] + (let [command (get-response-or-command type db command-key) + command' (add-params command params) + first-parameter (get (:params command') 0) + value (:value first-parameter)] (update-in db [:chats current-chat-id :command-input] merge {:content value - :command command + :command command' :parameter-idx 0 :params params :to-message-id message-id})))) diff --git a/src/status_im/protocol/chat.cljs b/src/status_im/protocol/chat.cljs index 65db94f34e..427adacd19 100644 --- a/src/status_im/protocol/chat.cljs +++ b/src/status_im/protocol/chat.cljs @@ -45,20 +45,18 @@ [{:keys [web3 message]}] (debug :send-clock-value-request message) (d/add-pending-message! - web3 - (merge message-defaults - (-> message - (assoc - :type :clock-value-request - :requires-ack? false))))) + web3 + (merge message-defaults + (assoc message + :type :clock-value-request + :requires-ack? false)))) (defn send-clock-value! [{:keys [web3 message]}] (debug :send-clock-value message) (d/add-pending-message! - web3 - (merge message-defaults - (-> message - (assoc - :type :clock-value - :requires-ack? false))))) + web3 + (merge message-defaults + (assoc message + :type :clock-value + :requires-ack? false)))) diff --git a/src/status_im/protocol/discoveries.cljs b/src/status_im/protocol/discoveries.cljs index 9bffca3120..f3a61cdfcc 100644 --- a/src/status_im/protocol/discoveries.cljs +++ b/src/status_im/protocol/discoveries.cljs @@ -115,9 +115,8 @@ (defn send-status! [{:keys [web3 message]}] (debug :broadcasting-status) - (let [message (-> message - (assoc :type :discover - :topics [(make-discover-topic (:from message))]))] + (let [message (assoc message :type :discover + :topics [(make-discover-topic (:from message))])] (d/add-pending-message! web3 message))) (defn send-discoveries-request! @@ -125,19 +124,18 @@ (debug :sending-discoveries-request) (d/add-pending-message! web3 - (-> message - (assoc :type :discoveries-request - :topics [(make-discover-topic (:from message))])))) + (assoc message :type :discoveries-request + :topics [(make-discover-topic (:from message))]))) (defn send-discoveries-response! [{:keys [web3 discoveries message]}] (debug :sending-discoveries-response) - (doseq [portion (->> (take 100 discoveries) + (doseq [portion (->> discoveries + (take 100) (partition 10 10 nil))] (d/add-pending-message! web3 - (-> message - (assoc :type :discoveries-response - :topics [(make-discover-topic (:from message))] - :message-id (random/id) - :payload {:data (into [] portion)}))))) + (assoc message :type :discoveries-response + :topics [(make-discover-topic (:from message))] + :message-id (random/id) + :payload {:data (into [] portion)})))) diff --git a/src/status_im/protocol/encryption.cljs b/src/status_im/protocol/encryption.cljs index 13043b7656..cc4791bc20 100644 --- a/src/status_im/protocol/encryption.cljs +++ b/src/status_im/protocol/encryption.cljs @@ -8,7 +8,8 @@ "Returns {:private \"private key\" :public \"public key\"" [] (let [{:keys [enc dec]} - (-> (.generate ecc (.-ENC_DEC ecc) default-curve) + (-> ecc + (.generate (.-ENC_DEC ecc) default-curve) (js->clj :keywordize-keys true))] {:private dec :public enc})) diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 6c4718a694..feb0b987fb 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -16,7 +16,8 @@ [status-im.utils.datetime :as dt] [taoensso.timbre :as log :refer-macros [debug]] [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 (fn [db [_ current-account-id]] @@ -75,10 +76,11 @@ (register-handler :initialize-sync-listener (fn [{:keys [web3 sync-listener] :as db} _] (if-not sync-listener - (->> (.isSyncing (.-eth web3) - (fn [error sync] - (dispatch [:update-sync-state error sync]))) - (assoc db :sync-listener)) + (let [sync-listener (.isSyncing + (.-eth web3) + (fn [error sync] + (dispatch [:update-sync-state error sync])))] + (assoc db :sync-listener sync-listener)) db))) (register-handler :incoming-message @@ -152,13 +154,15 @@ [identity from {:keys [message-id timestamp]}] (let [remover-name (:name (contacts/get-by-id from)) 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)))) (defn you-removed-from-group-message [from {:keys [message-id timestamp]}] (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)))) (defn participant-left-group-message @@ -198,10 +202,9 @@ [_ {:keys [from] {:keys [group-id timestamp] :as payload} :payload}]] (when (chats/new-update? timestamp group-id) - (let [message - (-> (you-removed-from-group-message from payload) - (assoc :group-id group-id))] - (dispatch [:received-message message])) + (let [message (you-removed-from-group-message from payload) + message' (assoc message :group-id group-id)] + (dispatch [:received-message message'])) (protocol/stop-watching-group! {:web3 web3 :group-id group-id}) (dispatch [:update-chat! {:chat-id group-id @@ -329,18 +332,18 @@ (register-handler :message-clock-value-request (u/side-effect! - (fn [_ [_ {:keys [from] {:keys [message-id]} :payload}]] - (let [{:keys [chat-id]} (messages/get-by-id message-id) - message-overhead (chats/get-message-overhead chat-id) - last-clock-value (messages/get-last-clock-value chat-id)] - (if (> message-overhead 0) - (let [last-outgoing (->> (messages/get-last-outgoing chat-id message-overhead) - (reverse) - (map-indexed vector))] - (chats/reset-message-overhead chat-id) - (doseq [[i message] last-outgoing] - (dispatch [:update-clock-value! from i message (+ last-clock-value 100)]))) - (dispatch [:send-clock-value! from message-id])))))) + (fn [_ [_ {:keys [from] {:keys [message-id]} :payload}]] + (let [{:keys [chat-id]} (messages/get-by-id message-id) + message-overhead (chats/get-message-overhead chat-id) + last-clock-value (messages/get-last-clock-value chat-id)] + (if (pos? message-overhead) + (let [last-outgoing (->> (messages/get-last-outgoing chat-id message-overhead) + (reverse) + (map-indexed vector))] + (chats/reset-message-overhead chat-id) + (doseq [[i message] last-outgoing] + (dispatch [:update-clock-value! from i message (+ last-clock-value 100)]))) + (dispatch [:send-clock-value! from message-id])))))) (register-handler :message-clock-value (after save-message-clock-value!) diff --git a/src/status_im/protocol/message_cache.cljs b/src/status_im/protocol/message_cache.cljs index 969ae7041b..db9a4fbdc9 100644 --- a/src/status_im/protocol/message_cache.cljs +++ b/src/status_im/protocol/message_cache.cljs @@ -6,7 +6,7 @@ (defn init! [messages] - (reset! messages-set (into #{} messages)) + (reset! messages-set (set messages)) (reset! messages-map (->> messages (map (fn [{:keys [message-id type] :as message}] [[message-id type] message])) diff --git a/src/status_im/protocol/web3/utils.cljs b/src/status_im/protocol/web3/utils.cljs index 487d763b03..8d8bdd4b29 100644 --- a/src/status_im/protocol/web3/utils.cljs +++ b/src/status_im/protocol/web3/utils.cljs @@ -4,8 +4,6 @@ (def web3 (js/require "web3")) -(def status-app-topic "status-app") - (defn from-utf8 [s] (.fromUtf8 web3.prototype s)) @@ -16,8 +14,9 @@ (.-shh web3)) (defn make-web3 [rpc-url] - (->> (web3.providers.HttpProvider. rpc-url) - (web3.))) + (->> rpc-url + web3.providers.HttpProvider. + web3.)) (defn timestamp [] (to-long (now))) diff --git a/src/status_im/utils/datetime.cljs b/src/status_im/utils/datetime.cljs index 24d82741c9..103f81d855 100644 --- a/src/status_im/utils/datetime.cljs +++ b/src/status_im/utils/datetime.cljs @@ -35,7 +35,7 @@ :else (today-format-fn local))))) (defn day-relative [ms] - (when (> ms 0) + (when (pos? ms) (to-short-str ms #(label :t/datetime-today)))) (defn format-time-ago [diff unit] diff --git a/src/status_im/utils/ethereum_network.cljs b/src/status_im/utils/ethereum_network.cljs index 2fb3ca707c..5a73547b27 100644 --- a/src/status_im/utils/ethereum_network.cljs +++ b/src/status_im/utils/ethereum_network.cljs @@ -4,8 +4,7 @@ (def Web3 (js/require "web3")) (defn web3 [] - (->> (Web3.providers.HttpProvider. c/ethereum-rpc-url) - (Web3.))) + (Web3. (Web3.providers.HttpProvider. c/ethereum-rpc-url))) (def networks {"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" :mainnet diff --git a/src/status_im/utils/gfycat/core.cljs b/src/status_im/utils/gfycat/core.cljs index ce261d0600..c2539aab2b 100644 --- a/src/status_im/utils/gfycat/core.cljs +++ b/src/status_im/utils/gfycat/core.cljs @@ -5,12 +5,11 @@ (defn- pick-random [vector] - (-> (rand-nth vector) - str/capitalize)) + (str/capitalize (rand-nth vector))) (defn generate-gfy [] (let [first-adjective (pick-random adjectives/data) second-adjective (pick-random adjectives/data) animal (pick-random animals/data)] - (str first-adjective " " second-adjective " " animal))) \ No newline at end of file + (str first-adjective " " second-adjective " " animal))) diff --git a/src/status_im/utils/image_processing.cljs b/src/status_im/utils/image_processing.cljs index e10f627da0..b639e33e1e 100644 --- a/src/status_im/utils/image_processing.cljs +++ b/src/status_im/utils/image_processing.cljs @@ -12,11 +12,9 @@ (.catch on-error)))) (defn- image-base64-encode [path on-success on-error] - (let [on-encoded (fn [data] - (on-success data)) - on-error (fn [error] + (let [on-error (fn [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] (let [on-resized (fn [path]