Parse messages in status-go
This commit enables parsing of messages in status-go. Currently only a few messages are supported in status-protocol-go. For now we only enable Message types. Status-react will conditionally use the parsed version if present. Eventually this can be moved to a separate signal/different structure, but for the time being is best to validate with the minimum amount of changes. The next step would be handle validation and processing of the field in status-go, so we can skip saving the message from status-react. This commit should improve performance of receiving messages from a chat, although haven't had time to validate that. Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
629464cc35
commit
5fe385c225
|
@ -133,7 +133,7 @@
|
|||
:content (cond-> {:chat-id current-chat-id
|
||||
:text input-text}
|
||||
message-id
|
||||
(assoc :response-to-v2 message-id)
|
||||
(assoc :response-to message-id)
|
||||
preferred-name
|
||||
(assoc :name preferred-name))})
|
||||
(commands.input/set-command-reference nil)
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
|
||||
(defn emoji-only-content?
|
||||
"Determines if text is just an emoji"
|
||||
[{:keys [text response-to-v2]}]
|
||||
(and (not response-to-v2)
|
||||
[{:keys [text response-to]}]
|
||||
(and (not response-to)
|
||||
(string? text)
|
||||
(re-matches constants/regx-emoji text)))
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
:content-type :contentType
|
||||
:clock-value :clockValue
|
||||
:outgoing-status :outgoingStatus})
|
||||
(assoc :replyTo (get-in message [:content :response-to-v2]))))
|
||||
(assoc :replyTo (get-in message [:content :response-to]))))
|
||||
|
||||
(defn update-quoted-message [message]
|
||||
(let [parsed-content (utils/safe-read-message-content (get-in message [:quotedMessage :content]))]
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
|
||||
(spec/def :message.content/text (spec/and string? (complement s/blank?)))
|
||||
(spec/def :message.content/response-to string?)
|
||||
(spec/def :message.content/response-to-v2 string?)
|
||||
(spec/def :message.content/command-path (spec/tuple string? (spec/coll-of (spec/or :scope keyword? :chat-id string?) :kind set? :min-count 1)))
|
||||
(spec/def :message.content/uri (spec/and string? (complement s/blank?)))
|
||||
(spec/def :message.content/pack (spec/and string? (complement s/blank?)))
|
||||
|
|
|
@ -16,6 +16,31 @@
|
|||
[taoensso.timbre :as log]
|
||||
[status-im.ethereum.json-rpc :as json-rpc]))
|
||||
|
||||
(def message-type-message 1)
|
||||
|
||||
(defn build-message [parsed-message-js]
|
||||
(let [content (.-content parsed-message-js)
|
||||
built-message
|
||||
(protocol/Message.
|
||||
{:text (.-text content)
|
||||
:response-to (.-response-to content)
|
||||
:chat-id (.-chat_id content)}
|
||||
(.-content_type parsed-message-js)
|
||||
(keyword (.-message_type parsed-message-js))
|
||||
(.-clock parsed-message-js)
|
||||
(.-timestamp parsed-message-js))]
|
||||
built-message))
|
||||
|
||||
(defn handle-message
|
||||
"Check if parsedMessage is present and of a supported type, if so
|
||||
build a record using the right type. Otherwise defaults to transit
|
||||
deserializing"
|
||||
[message-js]
|
||||
(if (and (.-parsedMessage message-js)
|
||||
(= message-type-message) (.-messageType message-js))
|
||||
(build-message (.-parsedMessage message-js))
|
||||
(transit/deserialize (.-payload message-js))))
|
||||
|
||||
(fx/defn receive-message
|
||||
"Receive message handles a new status-message.
|
||||
dedup-id is passed by status-go and is used to deduplicate messages at that layer.
|
||||
|
@ -23,7 +48,6 @@
|
|||
in order to stop receiving that message"
|
||||
[{:keys [db]} now-in-s filter-chat-id message-js]
|
||||
(let [blocked-contacts (get db :contacts/blocked #{})
|
||||
payload (.-payload message-js)
|
||||
timestamp (.-timestamp (.-message message-js))
|
||||
metadata-js (.-metadata message-js)
|
||||
metadata {:author {:publicKey (.-publicKey (.-author metadata-js))
|
||||
|
@ -32,9 +56,7 @@
|
|||
:dedupId (.-dedupId metadata-js)
|
||||
:encryptionId (.-encryptionId metadata-js)
|
||||
:messageId (.-messageId metadata-js)}
|
||||
raw-payload {:raw-payload message-js}
|
||||
status-message (-> payload
|
||||
transit/deserialize)
|
||||
status-message (handle-message message-js)
|
||||
sig (-> metadata :author :publicKey)]
|
||||
(when (and sig
|
||||
status-message
|
||||
|
|
|
@ -70,9 +70,7 @@
|
|||
[{:keys [chat-id message-id content
|
||||
timestamp-str group-chat outgoing current-public-key expanded?] :as message}]
|
||||
[message-view message
|
||||
(let [response-to (or (:response-to content)
|
||||
(:response-to-v2 content))
|
||||
|
||||
(let [response-to (:response-to content)
|
||||
collapsible? (and (:should-collapse? content) group-chat)]
|
||||
[react/view
|
||||
(when response-to
|
||||
|
@ -98,8 +96,7 @@
|
|||
|
||||
(defn emoji-message
|
||||
[{:keys [content current-public-key alias] :as message}]
|
||||
(let [response-to (or (:response-to content)
|
||||
(:response-to-v2 content))]
|
||||
(let [response-to (:response-to content)]
|
||||
[message-view message
|
||||
[react/view {:style (style/style-message-text false)}
|
||||
(when response-to
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
|
||||
"owner": "status-im",
|
||||
"repo": "status-go",
|
||||
"version": "v0.34.0-beta.4",
|
||||
"commit-sha1": "e311307061ebf67fece33ff02e811d94972ae5b1",
|
||||
"src-sha256": "063yfb9r1vdgskhfqg0r400wrpwk2ibryc785pffwash70yyf5y0"
|
||||
"version": "v0.34.0-beta.6",
|
||||
"commit-sha1": "9d6601207f7bb2acf0ef0b952b2735995062fca7",
|
||||
"src-sha256": "1w6c8vgawnd48ygarh18gjzzf3x90zidsi7kiwszmygfd7dh0dp8"
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
(testing "message to rpc"
|
||||
(let [message {:message-id message-id
|
||||
:content {:chat-id chat-id
|
||||
:response-to-v2 "id-2"
|
||||
:response-to "id-2"
|
||||
:text "hta"}
|
||||
:whisper-timestamp 1
|
||||
:dedup-id "ATIwMTkwODE0YTdkNWZhZGY1N2E0ZDU3MzUxZmJkNDZkZGM1ZTU4ZjRlYzUyYWYyMDA5NTc2NWYyYmIxOTQ2OTM3NGUwNjdiMvEpTIGEjHOTAyqsrN39wST4npnSAv1AR8jJWeubanjkoGIyJooD5RVRnx6ZMt+/JzBOD2hoZzlHQWA0bC6XbdU="
|
||||
|
@ -26,7 +26,7 @@
|
|||
:from from
|
||||
:chatId chat-id
|
||||
:replyTo "id-2"
|
||||
:content "{\"chat-id\":\"chat-id\",\"response-to-v2\":\"id-2\",\"text\":\"hta\"}"
|
||||
:content "{\"chat-id\":\"chat-id\",\"response-to\":\"id-2\",\"text\":\"hta\"}"
|
||||
:contentType "text/plain"
|
||||
:messageType "public-group-user-message"
|
||||
:clockValue 2
|
||||
|
|
Loading…
Reference in New Issue