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:
Andrea Maria Piana 2018-01-13 19:30:40 +00:00 committed by Eric Dvorsak
parent 63afd37921
commit 3a65dcd3c2
No known key found for this signature in database
GPG Key ID: 932AC1CE5F05DE0C
3 changed files with 39 additions and 15 deletions

View File

@ -1,5 +1,5 @@
(ns status-im.chat.handlers
(:require [re-frame.core :refer [enrich after debug dispatch reg-fx]]
(ns status-im.chat.handlers
(:require [re-frame.core :refer [enrich after debug dispatch reg-fx]]
[clojure.string :as string]
[status-im.ui.components.styles :refer [default-chat-color]]
[status-im.chat.constants :as chat-consts]
@ -13,7 +13,7 @@
console-chat-id]]
[status-im.utils.random :as random]
[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))
(defn remove-chat

View File

@ -439,8 +439,9 @@
(fn [{:keys [db]} [_ id]]
(if (spec/valid? :global/address id)
{::request-contact-by-address id}
{:dispatch (if (get-in db [:contacts/contacts id])
[:add-pending-contact id]
[:add-new-contact-and-open-chat {:name (generate-gfy id)
:photo-path (identicon id)
:whisper-identity id}])})))
{:dispatch-n (if (get-in db [:contacts/contacts id])
[[:add-pending-contact id]
[:start-chat id {:navigation-replace? true}]]
[[:add-new-contact-and-open-chat {:name (generate-gfy id)
:photo-path (identicon id)
:whisper-identity id}]])})))

View File

@ -124,6 +124,8 @@
(rf/reg-fx ::group-events/save-contact-group-property #())
(rf/reg-fx ::group-events/add-contacts-to-contact-group #())
(rf/reg-fx :save-chat #())
(rf/reg-cofx
::contacts-events/get-all-contacts
(fn [coeffects _]
@ -152,7 +154,7 @@
load-contact-groups
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,
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-update-received (update-contact ;TODO :update-chat!)
hide-contact (update-contact ;TODO :account-update-keys)
@ -174,7 +176,8 @@
(rf/dispatch [:initialize-db])
(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"
@ -230,17 +233,20 @@
:photo-path ""
:whisper-identity new-contact-public-key
: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"
(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-new-contact-and-open-chat
;; :status-im.contacts.events/add-new-contact
;; :status-im.contacts.events/send-contact-request
;;TODO :start-chat
(rf/reg-event-db :start-chat (fn [db _] db))
;; :status-im.chat.events/start-chat
(rf/dispatch [:add-contact-handler new-contact-public-key])
@ -251,7 +257,13 @@
(is (= new-contact
(-> @contacts
(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"
@ -324,14 +336,25 @@
;; :add-pending-contact
;; :status-im.contacts.events/add-new-contact
;; :status-im.contacts.events/send-contact-request
;; :status-im.chat.events/start-chat
;;TODO :discoveries-send-portions
(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])
(testing "it sets the pending? flag to 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"