[ISSUE #3520] Allow adding/chatting with contacts from public chats
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
parent
2653cebd7d
commit
8c6dde8e06
|
@ -24,7 +24,7 @@
|
|||
pending-contact? [:current-contact :pending?]]
|
||||
(when pending-contact?
|
||||
[react/touchable-highlight
|
||||
{:on-press #(re-frame/dispatch [:add-pending-contact chat-id])}
|
||||
{:on-press #(re-frame/dispatch [:add-contact chat-id])}
|
||||
[react/view style/add-contact
|
||||
[react/text {:style style/add-contact-text}
|
||||
(i18n/label :t/add-to-contacts)]]])))
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
[status-im.data-store.contacts :as contacts]
|
||||
[clojure.string :as s]
|
||||
[status-im.protocol.core :as protocol]
|
||||
[status-im.utils.contacts :as utils.contacts]
|
||||
[status-im.utils.utils :refer [http-post]]
|
||||
[status-im.utils.random :as random]
|
||||
[taoensso.timbre :as log]
|
||||
|
@ -11,8 +12,6 @@
|
|||
[status-im.utils.js-resources :as js-res]
|
||||
[status-im.react-native.js-dependencies :as rn-dependencies]
|
||||
[status-im.js-dependencies :as dependencies]
|
||||
[status-im.utils.identicon :refer [identicon]]
|
||||
[status-im.utils.gfycat.core :refer [generate-gfy]]
|
||||
[status-im.i18n :refer [label]]
|
||||
[status-im.ui.screens.contacts.navigation]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
|
@ -259,21 +258,12 @@
|
|||
(assoc-in [:db :contacts/new-identity] "")
|
||||
(assoc ::save-contact contact)))
|
||||
|
||||
(register-handler-fx
|
||||
:add-new-contact-and-open-chat
|
||||
(fn [{:keys [db]} [_ {:keys [whisper-identity] :as contact}]]
|
||||
(when-not (get-in db [:contacts/contacts whisper-identity])
|
||||
(let [contact (assoc contact :address (public-key->address whisper-identity))]
|
||||
(-> {:db db}
|
||||
(add-new-contact contact)
|
||||
(update :db #(navigation/navigate-to-clean % :home))
|
||||
(assoc :dispatch [:start-chat whisper-identity {:navigation-replace? true}]))))))
|
||||
|
||||
(defn add-pending-contact [{:keys [db] :as fx} chat-or-whisper-id]
|
||||
(defn add-contact [{:keys [db] :as fx} chat-or-whisper-id]
|
||||
(let [{:keys [chats] :contacts/keys [contacts]} db
|
||||
contact (if-let [contact-info (get-in chats [chat-or-whisper-id :contact-info])]
|
||||
(read-string contact-info)
|
||||
(get contacts chat-or-whisper-id))
|
||||
(or (get contacts chat-or-whisper-id)
|
||||
(utils.contacts/whisper-id->new-contact chat-or-whisper-id)))
|
||||
contact' (assoc contact
|
||||
:address (public-key->address chat-or-whisper-id)
|
||||
:pending? false)]
|
||||
|
@ -282,18 +272,21 @@
|
|||
(discover-events/send-portions-when-contact-exists chat-or-whisper-id)
|
||||
(add-new-contact contact'))))
|
||||
|
||||
(register-handler-fx
|
||||
:add-pending-contact
|
||||
(fn [{:keys [db]} [_ chat-or-whisper-id]]
|
||||
(add-pending-contact {:db db} chat-or-whisper-id)))
|
||||
(defn add-contact-and-open-chat [fx whisper-id]
|
||||
(-> fx
|
||||
(add-contact whisper-id)
|
||||
(update :db #(navigation/navigate-to-clean % :home))
|
||||
(assoc :dispatch [:start-chat whisper-id {:navigation-replace? true}])))
|
||||
|
||||
(register-handler-fx
|
||||
:add-pending-contact-and-open-chat
|
||||
:add-contact
|
||||
(fn [{:keys [db]} [_ chat-or-whisper-id]]
|
||||
(add-contact {:db db} chat-or-whisper-id)))
|
||||
|
||||
(register-handler-fx
|
||||
:add-contact-and-open-chat
|
||||
(fn [{:keys [db]} [_ whisper-id]]
|
||||
(-> {:db db}
|
||||
(add-pending-contact whisper-id)
|
||||
(update :db #(navigation/navigate-to-clean % :home))
|
||||
(assoc :dispatch [:start-chat whisper-id {:navigation-replace? true}]))))
|
||||
(add-contact-and-open-chat {:db db} whisper-id)))
|
||||
|
||||
(register-handler-fx
|
||||
:set-contact-identity-from-qr
|
||||
|
@ -383,11 +376,6 @@
|
|||
|
||||
(register-handler-fx
|
||||
:add-contact-handler
|
||||
(fn [{:keys [db]}]
|
||||
(let [{:contacts/keys [new-identity]} db]
|
||||
(when (and new-identity (not (string/blank? new-identity)))
|
||||
{:dispatch (if (get-in db [:contacts/contacts new-identity])
|
||||
[:add-pending-contact-and-open-chat new-identity]
|
||||
[:add-new-contact-and-open-chat {:name (generate-gfy new-identity)
|
||||
:photo-path (identicon new-identity)
|
||||
:whisper-identity new-identity}])}))))
|
||||
(fn [{{:contacts/keys [new-identity] :as db} :db}]
|
||||
(when (seq new-identity)
|
||||
(add-contact-and-open-chat {:db db} new-identity))))
|
||||
|
|
|
@ -98,10 +98,15 @@
|
|||
(->> (remove :pending? (vals groups))
|
||||
(sort-by :order >))))
|
||||
|
||||
(reg-sub :contact
|
||||
(reg-sub :current-contact-identity
|
||||
(fn [db]
|
||||
(let [identity (:contacts/identity db)]
|
||||
(get-in db [:contacts/contacts identity]))))
|
||||
(:contacts/identity db)))
|
||||
|
||||
(reg-sub :contact
|
||||
:<- [:get-contacts]
|
||||
:<- [:current-contact-identity]
|
||||
(fn [[contacts identity]]
|
||||
(contacts identity)))
|
||||
|
||||
(reg-sub :contact-by-identity
|
||||
(fn [db [_ identity]]
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
[status-im.ui.components.status-bar.view :as status-bar]
|
||||
[status-im.i18n :as i18n]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.utils.contacts :as utils.contacts]
|
||||
[status-im.ui.components.toolbar.view :as toolbar]
|
||||
[status-im.ui.components.list.views :as list]))
|
||||
|
||||
|
@ -19,7 +20,7 @@
|
|||
(concat (if pending?
|
||||
[{:label (i18n/label :t/add-to-contacts)
|
||||
:icon :icons/add-contact
|
||||
:action #(re-frame/dispatch [:add-pending-contact chat-id])}]
|
||||
:action #(re-frame/dispatch [:add-contact whisper-identity])}]
|
||||
[{:label (i18n/label :t/in-contacts)
|
||||
:icon :icons/in-contacts
|
||||
:disabled? true}])
|
||||
|
@ -52,19 +53,21 @@
|
|||
[profile-info-contact-code-item whisper-identity]])
|
||||
|
||||
(defview profile []
|
||||
(letsubs [contact [:contact]
|
||||
(letsubs [identity [:current-contact-identity]
|
||||
maybe-contact [:contact]
|
||||
chat-id [:get :current-chat-id]]
|
||||
[react/view profile.components.styles/profile
|
||||
[status-bar/status-bar]
|
||||
[profile-contact-toolbar]
|
||||
[react/scroll-view
|
||||
[react/view profile.components.styles/profile-form
|
||||
[profile.components/profile-header contact false false nil nil]]
|
||||
[list/action-list (actions contact chat-id)
|
||||
{:container-style styles/action-container
|
||||
:action-style styles/action
|
||||
:action-label-style styles/action-label
|
||||
:action-separator-style styles/action-separator
|
||||
:icon-opts styles/action-icon-opts}]
|
||||
[react/view styles/contact-profile-info-container
|
||||
[profile-info contact]]]]))
|
||||
(let [contact (or maybe-contact (utils.contacts/whisper-id->new-contact identity))]
|
||||
[react/view profile.components.styles/profile
|
||||
[status-bar/status-bar]
|
||||
[profile-contact-toolbar]
|
||||
[react/scroll-view
|
||||
[react/view profile.components.styles/profile-form
|
||||
[profile.components/profile-header contact false false nil nil]]
|
||||
[list/action-list (actions contact chat-id)
|
||||
{:container-style styles/action-container
|
||||
:action-style styles/action
|
||||
:action-label-style styles/action-label
|
||||
:action-separator-style styles/action-separator
|
||||
:icon-opts styles/action-icon-opts}]
|
||||
[react/view styles/contact-profile-info-container
|
||||
[profile-info contact]]]])))
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
(ns status-im.utils.contacts
|
||||
(:require
|
||||
[status-im.utils.identicon :as identicon]
|
||||
[status-im.utils.gfycat.core :as gfycat]))
|
||||
|
||||
(defn whisper-id->new-contact [whisper-id]
|
||||
{:name (gfycat/generate-gfy whisper-id)
|
||||
:photo-path (identicon/identicon whisper-id)
|
||||
:pending? true
|
||||
:whisper-identity whisper-id})
|
|
@ -110,7 +110,7 @@
|
|||
contact-request-received (update-contact, watch-contact ;TODO :update-chat!)
|
||||
contact-update-received (update-contact ;TODO :update-chat!)
|
||||
hide-contact (update-contact ;TODO :account-update-keys)
|
||||
add-contact-handler (add-pending-contact, status-im.contacts.events/add-new-contact
|
||||
add-contact-handler (add-contact, status-im.contacts.events/add-new-contact
|
||||
status-im.contacts.events/send-contact-request ;TODO :discoveries-send-portions)
|
||||
|
||||
create-new-contact-group
|
||||
|
@ -241,7 +241,8 @@
|
|||
(def new-contact {:name ""
|
||||
:photo-path ""
|
||||
:whisper-identity new-contact-public-key
|
||||
:address new-contact-address})
|
||||
:address new-contact-address
|
||||
:pending? false})
|
||||
(def contact (rf/subscribe [:contact-by-identity new-contact-public-key]))
|
||||
(def current-chat-id (rf/subscribe [:get-current-chat-id]))
|
||||
|
||||
|
@ -338,11 +339,11 @@
|
|||
(is (= (assoc received-contact2 :pending? true)
|
||||
(get @contacts new-contact-public-key)))))
|
||||
|
||||
(testing ":add-contact-handler event - :add-pending-contact"
|
||||
(testing ":add-contact-handler event - :add-contact"
|
||||
|
||||
;; :add-contact-handler event dispatches next 4 events
|
||||
;;
|
||||
;; :add-pending-contact
|
||||
;; :add-contact
|
||||
;; :status-im.contacts.events/add-new-contact
|
||||
;; :status-im.contacts.events/send-contact-request
|
||||
;;TODO :discoveries-send-portions
|
||||
|
|
Loading…
Reference in New Issue