Fixes delivery status issues:

use :ack-of-message instead of :message-id
check if message was already set to :seen
This commit is contained in:
Roman Volosovskyi 2016-09-20 19:17:37 +03:00
parent c0fae5b4b7
commit cfc16ee008
3 changed files with 41 additions and 32 deletions

View File

@ -46,10 +46,12 @@
(r/create :account :pending-message message' true)))))
(defn remove-pending-message!
[{{:keys [message-id]} :payload}]
[{{:keys [message-id ack-of-message]} :payload}]
(r/write :account
(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]
(r/write

View File

@ -1,22 +1,24 @@
(ns status-im.protocol.ack
(: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!
[web3
from
{:keys [type requires-ack? message-id ack? group-id]}
{:keys [type requires-ack? message-id ack? group-id ack-of-message]}
identity]
(when (and requires-ack? (not ack?))
(let [message {:from identity
:to from
:message-id message-id
:message-id (random/id)
:topics [f/status-topic]
:type type
:ack? true
:payload {:type type
:ack? true
:ack-of-message message-id
:group-id group-id}}]
(d/add-pending-message! web3 message)))
(when ack?
(d/remove-pending-message! web3 message-id from)))
(d/remove-pending-message! web3 ack-of-message from)))

View File

@ -181,8 +181,10 @@
(defn save-message-status! [status]
(fn [_ [_
{:keys [from]
{:keys [message-id group-id]} :payload}]]
(when-let [message (messages/get-message message-id)]
{:keys [message-id ack-of-message group-id]} :payload}]]
(let [message-id' (or ack-of-message message-id)]
(when-let [{:keys [message-status] :as message} (messages/get-message message-id')]
(when-not (= (keyword message-status) :seen)
(let [group? (boolean group-id)
message (if (and group? (not= status :sent))
(update-in message
@ -194,18 +196,19 @@
old-status
status)}))
(assoc message :message-status status))]
(messages/update-message! message)))))
(messages/update-message! message)))))))
(defn update-message-status [status]
(fn [db
[_ {: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))
(let [group? (boolean group-id)
(let [message-id' (or ack-of-message message-id)
group? (boolean group-id)
status-path (if (and group? (not= status :sent))
[:message-user-statuses message-id from]
[:message-statuses message-id])
[:message-user-statuses message-id' from]
[:message-statuses message-id'])
current-status (get-in db status-path)]
(if-not (= :seen current-status)
(assoc-in db status-path {:whisper-identity from
@ -232,8 +235,10 @@
(register-handler :message-seen
[(after (save-message-status! :seen))
(after (fn [_ [_ {:keys [chat-id]}]]
(dispatch [:remove-unviewed-messages chat-id])))]
(after (fn [_ [_ {:keys [from]
{:keys [group-id]} :payload}]]
(when-not group-id
(dispatch [:remove-unviewed-messages from]))))]
(update-message-status :seen))
(register-handler :pending-message-upsert