Merge pull request #2470 from status-im/bug-broken-group-chat-#2418
Fix broken group chats
This commit is contained in:
commit
ff0f5b5d56
|
@ -162,8 +162,7 @@
|
|||
(if (chats const/console-chat-id)
|
||||
{:db db}
|
||||
(cond-> {:db (-> db
|
||||
(assoc :new-chat sign-up/console-chat
|
||||
:current-chat-id const/console-chat-id)
|
||||
(assoc :current-chat-id const/console-chat-id)
|
||||
(update :chats assoc const/console-chat-id sign-up/console-chat))
|
||||
:dispatch-n [[:add-contacts [sign-up/console-contact]]]
|
||||
:save-chat sign-up/console-chat
|
||||
|
@ -324,8 +323,8 @@
|
|||
(handlers/register-handler-fx
|
||||
:add-chat
|
||||
[(re-frame/inject-cofx :gfy-generator) re-frame/trim-v]
|
||||
(fn [cofx [chat-id]]
|
||||
(model/add-chat cofx chat-id)))
|
||||
(fn [cofx [chat-id chat-props]]
|
||||
(model/add-chat cofx chat-id chat-props)))
|
||||
|
||||
(defn- navigate-to-chat
|
||||
[cofx chat-id navigation-replace?]
|
||||
|
|
|
@ -12,30 +12,33 @@
|
|||
(update-in db [:chat-ui-props current-chat-id ui-element] not))
|
||||
|
||||
(defn- create-new-chat
|
||||
[{:keys [db gfy-generator now]} chat-id]
|
||||
[{:keys [db gfy-generator now]} chat-id chat-props]
|
||||
(let [{:keys [name whisper-identity]} (get-in db [:contacts/contacts chat-id])]
|
||||
{:chat-id chat-id
|
||||
:name (or name (gfy-generator whisper-identity))
|
||||
:color styles/default-chat-color
|
||||
:group-chat false
|
||||
:is-active true
|
||||
:timestamp now
|
||||
:contacts [{:identity chat-id}]}))
|
||||
(merge {:chat-id chat-id
|
||||
:name (or name (gfy-generator whisper-identity))
|
||||
:color styles/default-chat-color
|
||||
:group-chat false
|
||||
:is-active true
|
||||
:timestamp now
|
||||
:contacts [{:identity chat-id}]}
|
||||
chat-props)))
|
||||
|
||||
(defn add-chat
|
||||
[{:keys [db] :as cofx} chat-id]
|
||||
(let [new-chat (create-new-chat cofx chat-id)
|
||||
existing-chats (:chats db)]
|
||||
{:db (cond-> (assoc db :new-chat new-chat)
|
||||
(not (contains? existing-chats chat-id))
|
||||
(update :chats assoc chat-id new-chat))
|
||||
:save-chat new-chat}))
|
||||
([cofx chat-id]
|
||||
(add-chat cofx chat-id {}))
|
||||
([{:keys [db] :as cofx} chat-id chat-props]
|
||||
(let [new-chat (create-new-chat cofx chat-id chat-props)
|
||||
existing-chats (:chats db)]
|
||||
{:db (cond-> db
|
||||
(not (contains? existing-chats chat-id))
|
||||
(update :chats assoc chat-id new-chat))
|
||||
:save-chat new-chat})))
|
||||
|
||||
(defn update-chat
|
||||
"Updates chat properties, if chat is not present in db, creates a default new one"
|
||||
[{:keys [db get-stored-chat]} {:keys [chat-id] :as chat}]
|
||||
(let [chat (merge (or (get-stored-chat chat-id)
|
||||
(create-new-chat db chat-id))
|
||||
(create-new-chat db chat-id {}))
|
||||
chat)]
|
||||
{:db (update-in db [:chats chat-id] merge chat)
|
||||
:save-chat chat}))
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
(s/def :chat/chats (s/nilable map?)) ;; {id (string) chat (map)} active chats on chat's tab
|
||||
(s/def :chat/current-chat-id (s/nilable string?)) ;;current or last opened chat-id
|
||||
(s/def :chat/chat-id (s/nilable string?)) ;;what is the difference ? ^
|
||||
(s/def :chat/new-chat (s/nilable map?)) ;;used during adding new chat
|
||||
(s/def :chat/new-chat-name (s/nilable string?)) ;;we have name in the new-chat why do we need this field
|
||||
(s/def :chat/chat-animations (s/nilable map?)) ;;{id (string) props (map)}
|
||||
(s/def :chat/chat-ui-props (s/nilable map?)) ;;{id (string) props (map)}
|
||||
|
|
|
@ -26,9 +26,7 @@
|
|||
:accounts/current-account-id nil}
|
||||
{:keys [db dispatch-n]} (chat-events/init-console-chat fresh-db false)]
|
||||
(is (= (:current-chat-id db)
|
||||
(:chat-id sign-up/console-chat)))
|
||||
(is (= (:new-chat db)
|
||||
sign-up/console-chat))
|
||||
(:chat-id sign-up/console-chat)))
|
||||
(is (= (:current-chat-id db)
|
||||
const/console-chat-id))
|
||||
(is (= dispatch-n
|
||||
|
@ -40,9 +38,7 @@
|
|||
:accounts/current-account-id (:whisper-identity contact)}
|
||||
{:keys [db dispatch-n]} (chat-events/init-console-chat fresh-db false)]
|
||||
(is (= (:current-chat-id db)
|
||||
(:chat-id sign-up/console-chat)))
|
||||
(is (= (:new-chat db)
|
||||
sign-up/console-chat))
|
||||
(:chat-id sign-up/console-chat)))
|
||||
(is (= (:current-chat-id db)
|
||||
const/console-chat-id))
|
||||
(is (= dispatch-n [[:add-contacts [sign-up/console-contact]]])))))
|
||||
|
|
Loading…
Reference in New Issue