Fixes delivery status issues:
use :ack-of-message instead of :message-id
check if message was already set to :seen
Former-commit-id: cfc16ee008
This commit is contained in:
parent
a694034d20
commit
be66439f53
|
@ -46,10 +46,12 @@
|
||||||
(r/create :account :pending-message message' true)))))
|
(r/create :account :pending-message message' true)))))
|
||||||
|
|
||||||
(defn remove-pending-message!
|
(defn remove-pending-message!
|
||||||
[{{:keys [message-id]} :payload}]
|
[{{:keys [message-id ack-of-message]} :payload}]
|
||||||
(r/write :account
|
(r/write :account
|
||||||
(fn []
|
(fn []
|
||||||
(r/delete :account (r/get-by-field :account :pending-message :message-id message-id)))))
|
(r/delete :account
|
||||||
|
(r/get-by-field :account :pending-message
|
||||||
|
:message-id (or ack-of-message message-id))))))
|
||||||
|
|
||||||
(defn remove-all-by-chat [chat-id]
|
(defn remove-all-by-chat [chat-id]
|
||||||
(r/write
|
(r/write
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
(ns status-im.protocol.ack
|
(ns status-im.protocol.ack
|
||||||
(:require [status-im.protocol.web3.delivery :as d]
|
(:require [status-im.protocol.web3.delivery :as d]
|
||||||
[status-im.protocol.web3.filtering :as f]))
|
[status-im.protocol.web3.filtering :as f]
|
||||||
|
[status-im.utils.random :as random]))
|
||||||
|
|
||||||
(defn check-ack!
|
(defn check-ack!
|
||||||
[web3
|
[web3
|
||||||
from
|
from
|
||||||
{:keys [type requires-ack? message-id ack? group-id]}
|
{:keys [type requires-ack? message-id ack? group-id ack-of-message]}
|
||||||
identity]
|
identity]
|
||||||
(when (and requires-ack? (not ack?))
|
(when (and requires-ack? (not ack?))
|
||||||
(let [message {:from identity
|
(let [message {:from identity
|
||||||
:to from
|
:to from
|
||||||
:message-id message-id
|
:message-id (random/id)
|
||||||
:topics [f/status-topic]
|
:topics [f/status-topic]
|
||||||
:type type
|
:type type
|
||||||
:ack? true
|
:ack? true
|
||||||
:payload {:type type
|
:payload {:type type
|
||||||
:ack? true
|
:ack? true
|
||||||
:group-id group-id}}]
|
:ack-of-message message-id
|
||||||
|
:group-id group-id}}]
|
||||||
(d/add-pending-message! web3 message)))
|
(d/add-pending-message! web3 message)))
|
||||||
(when ack?
|
(when ack?
|
||||||
(d/remove-pending-message! web3 message-id from)))
|
(d/remove-pending-message! web3 ack-of-message from)))
|
||||||
|
|
|
@ -180,32 +180,35 @@
|
||||||
|
|
||||||
(defn save-message-status! [status]
|
(defn save-message-status! [status]
|
||||||
(fn [_ [_
|
(fn [_ [_
|
||||||
{:keys [from]
|
{:keys [from]
|
||||||
{:keys [message-id group-id]} :payload}]]
|
{:keys [message-id ack-of-message group-id]} :payload}]]
|
||||||
(when-let [message (messages/get-message message-id)]
|
(let [message-id' (or ack-of-message message-id)]
|
||||||
(let [group? (boolean group-id)
|
(when-let [{:keys [message-status] :as message} (messages/get-message message-id')]
|
||||||
message (if (and group? (not= status :sent))
|
(when-not (= (keyword message-status) :seen)
|
||||||
(update-in message
|
(let [group? (boolean group-id)
|
||||||
[:user-statuses from]
|
message (if (and group? (not= status :sent))
|
||||||
(fn [{old-status :status}]
|
(update-in message
|
||||||
{:id (random/id)
|
[:user-statuses from]
|
||||||
:whisper-identity from
|
(fn [{old-status :status}]
|
||||||
:status (if (= (keyword old-status) :seen)
|
{:id (random/id)
|
||||||
old-status
|
:whisper-identity from
|
||||||
status)}))
|
:status (if (= (keyword old-status) :seen)
|
||||||
(assoc message :message-status status))]
|
old-status
|
||||||
(messages/update-message! message)))))
|
status)}))
|
||||||
|
(assoc message :message-status status))]
|
||||||
|
(messages/update-message! message)))))))
|
||||||
|
|
||||||
|
|
||||||
(defn update-message-status [status]
|
(defn update-message-status [status]
|
||||||
(fn [db
|
(fn [db
|
||||||
[_ {:keys [from]
|
[_ {:keys [from]
|
||||||
{:keys [message-id group-id]} :payload}]]
|
{:keys [message-id ack-of-message group-id]} :payload}]]
|
||||||
(if (chats/is-active? (or group-id from))
|
(if (chats/is-active? (or group-id from))
|
||||||
(let [group? (boolean group-id)
|
(let [message-id' (or ack-of-message message-id)
|
||||||
status-path (if (and group? (not= status :sent))
|
group? (boolean group-id)
|
||||||
[:message-user-statuses message-id from]
|
status-path (if (and group? (not= status :sent))
|
||||||
[:message-statuses message-id])
|
[:message-user-statuses message-id' from]
|
||||||
|
[:message-statuses message-id'])
|
||||||
current-status (get-in db status-path)]
|
current-status (get-in db status-path)]
|
||||||
(if-not (= :seen current-status)
|
(if-not (= :seen current-status)
|
||||||
(assoc-in db status-path {:whisper-identity from
|
(assoc-in db status-path {:whisper-identity from
|
||||||
|
@ -232,8 +235,10 @@
|
||||||
|
|
||||||
(register-handler :message-seen
|
(register-handler :message-seen
|
||||||
[(after (save-message-status! :seen))
|
[(after (save-message-status! :seen))
|
||||||
(after (fn [_ [_ {:keys [chat-id]}]]
|
(after (fn [_ [_ {:keys [from]
|
||||||
(dispatch [:remove-unviewed-messages chat-id])))]
|
{:keys [group-id]} :payload}]]
|
||||||
|
(when-not group-id
|
||||||
|
(dispatch [:remove-unviewed-messages from]))))]
|
||||||
(update-message-status :seen))
|
(update-message-status :seen))
|
||||||
|
|
||||||
(register-handler :pending-message-upsert
|
(register-handler :pending-message-upsert
|
||||||
|
|
Loading…
Reference in New Issue