Add to Contacts tab does not appear (#636)

This commit is contained in:
alwx 2017-01-16 15:41:02 +03:00 committed by Roman Volosovskyi
parent 285df463e3
commit d08ca05d33
14 changed files with 144 additions and 42 deletions

View File

@ -98,8 +98,8 @@
[chat-icon]]]))))
(defview add-contact-bar []
[pending-contact? [:chat :pending-contact?]
chat-id [:get :current-chat-id]]
[chat-id [:get :current-chat-id]
pending-contact? [:current-contact :pending?]]
(when pending-contact?
[touchable-highlight
{:on-press #(dispatch [:add-pending-contact chat-id])}

View File

@ -47,7 +47,7 @@
(defview pending-contact-badge
[chat-id {:keys [pending-wrapper pending-outer-circle pending-inner-circle]}]
[pending-contact? [:get-in [:chats chat-id :pending-contact?]]]
[pending-contact? [:get-in [:contacts chat-id :pending?]]]
(when pending-contact?
[view pending-wrapper
[view pending-outer-circle

View File

@ -25,7 +25,7 @@
(anim/set-value offline-opacity 0)
(when (or (= @network-status :offline) (= @sync-state :offline))
(start-offline-animation offline-opacity)))
pending-contact? (subscribe [:chat :pending-contact?])
pending-contact? (subscribe [:current-contact :pending?])
view-id (subscribe [:get :view-id])]
(r/create-class
{:component-did-mount

View File

@ -15,7 +15,6 @@
[taoensso.timbre :as log]
[cljs.reader :refer [read-string]]))
(defmethod nav/preload-data! :group-contacts
[db [_ _ group]]
(dissoc
@ -216,12 +215,9 @@
(fn [{:keys [chats contacts]} [_ chat-id]]
(let [contact (if-let [contact-info (get-in chats [chat-id :contact-info])]
(read-string contact-info)
(-> contacts
(get chat-id)
(-> (get contacts chat-id)
(assoc :pending false)))]
(dispatch [::prepare-contact contact])
(dispatch [:update-chat! {:chat-id chat-id
:pending-contact? false}])
(dispatch [:watch-contact contact])
(dispatch [:discoveries-send-portions chat-id])))))
@ -279,8 +275,6 @@
(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)])
(dispatch [:account-update-keys]))))

View File

@ -8,7 +8,8 @@
color-light-gray
color-separator
color-gray2]]
[status-im.components.toolbar.styles :refer [toolbar-background2]]))
[status-im.components.toolbar.styles :refer [toolbar-background2]]
[status-im.utils.platform :as p]))
;; Contacts list
@ -21,7 +22,8 @@
:background-color toolbar-background2})
(def contacts-list-container
{:flex 1})
{:flex 1
:margin-bottom (when p/ios? 72)})
(def empty-contact-groups
(merge contact-groups

View File

@ -3,6 +3,12 @@
(:require [re-frame.core :refer [register-sub subscribe]]
[status-im.utils.identicon :refer [identicon]]))
(register-sub :current-contact
(fn [db [_ k]]
(-> @db
(get-in [:contacts (:current-chat-id @db) k])
(reaction))))
(register-sub :get-contacts
(fn [db _]
(let [contacts (reaction (:contacts @db))]
@ -19,7 +25,7 @@
(register-sub :all-added-contacts
(fn [db _]
(let [contacts (reaction (:contacts @db))]
(->> (remove #(true? (:pending (second %))) @contacts)
(->> (remove #(true? (:pending? (second %))) @contacts)
(sort-contacts)
(reaction)))))

View File

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

View File

@ -11,13 +11,13 @@
(data-store/get-by-id-cljs whisper-identity))
(defn save
[{:keys [whisper-identity pending] :as contact}]
(let [{pending-db :pending
:as contact-db} (data-store/get-by-id whisper-identity)
contact (assoc contact :pending
[{:keys [whisper-identity pending?] :as contact}]
(let [{pending-db? :pending?
:as contact-db} (data-store/get-by-id whisper-identity)
contact (assoc contact :pending?
(boolean (if contact-db
(if (nil? pending) pending-db pending)
pending)))]
(if (nil? pending?) pending-db? pending?)
pending?)))]
(data-store/save contact (if contact-db true false))))
(defn save-all

View File

@ -1,7 +1,11 @@
(ns status-im.data-store.realm.schemas.account.core
(:require [status-im.data-store.realm.schemas.account.v1.core :as v1]))
(:require [status-im.data-store.realm.schemas.account.v1.core :as v1]
[status-im.data-store.realm.schemas.account.v2.core :as v2]))
; put schemas ordered by version
(def schemas [{:schema v1/schema
:schemaVersion 1
:migration v1/migration}])
:migration v1/migration}
{:schema v2/schema
:schemaVersion 2
:migration v2/migration}])

View File

@ -0,0 +1,38 @@
(ns status-im.data-store.realm.schemas.account.v2.chat
(:require [taoensso.timbre :as log]
[status-im.components.styles :refer [default-chat-color]]))
(def schema {:name :chat
:primaryKey :chat-id
:properties {:chat-id :string
:name :string
:color {:type :string
:default default-chat-color}
:group-chat {:type :bool
:indexed true}
:group-admin {:type :string
:optional true}
:is-active :bool
:timestamp :int
:contacts {:type :list
:objectType :chat-contact}
:removed-at {:type :int
:optional true}
:removed-from-at {:type :int
:optional true}
:added-to-at {:type :int
:optional true}
:updated-at {:type :int
:optional true}
:last-message-id :string
:message-overhead {:type :int
:default 0}
:public-key {:type :string
:optional true}
:private-key {:type :string
:optional true}
:contact-info {:type :string
:optional true}}})
(defn migration [old-realm new-realm]
(log/debug "migrating chat schema v2"))

View File

@ -0,0 +1,26 @@
(ns status-im.data-store.realm.schemas.account.v2.contact
(:require [taoensso.timbre :as log]))
(def schema {:name :contact
:primaryKey :whisper-identity
:properties {:address {:type "string" :optional true}
:whisper-identity "string"
:name {:type "string" :optional true}
:photo-path {:type "string" :optional true}
:last-updated {:type "int" :default 0}
:last-online {:type "int" :default 0}
:pending? {:type "bool" :default false}
:status {:type "string" :optional true}
:public-key {:type :string
:optional true}
:private-key {:type :string
:optional true}
:dapp? {:type :bool
:default false}
:dapp-url {:type :string
:optional true}
:dapp-hash {:type :int
:optional true}}})
(defn migration [old-realm new-realm]
(log/debug "migrating contact schema v2"))

View File

@ -0,0 +1,32 @@
(ns status-im.data-store.realm.schemas.account.v2.core
(:require [status-im.data-store.realm.schemas.account.v2.chat :as chat]
[status-im.data-store.realm.schemas.account.v1.chat-contact :as chat-contact]
[status-im.data-store.realm.schemas.account.v1.command :as command]
[status-im.data-store.realm.schemas.account.v2.contact :as contact]
[status-im.data-store.realm.schemas.account.v1.discover :as discover]
[status-im.data-store.realm.schemas.account.v1.kv-store :as kv-store]
[status-im.data-store.realm.schemas.account.v1.message :as message]
[status-im.data-store.realm.schemas.account.v1.pending-message :as pending-message]
[status-im.data-store.realm.schemas.account.v1.processed-message :as processed-message]
[status-im.data-store.realm.schemas.account.v1.request :as request]
[status-im.data-store.realm.schemas.account.v1.tag :as tag]
[status-im.data-store.realm.schemas.account.v1.user-status :as user-status]
[taoensso.timbre :as log]))
(def schema [chat/schema
chat-contact/schema
command/schema
contact/schema
discover/schema
kv-store/schema
message/schema
pending-message/schema
processed-message/schema
request/schema
tag/schema
user-status/schema])
(defn migration [old-realm new-realm]
(log/debug "migrating v2 account database: " old-realm new-realm)
(chat/migration old-realm new-realm)
(contact/migration old-realm new-realm))

View File

@ -385,24 +385,24 @@
(when from
(let [{{:keys [name profile-image address status]} :contact
{:keys [public private]} :keypair} payload
contact {:whisper-identity from
:public-key public
:private-key private
:address address
:status status
:photo-path profile-image
:name name}
contact-exists? (get contacts from)
chat {:name name
:chat-id from
:contact-info (prn-str contact)
:pending-contact? true}]
(if contact-exists?
(do
existing-contact (get contacts from)
contact {:whisper-identity from
:public-key public
:private-key private
:address address
:status status
:photo-path profile-image
:name name}
chat {:name name
:chat-id from
:contact-info (prn-str contact)}]
(if-not existing-contact
(let [contact (assoc contact :pending? true)]
(dispatch [:add-contacts [contact]])
(dispatch [:add-chat from chat]))
(when-not (:pending? existing-contact)
(dispatch [:update-contact! contact])
(dispatch [:watch-contact contact]))
(dispatch [:add-chat from chat])))))))
(dispatch [:watch-contact contact]))))))))
(register-handler ::post-error
(u/side-effect!

View File

@ -35,6 +35,6 @@
(defn identities [contacts]
(->> (map second contacts)
(remove (fn [{:keys [dapp? pending]}]
(or pending dapp?)))
(remove (fn [{:keys [dapp? pending?]}]
(or pending? dapp?)))
(map :whisper-identity)))