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