[bug] fix error when receiving message from unknown contact
This commit is contained in:
parent
395f67fffd
commit
9bf5facb63
|
@ -60,11 +60,6 @@
|
|||
(fn [cofx _]
|
||||
(assoc cofx :get-stored-chat chats-store/get-by-id)))
|
||||
|
||||
(re-frame/reg-cofx
|
||||
:gfy-generator
|
||||
(fn [cofx _]
|
||||
(assoc cofx :gfy-generator gfycat/generate-gfy)))
|
||||
|
||||
;;;; Effects
|
||||
|
||||
(re-frame/reg-fx
|
||||
|
@ -290,7 +285,7 @@
|
|||
;; TODO(janherich): remove this unnecessary event in the future (only model function `add-chat` will stay)
|
||||
(handlers/register-handler-fx
|
||||
:add-chat
|
||||
[(re-frame/inject-cofx :gfy-generator) re-frame/trim-v]
|
||||
[re-frame/trim-v]
|
||||
(fn [cofx [chat-id chat-props]]
|
||||
(model/add-chat cofx chat-id chat-props)))
|
||||
|
||||
|
@ -313,8 +308,7 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:start-chat
|
||||
[(re-frame/inject-cofx :gfy-generator)
|
||||
(re-frame/inject-cofx :get-stored-messages)
|
||||
[(re-frame/inject-cofx :get-stored-messages)
|
||||
re-frame/trim-v]
|
||||
(fn [{:keys [db] :as cofx} [contact-id {:keys [navigation-replace?]}]]
|
||||
(when (not= (:current-public-key db) contact-id) ; don't allow to open chat with yourself
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
access-scope->commands-responses
|
||||
account
|
||||
chat
|
||||
contacts)]
|
||||
contacts)]
|
||||
(:ref (get available-commands-responses response-name))))
|
||||
|
||||
(defn add-message
|
||||
|
@ -60,10 +60,13 @@
|
|||
(not= from (:public-key current-account))
|
||||
(pop-up-chat? chat-identifier))
|
||||
(let [group-chat? (not (nil? group-id))
|
||||
chat-exists? (get-in db [:chats chat-identifier])
|
||||
fx (if chat-exists?
|
||||
(model/upsert-chat cofx {:chat-id chat-identifier
|
||||
:group-chat group-chat?})
|
||||
(model/add-chat cofx chat-identifier))
|
||||
command-request? (= content-type const/content-type-command-request)
|
||||
command (:command content)
|
||||
fx (model/upsert-chat cofx {:chat-id chat-identifier
|
||||
:group-chat group-chat?})
|
||||
enriched-message (cond-> (assoc (chat-utils/check-author-direction
|
||||
(get-last-stored-message chat-identifier)
|
||||
message)
|
||||
|
@ -78,16 +81,17 @@
|
|||
current-account
|
||||
(get-in fx [:db :chats chat-identifier])
|
||||
contacts
|
||||
command)))]
|
||||
command)))
|
||||
update-db-fx #(-> %
|
||||
(chat-utils/add-message-to-db chat-identifier chat-identifier enriched-message
|
||||
(:new? enriched-message))
|
||||
(unviewed-messages-model/add-unviewed-message chat-identifier message-id)
|
||||
(assoc-in [:chats chat-identifier :last-message] enriched-message))]
|
||||
(cond-> (-> fx
|
||||
(update :db #(-> %
|
||||
(chat-utils/add-message-to-db chat-identifier chat-identifier enriched-message
|
||||
(:new? enriched-message))
|
||||
(unviewed-messages-model/add-unviewed-message chat-identifier message-id)
|
||||
(assoc-in [:chats chat-identifier :last-message] enriched-message)))
|
||||
(update :db update-db-fx)
|
||||
(assoc :save-message (dissoc enriched-message :new?)))
|
||||
|
||||
command
|
||||
command
|
||||
(update :dispatch-n concat [[:request-command-message-data enriched-message :short-preview]
|
||||
[:request-command-preview enriched-message]])
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
(ns status-im.chat.models
|
||||
(:require [status-im.ui.components.styles :as styles]))
|
||||
(:require [status-im.ui.components.styles :as styles]
|
||||
[status-im.utils.gfycat.core :as gfycat]))
|
||||
|
||||
(defn set-chat-ui-props
|
||||
"Updates ui-props in active chat by merging provided kvs into them"
|
||||
|
@ -12,10 +13,10 @@
|
|||
(update-in db [:chat-ui-props current-chat-id ui-element] not))
|
||||
|
||||
(defn- create-new-chat
|
||||
[{:keys [db gfy-generator now]} chat-id chat-props]
|
||||
(let [{:keys [name whisper-identity]} (get-in db [:contacts/contacts chat-id])]
|
||||
[{:keys [db now] :as cofx} chat-id chat-props]
|
||||
(let [name (get-in db [:contacts/contacts chat-id :name])]
|
||||
(merge {:chat-id chat-id
|
||||
:name (or name (gfy-generator whisper-identity))
|
||||
:name (or name (gfycat/generate-gfy chat-id))
|
||||
:color styles/default-chat-color
|
||||
:group-chat false
|
||||
:is-active true
|
||||
|
@ -34,15 +35,20 @@
|
|||
(update :chats assoc chat-id new-chat))
|
||||
:save-chat new-chat})))
|
||||
|
||||
;; TODO (yenda): there should be an option to update the timestamp
|
||||
;; this shouldn't need a specific function like `upsert-chat` which
|
||||
;; is wrongfuly named
|
||||
(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}]
|
||||
[{:keys [db get-stored-chat] :as cofx} {:keys [chat-id] :as chat}]
|
||||
(let [chat (merge (or (get-stored-chat chat-id)
|
||||
(create-new-chat db chat-id {}))
|
||||
(create-new-chat cofx chat-id {}))
|
||||
chat)]
|
||||
{:db (update-in db [:chats chat-id] merge chat)
|
||||
:save-chat chat}))
|
||||
|
||||
;; TODO (yenda): an upsert is suppose to add the entry if it doesn't
|
||||
;; exist and update it if it does
|
||||
(defn upsert-chat
|
||||
"Just like `update-chat` only implicitely updates timestamp"
|
||||
[cofx chat]
|
||||
|
|
Loading…
Reference in New Issue