[#6956] store :raw-payload-hash in message (upgradable message-ids)
Currently, we calculate `message-id` as `sha3(from + raw_payload)`, but we do not store `raw_payload` and it might be problematic to restore it from DB because: 1) `content` field might be changed and so `Message` record will differ from the original one 2) it is even more problematic for `GroupMembershipUpdate` message because we don't save it in DB In order to handle this, we can store `sha3(raw_payload)` as `raw-payload-hash` prop of `message` entity and use it in case of emergency :) `message-id` will be calculated as `sha3(from + sha3(raw_payload))`
This commit is contained in:
parent
b6e515618b
commit
50a70f6e57
|
@ -307,7 +307,8 @@
|
||||||
:content-type constants/content-type-status}]
|
:content-type constants/content-type-status}]
|
||||||
(assoc message
|
(assoc message
|
||||||
:message-id (transport.utils/system-message-id message)
|
:message-id (transport.utils/system-message-id message)
|
||||||
:old-message-id "system")))
|
:old-message-id "system"
|
||||||
|
:raw-payload-hash "system")))
|
||||||
|
|
||||||
(defn group-message? [{:keys [message-type]}]
|
(defn group-message? [{:keys [message-type]}]
|
||||||
(#{:group-user-message :public-group-user-message} message-type))
|
(#{:group-user-message :public-group-user-message} message-type))
|
||||||
|
@ -342,7 +343,8 @@
|
||||||
message-id (transport.utils/message-id from raw-payload)
|
message-id (transport.utils/message-id from raw-payload)
|
||||||
message-with-id (assoc message
|
message-with-id (assoc message
|
||||||
:message-id message-id
|
:message-id message-id
|
||||||
:old-message-id old-message-id)]
|
:old-message-id old-message-id
|
||||||
|
:raw-payload-hash (transport.utils/sha3 raw-payload))]
|
||||||
|
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
(chat-model/upsert-chat {:chat-id chat-id
|
(chat-model/upsert-chat {:chat-id chat-id
|
||||||
|
|
|
@ -281,7 +281,7 @@
|
||||||
(def v27 [chat/v9
|
(def v27 [chat/v9
|
||||||
transport/v7
|
transport/v7
|
||||||
contact/v3
|
contact/v3
|
||||||
message/v8
|
message/v9
|
||||||
mailserver/v11
|
mailserver/v11
|
||||||
mailserver-topic/v1
|
mailserver-topic/v1
|
||||||
user-status/v2
|
user-status/v2
|
||||||
|
|
|
@ -57,3 +57,8 @@
|
||||||
(assoc-in [:properties :old-message-id]
|
(assoc-in [:properties :old-message-id]
|
||||||
{:type :string
|
{:type :string
|
||||||
:indexed true})))
|
:indexed true})))
|
||||||
|
|
||||||
|
(def v9
|
||||||
|
(-> v8
|
||||||
|
(assoc-in [:properties :raw-payload-hash]
|
||||||
|
{:type :string})))
|
||||||
|
|
|
@ -263,9 +263,11 @@
|
||||||
clock-value timestamp)
|
clock-value timestamp)
|
||||||
old-message-id (old-message-id message-record)
|
old-message-id (old-message-id message-record)
|
||||||
raw-payload (raw-payload message-record)
|
raw-payload (raw-payload message-record)
|
||||||
message-id (transport.utils/message-id from raw-payload)]
|
message-id (transport.utils/message-id from raw-payload)
|
||||||
|
raw-payload-hash (transport.utils/sha3 raw-payload)]
|
||||||
(vswap! old-ids->new-ids assoc prev-message-id message-id)
|
(vswap! old-ids->new-ids assoc prev-message-id message-id)
|
||||||
(aset message "message-id" message-id)
|
(aset message "message-id" message-id)
|
||||||
|
(aset message "raw-payload-hash" raw-payload-hash)
|
||||||
(aset message "old-message-id" old-message-id)))
|
(aset message "old-message-id" old-message-id)))
|
||||||
|
|
||||||
(dotimes [i (.-length user-statuses)]
|
(dotimes [i (.-length user-statuses)]
|
||||||
|
|
|
@ -118,6 +118,8 @@
|
||||||
signature
|
signature
|
||||||
(.-payload (:js-obj cofx)))
|
(.-payload (:js-obj cofx)))
|
||||||
:chat-id chat-id
|
:chat-id chat-id
|
||||||
|
:raw-payload-hash (transport.utils/sha3
|
||||||
|
(.-payload (:js-obj cofx)))
|
||||||
:from signature
|
:from signature
|
||||||
:js-obj (:js-obj cofx))]})
|
:js-obj (:js-obj cofx))]})
|
||||||
(validate [this]
|
(validate [this]
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
(defn message-id
|
(defn message-id
|
||||||
"Get a message-id"
|
"Get a message-id"
|
||||||
[from raw-payload]
|
[from raw-payload]
|
||||||
(sha3 (str from raw-payload)))
|
(sha3 (str from (sha3 raw-payload))))
|
||||||
|
|
||||||
(defn get-topic
|
(defn get-topic
|
||||||
"Get the topic of a group chat or public chat from the chat-id"
|
"Get the topic of a group chat or public chat from the chat-id"
|
||||||
|
|
Loading…
Reference in New Issue