Merge pull request #14 from status-im/online-pending-messages
Checking pending messages when user appears online (#210)
This commit is contained in:
commit
088d6dbf94
|
@ -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"
|
||||
|
|
|
@ -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))
|
||||
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)))))
|
|
@ -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))
|
||||
|
|
|
@ -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 (<! (timeout check-delivery-interval))))))
|
|
@ -21,7 +21,8 @@
|
|||
(def discovery-user-topic "status-user-")
|
||||
(def discovery-hashtag-topic "status-hashtag-")
|
||||
|
||||
(def daily-broadcast-ttl (* 60 60 24))
|
||||
(def hourly-broadcast-ttl (* 60 60))
|
||||
(def daily-broadcast-ttl (* hourly-broadcast-ttl 24))
|
||||
(def weekly-broadcast-ttl (* daily-broadcast-ttl 7))
|
||||
(def monthly-broadcast-ttl (* daily-broadcast-ttl 30))
|
||||
|
||||
|
@ -117,7 +118,7 @@
|
|||
"Broadcast user's online presence"
|
||||
[topics]
|
||||
(send-discover-messages {:topics topics
|
||||
:ttl daily-broadcast-ttl
|
||||
:ttl hourly-broadcast-ttl
|
||||
:payload {:at (to-long (now))
|
||||
:type :contact-online}}))
|
||||
|
||||
|
|
|
@ -21,14 +21,6 @@
|
|||
(invoke-user-handler :pending-message-upsert {:message message})
|
||||
(swap! state assoc-in [:pending-messages message-id] message))))
|
||||
|
||||
(defn update-pending-message [message-id new-message-data]
|
||||
(swap! state (fn [state]
|
||||
(if-let [message (get-in state [:pending-messages message-id])]
|
||||
(let [new-message (merge message new-message-data)]
|
||||
(invoke-user-handler :pending-message-upsert {:message new-message})
|
||||
(assoc-in state [:pending-messages message-id] new-message))
|
||||
state))))
|
||||
|
||||
(defn update-pending-message-identities [id from]
|
||||
(swap! state update-in [:pending-messages]
|
||||
(fn [pending-messages]
|
||||
|
@ -41,7 +33,7 @@
|
|||
|
||||
(empty? (get-in messages [id :identities])) ;; test
|
||||
(do
|
||||
(log/info "Removing message" id "f=rom pending")
|
||||
(log/info "Removing message" id "from pending")
|
||||
(invoke-user-handler :pending-message-remove {:message-id id})
|
||||
(dissoc messages id))))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue