Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
yenda committed Feb 4, 2019
1 parent bdd7d6d commit a22e382
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/status_im/contact/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
(clojure.string/lower-case name2))))
(vals contacts)))

(defn active
[contacts]
(->> contacts
(remove (fn [[_ {:keys [pending? hide-contact? blocked?]}]]
(or pending? hide-contact? blocked?)))
sort-contacts))

(defn filter-dapps
[v dev-mode?]
(remove #(when-not dev-mode? (true? (:developer? %))) v))
Expand Down Expand Up @@ -131,3 +138,7 @@
(defn get-blocked-contacts
[contacts]
(into #{} (map :public-key (filter :blocked? contacts))))

(defn blocked?
[db contact]
(get-in db [:contacts/contacts contact :blocked?]))
5 changes: 1 addition & 4 deletions src/status_im/contact/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
:contacts/active
:<- [:contacts/contacts]
(fn [contacts]
(->> contacts
(remove (fn [[_ {:keys [pending? hide-contact? blocked?]}]]
(or pending? hide-contact? blocked?)))
(contact.db/sort-contacts))))
(contact.db/active contacts)))

(re-frame/reg-sub
:contacts/active-count
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/data_store/contacts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

(defn- get-messages-by-messages-ids
[message-ids]
(when-not (empty message-ids)
(when (not-empty message-ids)
(-> @core/account-realm
(.objects "message")
(.filtered (str "(" (core/in-query "message-id" message-ids) ")")))))
Expand Down
15 changes: 9 additions & 6 deletions src/status_im/notifications/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[taoensso.timbre :as log]
[status-im.i18n :as i18n]
[status-im.accounts.db :as accounts.db]
[status-im.contact.db :as contact.db]
[status-im.chat.models :as chat-model]
[status-im.utils.platform :as platform]
[status-im.utils.fx :as fx]
Expand Down Expand Up @@ -82,7 +83,7 @@
(:public-key
(first
(filter #(= (anonymize-pubkey (:public-key %)) hash)
(vals accounts)))))
accounts))))

(defn lookup-contact-pubkey-from-hash
[{:keys [db] :as cofx} contact-pubkey-or-hash]
Expand All @@ -93,13 +94,14 @@
(= (count contact-pubkey-or-hash) pn-pubkey-hash-length))
(if-let
[account-pubkey (hash->pubkey contact-pubkey-or-hash
(:accounts/accounts db))]
(vals (:accounts/accounts db)))]
account-pubkey
(if (accounts.db/logged-in? cofx)
;; TODO: for simplicity we're doing a linear lookup of the contacts,
;; but we might want to build a map of hashed pubkeys to pubkeys
;; for this purpose
(hash->pubkey contact-pubkey-or-hash (:contacts/contacts db))
(hash->pubkey contact-pubkey-or-hash
(contact.db/active (:contacts/contacts db)))
(do
(log/warn "failed to lookup contact from hash, not logged in")
contact-pubkey-or-hash)))
Expand Down Expand Up @@ -202,7 +204,7 @@
(and (valid-notification-payload? rehydrated-payload)
(accounts.db/logged-in? cofx)
(some #(= (:public-key %) from)
(vals (:contacts/contacts db)))
(contact.db/active (:contacts/contacts db)))
(some #(= (:chat-id %) from)
(vals (:chats db)))))

Expand Down Expand Up @@ -318,10 +320,10 @@
(create-notification-channel))
(handle-initial-push-notification)))

(fx/defn process-stored-event [cofx address stored-pns]
(fx/defn process-stored-event [{:keys [db] :as cofx} address stored-pns]
(when-not platform/desktop?
(if (accounts.db/logged-in? cofx)
(let [current-account (get-in cofx [:db :account/account])
(let [current-account (:account/account db)
current-address (:address current-account)
current-account-pubkey (:public-key current-account)
stored-pn-val-json (or (get stored-pns current-account-pubkey)
Expand All @@ -333,6 +335,7 @@
from (lookup-contact-pubkey-from-hash cofx (:from stored-pn-payload))
to (lookup-contact-pubkey-from-hash cofx (:to stored-pn-payload))]
(when (and from
(not (contact.db/blocked? db from))
(= address current-address))
(log/debug "process-stored-event" "address" address "from" from "to" to)
(handle-push-notification-open cofx
Expand Down

0 comments on commit a22e382

Please sign in to comment.