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)
|
(if (chats const/console-chat-id)
|
||||||
{:db db}
|
{:db db}
|
||||||
(cond-> {:db (-> db
|
(cond-> {:db (-> db
|
||||||
(assoc :new-chat sign-up/console-chat
|
(assoc :current-chat-id const/console-chat-id)
|
||||||
:current-chat-id const/console-chat-id)
|
|
||||||
(update :chats assoc const/console-chat-id sign-up/console-chat))
|
(update :chats assoc const/console-chat-id sign-up/console-chat))
|
||||||
:dispatch-n [[:add-contacts [sign-up/console-contact]]]
|
:dispatch-n [[:add-contacts [sign-up/console-contact]]]
|
||||||
:save-chat sign-up/console-chat
|
:save-chat sign-up/console-chat
|
||||||
|
@ -324,8 +323,8 @@
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:add-chat
|
:add-chat
|
||||||
[(re-frame/inject-cofx :gfy-generator) re-frame/trim-v]
|
[(re-frame/inject-cofx :gfy-generator) re-frame/trim-v]
|
||||||
(fn [cofx [chat-id]]
|
(fn [cofx [chat-id chat-props]]
|
||||||
(model/add-chat cofx chat-id)))
|
(model/add-chat cofx chat-id chat-props)))
|
||||||
|
|
||||||
(defn- navigate-to-chat
|
(defn- navigate-to-chat
|
||||||
[cofx chat-id navigation-replace?]
|
[cofx chat-id navigation-replace?]
|
||||||
|
|
|
@ -12,30 +12,33 @@
|
||||||
(update-in db [:chat-ui-props current-chat-id ui-element] not))
|
(update-in db [:chat-ui-props current-chat-id ui-element] not))
|
||||||
|
|
||||||
(defn- create-new-chat
|
(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])]
|
(let [{:keys [name whisper-identity]} (get-in db [:contacts/contacts chat-id])]
|
||||||
{:chat-id chat-id
|
(merge {:chat-id chat-id
|
||||||
:name (or name (gfy-generator whisper-identity))
|
:name (or name (gfy-generator whisper-identity))
|
||||||
:color styles/default-chat-color
|
:color styles/default-chat-color
|
||||||
:group-chat false
|
:group-chat false
|
||||||
:is-active true
|
:is-active true
|
||||||
:timestamp now
|
:timestamp now
|
||||||
:contacts [{:identity chat-id}]}))
|
:contacts [{:identity chat-id}]}
|
||||||
|
chat-props)))
|
||||||
|
|
||||||
(defn add-chat
|
(defn add-chat
|
||||||
[{:keys [db] :as cofx} chat-id]
|
([cofx chat-id]
|
||||||
(let [new-chat (create-new-chat cofx chat-id)
|
(add-chat cofx chat-id {}))
|
||||||
existing-chats (:chats db)]
|
([{:keys [db] :as cofx} chat-id chat-props]
|
||||||
{:db (cond-> (assoc db :new-chat new-chat)
|
(let [new-chat (create-new-chat cofx chat-id chat-props)
|
||||||
(not (contains? existing-chats chat-id))
|
existing-chats (:chats db)]
|
||||||
(update :chats assoc chat-id new-chat))
|
{:db (cond-> db
|
||||||
:save-chat new-chat}))
|
(not (contains? existing-chats chat-id))
|
||||||
|
(update :chats assoc chat-id new-chat))
|
||||||
|
:save-chat new-chat})))
|
||||||
|
|
||||||
(defn update-chat
|
(defn update-chat
|
||||||
"Updates chat properties, if chat is not present in db, creates a default new one"
|
"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}]
|
[{:keys [db get-stored-chat]} {:keys [chat-id] :as chat}]
|
||||||
(let [chat (merge (or (get-stored-chat chat-id)
|
(let [chat (merge (or (get-stored-chat chat-id)
|
||||||
(create-new-chat db chat-id))
|
(create-new-chat db chat-id {}))
|
||||||
chat)]
|
chat)]
|
||||||
{:db (update-in db [:chats chat-id] merge chat)
|
{:db (update-in db [:chats chat-id] merge chat)
|
||||||
:save-chat 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/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/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/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/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-animations (s/nilable map?)) ;;{id (string) props (map)}
|
||||||
(s/def :chat/chat-ui-props (s/nilable map?)) ;;{id (string) props (map)}
|
(s/def :chat/chat-ui-props (s/nilable map?)) ;;{id (string) props (map)}
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
{:keys [db dispatch-n]} (chat-events/init-console-chat fresh-db false)]
|
{:keys [db dispatch-n]} (chat-events/init-console-chat fresh-db false)]
|
||||||
(is (= (:current-chat-id db)
|
(is (= (:current-chat-id db)
|
||||||
(:chat-id sign-up/console-chat)))
|
(:chat-id sign-up/console-chat)))
|
||||||
(is (= (:new-chat db)
|
|
||||||
sign-up/console-chat))
|
|
||||||
(is (= (:current-chat-id db)
|
(is (= (:current-chat-id db)
|
||||||
const/console-chat-id))
|
const/console-chat-id))
|
||||||
(is (= dispatch-n
|
(is (= dispatch-n
|
||||||
|
@ -41,8 +39,6 @@
|
||||||
{:keys [db dispatch-n]} (chat-events/init-console-chat fresh-db false)]
|
{:keys [db dispatch-n]} (chat-events/init-console-chat fresh-db false)]
|
||||||
(is (= (:current-chat-id db)
|
(is (= (:current-chat-id db)
|
||||||
(:chat-id sign-up/console-chat)))
|
(:chat-id sign-up/console-chat)))
|
||||||
(is (= (:new-chat db)
|
|
||||||
sign-up/console-chat))
|
|
||||||
(is (= (:current-chat-id db)
|
(is (= (:current-chat-id db)
|
||||||
const/console-chat-id))
|
const/console-chat-id))
|
||||||
(is (= dispatch-n [[:add-contacts [sign-up/console-contact]]])))))
|
(is (= dispatch-n [[:add-contacts [sign-up/console-contact]]])))))
|
||||||
|
|
Loading…
Reference in New Issue