diff --git a/project.clj b/project.clj index 6d2bcab..27f640d 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject status-im/protocol "0.2.1" +(defproject status-im/protocol "0.2.2" :description "FIXME: write this!" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" diff --git a/src/cljs/status_im/protocol/api.cljs b/src/cljs/status_im/protocol/api.cljs index 0494e11..3899da0 100644 --- a/src/cljs/status_im/protocol/api.cljs +++ b/src/cljs/status_im/protocol/api.cljs @@ -8,8 +8,8 @@ connection storage]] [status-im.protocol.state.delivery :refer [upsert-pending-message - update-pending-message - set-pending-messages]] + set-pending-messages + pending-messages]] [status-im.protocol.state.group-chat :refer [save-keypair get-keypair get-peer-identities @@ -52,7 +52,8 @@ do-periodically init-discovery-keypair get-discovery-keypair]] - [status-im.protocol.defaults :refer [default-content-type]] + [status-im.protocol.defaults :refer [default-content-type + send-online-period]] [status-im.utils.logging :as log]) (:require-macros [cljs.core.async.macros :refer [go]])) @@ -112,7 +113,7 @@ (listen connection handle-incoming-whisper-message {:topic [group-id]})) (doseq [topic topics] (listen connection handle-incoming-whisper-message {:topic topic})) - (do-periodically (* 60 10 1000) send-online) + (do-periodically (* send-online-period 1000) send-online) (invoke-user-handler :initialized {:identity account}))))) (defn init-pending-messages [pending-messages] @@ -259,4 +260,14 @@ :payload {:keypair keypair :type :user-discovery-keypair}})] (upsert-pending-message new-message) - new-message)) \ No newline at end of file + new-message)) + +(defn resend-pending-messages [to] + (let [messages (->> (pending-messages) + (filter (fn [[_ {:keys [chat-id identities status]}]] + (and (= (keyword status) :failed) + (or (= chat-id to) + (some #{to} identities))))))] + (doseq [[_ message] messages] + (upsert-pending-message (assoc message :status :sending + :retry-count 0))))) \ No newline at end of file diff --git a/src/cljs/status_im/protocol/defaults.cljs b/src/cljs/status_im/protocol/defaults.cljs index b7dd173..f146d65 100644 --- a/src/cljs/status_im/protocol/defaults.cljs +++ b/src/cljs/status_im/protocol/defaults.cljs @@ -6,6 +6,7 @@ (def max-send-attempts 5) (def check-delivery-interval 500) -(def status-message-ttl (* 60 60 2)) -(def ack-wait-timeout (t/hours 2)) +(def status-message-ttl (* 60 10)) +(def ack-wait-timeout (t/minutes 10)) (def sending-retry-timeout (t/seconds 10)) +(def send-online-period (* 60 10)) diff --git a/src/cljs/status_im/protocol/delivery.cljs b/src/cljs/status_im/protocol/delivery.cljs index 9007abf..8b4f825 100644 --- a/src/cljs/status_im/protocol/delivery.cljs +++ b/src/cljs/status_im/protocol/delivery.cljs @@ -49,9 +49,7 @@ (post-message (connection) message (post-message-callback pending-message)))) (do (log/info "Delivery-loop: Retry-count for message" message-id "reached maximum") - (let [internal? (state/internal? message-id)] - (state/remove-pending-message message-id) - (when-not internal? - (invoke-user-handler :message-failed {:message-id message-id - :chat-id chat-id})))))) + (if-not (state/internal? message-id) + (state/upsert-pending-message (assoc pending-message :status :failed)) + (state/remove-pending-message message-id))))) (recur (