Move automatic status updates timeout to status-go (#13602)
4aa34139...60a49fc7
This commit is contained in:
parent
a18deec330
commit
971d3ce818
|
@ -75,4 +75,5 @@
|
||||||
"wallet" (ethereum.subscriptions/new-wallet-event cofx (js->clj event-js :keywordize-keys true))
|
"wallet" (ethereum.subscriptions/new-wallet-event cofx (js->clj event-js :keywordize-keys true))
|
||||||
"local-notifications" (local-notifications/process cofx (js->clj event-js :keywordize-keys true))
|
"local-notifications" (local-notifications/process cofx (js->clj event-js :keywordize-keys true))
|
||||||
"community.found" (link.preview/cache-community-preview-data (js->clj event-js :keywordize-keys true))
|
"community.found" (link.preview/cache-community-preview-data (js->clj event-js :keywordize-keys true))
|
||||||
|
"status.updates.timedout" (visibility-status-updates/handle-visibility-status-updates cofx (js->clj event-js :keywordize-keys true))
|
||||||
(log/debug "Event " type " not handled"))))
|
(log/debug "Event " type " not handled"))))
|
||||||
|
|
|
@ -59,44 +59,25 @@
|
||||||
:title (i18n/label :t/status-inactive)
|
:title (i18n/label :t/status-inactive)
|
||||||
:subtitle (i18n/label :t/status-inactive-subtitle)}})
|
:subtitle (i18n/label :t/status-inactive-subtitle)}})
|
||||||
|
|
||||||
;; Currently, Another user is broadcasting their status updates at the rate of 5 minutes.
|
(defn calculate-real-status-type
|
||||||
;; So for status-type automatic, we need to show
|
|
||||||
;; that user online a little longer than that time. (broadcast receiving delay)
|
|
||||||
(defn calculate-real-status-type-and-time-left
|
|
||||||
[{:keys [status-type clock]}]
|
[{:keys [status-type clock]}]
|
||||||
(let [status-lifespan (if (= status-type
|
(let [status-lifespan (if (= status-type constants/visibility-status-automatic)
|
||||||
constants/visibility-status-automatic)
|
(datetime/minutes 5)
|
||||||
(datetime/minutes 5.05)
|
|
||||||
(datetime/weeks 2))
|
(datetime/weeks 2))
|
||||||
status-expire-time (+ (datetime/to-ms clock) status-lifespan)
|
status-expire-time (+ (datetime/to-ms clock) status-lifespan)
|
||||||
time-left (- status-expire-time (datetime/timestamp))
|
time-left (- status-expire-time (datetime/timestamp))]
|
||||||
status-type (if (or (nil? status-type)
|
(if (or (nil? status-type)
|
||||||
(and
|
(and
|
||||||
(not= status-type
|
(not= status-type constants/visibility-status-inactive)
|
||||||
constants/visibility-status-inactive)
|
(neg? time-left)))
|
||||||
(neg? time-left)))
|
constants/visibility-status-inactive
|
||||||
constants/visibility-status-inactive
|
status-type)))
|
||||||
status-type)]
|
|
||||||
{:real-status-type status-type
|
|
||||||
:time-left time-left}))
|
|
||||||
|
|
||||||
(defn dot-color
|
(defn dot-color [{:keys [status-type] :or {status-type constants/visibility-status-inactive}}]
|
||||||
[{:keys [status-type] :as visibility-status-update} my-icon?]
|
(:color (get visibility-status-type-data status-type)))
|
||||||
(if my-icon?
|
|
||||||
(if (= status-type constants/visibility-status-inactive)
|
|
||||||
colors/color-inactive quo2.colors/color-online)
|
|
||||||
(let [{:keys [real-status-type]}
|
|
||||||
(calculate-real-status-type-and-time-left visibility-status-update)]
|
|
||||||
(:color (get visibility-status-type-data real-status-type)))))
|
|
||||||
|
|
||||||
(defn dot-color-old
|
(defn dot-color-old [{:keys [status-type] :or {status-type constants/visibility-status-inactive}}]
|
||||||
[{:keys [status-type] :as visibility-status-update} my-icon?]
|
(:color (get visibility-status-type-data-old status-type)))
|
||||||
(if my-icon?
|
|
||||||
(if (= status-type constants/visibility-status-inactive)
|
|
||||||
colors/color-inactive colors/color-online)
|
|
||||||
(let [{:keys [real-status-type]}
|
|
||||||
(calculate-real-status-type-and-time-left visibility-status-update)]
|
|
||||||
(:color (get visibility-status-type-data-old real-status-type)))))
|
|
||||||
|
|
||||||
(defn my-icon? [public-key]
|
(defn my-icon? [public-key]
|
||||||
(or (string/blank? public-key)
|
(or (string/blank? public-key)
|
||||||
|
@ -112,7 +93,7 @@
|
||||||
visibility-status-update (visibility-status-update public-key my-icon?)
|
visibility-status-update (visibility-status-update public-key my-icon?)
|
||||||
size (/ container-size 2.4)
|
size (/ container-size 2.4)
|
||||||
margin -2
|
margin -2
|
||||||
dot-color (dot-color visibility-status-update my-icon?)
|
dot-color (dot-color visibility-status-update)
|
||||||
accessibility-label (if (= dot-color quo2.colors/color-online)
|
accessibility-label (if (= dot-color quo2.colors/color-online)
|
||||||
:online-profile-photo-dot
|
:online-profile-photo-dot
|
||||||
:offline-profile-photo-dot)]
|
:offline-profile-photo-dot)]
|
||||||
|
@ -127,7 +108,7 @@
|
||||||
visibility-status-update (visibility-status-update public-key my-icon?)
|
visibility-status-update (visibility-status-update public-key my-icon?)
|
||||||
size (/ container-size 4)
|
size (/ container-size 4)
|
||||||
margin (if identicon? (/ size 6) (/ size 7))
|
margin (if identicon? (/ size 6) (/ size 7))
|
||||||
dot-color (dot-color-old visibility-status-update my-icon?)
|
dot-color (dot-color-old visibility-status-update)
|
||||||
accessibility-label (if (= dot-color colors/color-online)
|
accessibility-label (if (= dot-color colors/color-online)
|
||||||
:online-profile-photo-dot
|
:online-profile-photo-dot
|
||||||
:offline-profile-photo-dot)]
|
:offline-profile-photo-dot)]
|
||||||
|
@ -140,5 +121,5 @@
|
||||||
(defn visibility-status-order [public-key]
|
(defn visibility-status-order [public-key]
|
||||||
(let [my-icon? (my-icon? public-key)
|
(let [my-icon? (my-icon? public-key)
|
||||||
visibility-status-update (visibility-status-update public-key my-icon?)
|
visibility-status-update (visibility-status-update public-key my-icon?)
|
||||||
dot-color (dot-color visibility-status-update my-icon?)]
|
dot-color (dot-color visibility-status-update)]
|
||||||
(if (= dot-color colors/color-online) 0 1)))
|
(if (= dot-color colors/color-online) 0 1)))
|
||||||
|
|
|
@ -13,31 +13,22 @@
|
||||||
constants/visibility-status-inactive
|
constants/visibility-status-inactive
|
||||||
constants/visibility-status-automatic)))
|
constants/visibility-status-automatic)))
|
||||||
|
|
||||||
(defn process-visibility-status-update
|
(defn process-visibility-status-update [acc visibility-status-update]
|
||||||
[acc {:keys [public-key clock] :as visibility-status-update}]
|
(let [real-status-type (utils/calculate-real-status-type visibility-status-update)]
|
||||||
(let [{:keys [real-status-type time-left]}
|
(assoc-in
|
||||||
(utils/calculate-real-status-type-and-time-left visibility-status-update)]
|
acc [:visibility-status-updates (:public-key visibility-status-update)]
|
||||||
(cond-> (assoc-in acc
|
(assoc visibility-status-update :status-type real-status-type))))
|
||||||
[:visibility-status-updates public-key]
|
|
||||||
visibility-status-update)
|
|
||||||
(= real-status-type constants/visibility-status-automatic)
|
|
||||||
(update :dispatch-later
|
|
||||||
#(conj % {:ms time-left
|
|
||||||
:dispatch [:visibility-status-updates/timeout-user-online-status
|
|
||||||
public-key clock]})))))
|
|
||||||
|
|
||||||
(fx/defn load-visibility-status-updates
|
(fx/defn load-visibility-status-updates
|
||||||
{:events [:visibility-status-updates/visibility-status-updates-loaded]}
|
{:events [:visibility-status-updates/visibility-status-updates-loaded]}
|
||||||
[{:keys [db]} visibility-status-updates-loaded]
|
[{:keys [db]} visibility-status-updates-loaded]
|
||||||
(let [{:keys [visibility-status-updates dispatch-later]}
|
(let [{:keys [visibility-status-updates]}
|
||||||
(reduce (fn [acc visibility-status-update-loaded]
|
(reduce (fn [acc visibility-status-update-loaded]
|
||||||
(let [{:keys [public-key] :as visibility-status-update}
|
(let [visibility-status-update (visibility-status-updates-store/<-rpc
|
||||||
(visibility-status-updates-store/<-rpc
|
visibility-status-update-loaded)]
|
||||||
visibility-status-update-loaded)]
|
|
||||||
(process-visibility-status-update acc visibility-status-update)))
|
(process-visibility-status-update acc visibility-status-update)))
|
||||||
{} visibility-status-updates-loaded)]
|
{} visibility-status-updates-loaded)]
|
||||||
(merge {:db (assoc db :visibility-status-updates visibility-status-updates)}
|
{:db (assoc db :visibility-status-updates visibility-status-updates)}))
|
||||||
(when dispatch-later {:utils/dispatch-later dispatch-later}))))
|
|
||||||
|
|
||||||
(defn handle-my-visibility-status-updates
|
(defn handle-my-visibility-status-updates
|
||||||
[acc my-current-status clock visibility-status-update]
|
[acc my-current-status clock visibility-status-update]
|
||||||
|
@ -72,9 +63,7 @@
|
||||||
db [:multiaccount :public-key])
|
db [:multiaccount :public-key])
|
||||||
my-current-status (get-in
|
my-current-status (get-in
|
||||||
db [:multiaccount :current-user-visibility-status])
|
db [:multiaccount :current-user-visibility-status])
|
||||||
{:keys [visibility-status-updates
|
{:keys [visibility-status-updates current-user-visibility-status dispatch]}
|
||||||
current-user-visibility-status
|
|
||||||
dispatch dispatch-later]}
|
|
||||||
(reduce (fn [acc visibility-status-update-received]
|
(reduce (fn [acc visibility-status-update-received]
|
||||||
(let [{:keys [public-key clock] :as visibility-status-update}
|
(let [{:keys [public-key clock] :as visibility-status-update}
|
||||||
(visibility-status-updates-store/<-rpc
|
(visibility-status-updates-store/<-rpc
|
||||||
|
@ -92,8 +81,7 @@
|
||||||
merge visibility-status-updates)
|
merge visibility-status-updates)
|
||||||
(update-in [:multiaccount :current-user-visibility-status]
|
(update-in [:multiaccount :current-user-visibility-status]
|
||||||
merge current-user-visibility-status))}
|
merge current-user-visibility-status))}
|
||||||
(when dispatch {:dispatch dispatch})
|
(when dispatch {:dispatch dispatch}))))
|
||||||
(when dispatch-later {:utils/dispatch-later dispatch-later}))))
|
|
||||||
|
|
||||||
(fx/defn update-visibility-status
|
(fx/defn update-visibility-status
|
||||||
{:events [:visibility-status-updates/update-visibility-status]}
|
{:events [:visibility-status-updates/update-visibility-status]}
|
||||||
|
@ -131,14 +119,6 @@
|
||||||
;; Enable broadcasting for current broadcast
|
;; Enable broadcasting for current broadcast
|
||||||
(send-visibility-status-updates? true))))
|
(send-visibility-status-updates? true))))
|
||||||
|
|
||||||
(fx/defn timeout-user-online-status
|
|
||||||
{:events [:visibility-status-updates/timeout-user-online-status]}
|
|
||||||
[{:keys [db]} public-key clock]
|
|
||||||
(let [current-clock (get-in db [:visibility-status-updates public-key :clock] 0)]
|
|
||||||
(when (= current-clock clock)
|
|
||||||
{:db (update-in db [:visibility-status-updates public-key]
|
|
||||||
merge {:status-type constants/visibility-status-inactive})})))
|
|
||||||
|
|
||||||
(fx/defn delayed-visibility-status-update
|
(fx/defn delayed-visibility-status-update
|
||||||
{:events [:visibility-status-updates/delayed-visibility-status-update]}
|
{:events [:visibility-status-updates/delayed-visibility-status-update]}
|
||||||
[{:keys [db]} status-type]
|
[{:keys [db]} status-type]
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
||||||
"owner": "status-im",
|
"owner": "status-im",
|
||||||
"repo": "status-go",
|
"repo": "status-go",
|
||||||
"version": "v0.103.4",
|
"version": "v0.104.1",
|
||||||
"commit-sha1": "4aa341395ccd854191e09b854142e65a21ead77c",
|
"commit-sha1": "60a49fc7d92d8bc28d3fc5a374d0cc798d53c89f",
|
||||||
"src-sha256": "0w27yxpcqh5lwgqwp7zgm40c37m2lglmvzxckjaccxz174xfqh3f"
|
"src-sha256": "0n4883fpg940jacn2cw7xg8axbhh2yn3inr2fsdwqqqfd8dxfnr4"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue