Start chat when user adds a pending contact from the "new contact" view
When a contact is removed it is set to pending?. If the same contact is added again we now dispatch a :start-chat event which initiate a 1-1 chat with them.
This commit is contained in:
parent
63afd37921
commit
3a65dcd3c2
|
@ -1,5 +1,5 @@
|
||||||
(ns status-im.chat.handlers
|
(ns status-im.chat.handlers
|
||||||
(:require [re-frame.core :refer [enrich after debug dispatch reg-fx]]
|
(:require [re-frame.core :refer [enrich after debug dispatch reg-fx]]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[status-im.ui.components.styles :refer [default-chat-color]]
|
[status-im.ui.components.styles :refer [default-chat-color]]
|
||||||
[status-im.chat.constants :as chat-consts]
|
[status-im.chat.constants :as chat-consts]
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
console-chat-id]]
|
console-chat-id]]
|
||||||
[status-im.utils.random :as random]
|
[status-im.utils.random :as random]
|
||||||
[status-im.utils.handlers :refer [register-handler register-handler-fx] :as u]
|
[status-im.utils.handlers :refer [register-handler register-handler-fx] :as u]
|
||||||
status-im.chat.events
|
status-im.chat.events
|
||||||
status-im.chat.handlers.send-message))
|
status-im.chat.handlers.send-message))
|
||||||
|
|
||||||
(defn remove-chat
|
(defn remove-chat
|
||||||
|
|
|
@ -439,8 +439,9 @@
|
||||||
(fn [{:keys [db]} [_ id]]
|
(fn [{:keys [db]} [_ id]]
|
||||||
(if (spec/valid? :global/address id)
|
(if (spec/valid? :global/address id)
|
||||||
{::request-contact-by-address id}
|
{::request-contact-by-address id}
|
||||||
{:dispatch (if (get-in db [:contacts/contacts id])
|
{:dispatch-n (if (get-in db [:contacts/contacts id])
|
||||||
[:add-pending-contact id]
|
[[:add-pending-contact id]
|
||||||
[:add-new-contact-and-open-chat {:name (generate-gfy id)
|
[:start-chat id {:navigation-replace? true}]]
|
||||||
:photo-path (identicon id)
|
[[:add-new-contact-and-open-chat {:name (generate-gfy id)
|
||||||
:whisper-identity id}])})))
|
:photo-path (identicon id)
|
||||||
|
:whisper-identity id}]])})))
|
||||||
|
|
|
@ -124,6 +124,8 @@
|
||||||
(rf/reg-fx ::group-events/save-contact-group-property #())
|
(rf/reg-fx ::group-events/save-contact-group-property #())
|
||||||
(rf/reg-fx ::group-events/add-contacts-to-contact-group #())
|
(rf/reg-fx ::group-events/add-contacts-to-contact-group #())
|
||||||
|
|
||||||
|
(rf/reg-fx :save-chat #())
|
||||||
|
|
||||||
(rf/reg-cofx
|
(rf/reg-cofx
|
||||||
::contacts-events/get-all-contacts
|
::contacts-events/get-all-contacts
|
||||||
(fn [coeffects _]
|
(fn [coeffects _]
|
||||||
|
@ -152,7 +154,7 @@
|
||||||
load-contact-groups
|
load-contact-groups
|
||||||
load-default-contacts (add-contact-groups, add-contacts, add-contacts-to-group ;TODO add-chat, load-commands!)
|
load-default-contacts (add-contact-groups, add-contacts, add-contacts-to-group ;TODO add-chat, load-commands!)
|
||||||
add-contact-handler (add-new-contact-and-open-chat, status-im.contacts.events/add-new-contact,
|
add-contact-handler (add-new-contact-and-open-chat, status-im.contacts.events/add-new-contact,
|
||||||
status-im.contacts.events/send-contact-request ;TODO start-chat)
|
status-im.contacts.events/send-contact-request, status-im.chat.events.start-chat)
|
||||||
contact-request-received (update-contact, watch-contact ;TODO :update-chat!)
|
contact-request-received (update-contact, watch-contact ;TODO :update-chat!)
|
||||||
contact-update-received (update-contact ;TODO :update-chat!)
|
contact-update-received (update-contact ;TODO :update-chat!)
|
||||||
hide-contact (update-contact ;TODO :account-update-keys)
|
hide-contact (update-contact ;TODO :account-update-keys)
|
||||||
|
@ -174,7 +176,8 @@
|
||||||
(rf/dispatch [:initialize-db])
|
(rf/dispatch [:initialize-db])
|
||||||
|
|
||||||
(let [contacts (rf/subscribe [:get-contacts])
|
(let [contacts (rf/subscribe [:get-contacts])
|
||||||
contact-groups (rf/subscribe [:get-contact-groups])]
|
contact-groups (rf/subscribe [:get-contact-groups])
|
||||||
|
view-id (rf/subscribe [:get :view-id])]
|
||||||
|
|
||||||
(testing ":load-contacts event"
|
(testing ":load-contacts event"
|
||||||
|
|
||||||
|
@ -230,17 +233,20 @@
|
||||||
:photo-path ""
|
:photo-path ""
|
||||||
:whisper-identity new-contact-public-key
|
:whisper-identity new-contact-public-key
|
||||||
:address new-contact-address}
|
:address new-contact-address}
|
||||||
contact (rf/subscribe [:contact-by-identity new-contact-public-key])]
|
contact (rf/subscribe [:contact-by-identity new-contact-public-key])
|
||||||
|
current-chat-id (rf/subscribe [:get-current-chat-id])]
|
||||||
|
|
||||||
(testing ":add-contact-handler event - new contact"
|
(testing ":add-contact-handler event - new contact"
|
||||||
|
|
||||||
|
(rf/dispatch [:set :view-id nil])
|
||||||
|
(rf/dispatch [:set :current-chat-id nil])
|
||||||
|
|
||||||
;; :add-contact-handler event dispatches next 4 events for new contact
|
;; :add-contact-handler event dispatches next 4 events for new contact
|
||||||
;;
|
;;
|
||||||
;; :add-new-contact-and-open-chat
|
;; :add-new-contact-and-open-chat
|
||||||
;; :status-im.contacts.events/add-new-contact
|
;; :status-im.contacts.events/add-new-contact
|
||||||
;; :status-im.contacts.events/send-contact-request
|
;; :status-im.contacts.events/send-contact-request
|
||||||
;;TODO :start-chat
|
;; :status-im.chat.events/start-chat
|
||||||
(rf/reg-event-db :start-chat (fn [db _] db))
|
|
||||||
|
|
||||||
(rf/dispatch [:add-contact-handler new-contact-public-key])
|
(rf/dispatch [:add-contact-handler new-contact-public-key])
|
||||||
|
|
||||||
|
@ -251,7 +257,13 @@
|
||||||
(is (= new-contact
|
(is (= new-contact
|
||||||
(-> @contacts
|
(-> @contacts
|
||||||
(get new-contact-public-key)
|
(get new-contact-public-key)
|
||||||
(assoc :photo-path "" :name ""))))))
|
(assoc :photo-path "" :name "")))))
|
||||||
|
|
||||||
|
(testing "it loads the 1-1 chat"
|
||||||
|
(is (= :chat @view-id)))
|
||||||
|
|
||||||
|
(testing "it adds the new contact to the chat"
|
||||||
|
(is (= new-contact-public-key @current-chat-id))))
|
||||||
|
|
||||||
(testing ":contact-request-received event"
|
(testing ":contact-request-received event"
|
||||||
|
|
||||||
|
@ -324,14 +336,25 @@
|
||||||
;; :add-pending-contact
|
;; :add-pending-contact
|
||||||
;; :status-im.contacts.events/add-new-contact
|
;; :status-im.contacts.events/add-new-contact
|
||||||
;; :status-im.contacts.events/send-contact-request
|
;; :status-im.contacts.events/send-contact-request
|
||||||
|
;; :status-im.chat.events/start-chat
|
||||||
|
|
||||||
;;TODO :discoveries-send-portions
|
;;TODO :discoveries-send-portions
|
||||||
(rf/reg-event-db :discoveries-send-portions (fn [db _] db))
|
(rf/reg-event-db :discoveries-send-portions (fn [db _] db))
|
||||||
|
|
||||||
|
(rf/dispatch [:set :view-id nil])
|
||||||
|
(rf/dispatch [:set :current-chat-id nil])
|
||||||
|
|
||||||
(rf/dispatch [:add-contact-handler new-contact-public-key])
|
(rf/dispatch [:add-contact-handler new-contact-public-key])
|
||||||
|
|
||||||
(testing "it sets the pending? flag to false"
|
(testing "it sets the pending? flag to false"
|
||||||
(is (= (assoc received-contact'' :pending? false)
|
(is (= (assoc received-contact'' :pending? false)
|
||||||
(get @contacts new-contact-public-key)))))
|
(get @contacts new-contact-public-key))))
|
||||||
|
|
||||||
|
(testing "it loads the 1-1 chat"
|
||||||
|
(is (= :chat @view-id)))
|
||||||
|
|
||||||
|
(testing "it adds the new contact to the chat"
|
||||||
|
(is (= new-contact-public-key @current-chat-id))))
|
||||||
|
|
||||||
(testing ":create-new-contact-group event"
|
(testing ":create-new-contact-group event"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue