Move automatic status updates timeout to status-go (#13602)

4aa34139...60a49fc7
This commit is contained in:
Parvesh Monu 2022-08-03 04:53:23 +05:30 committed by GitHub
parent a18deec330
commit 971d3ce818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 70 deletions

View File

@ -75,4 +75,5 @@
"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))
"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"))))

View File

@ -59,44 +59,25 @@
:title (i18n/label :t/status-inactive)
:subtitle (i18n/label :t/status-inactive-subtitle)}})
;; Currently, Another user is broadcasting their status updates at the rate of 5 minutes.
;; 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
(defn calculate-real-status-type
[{:keys [status-type clock]}]
(let [status-lifespan (if (= status-type
constants/visibility-status-automatic)
(datetime/minutes 5.05)
(let [status-lifespan (if (= status-type constants/visibility-status-automatic)
(datetime/minutes 5)
(datetime/weeks 2))
status-expire-time (+ (datetime/to-ms clock) status-lifespan)
time-left (- status-expire-time (datetime/timestamp))
status-type (if (or (nil? status-type)
(and
(not= status-type
constants/visibility-status-inactive)
(neg? time-left)))
constants/visibility-status-inactive
status-type)]
{:real-status-type status-type
:time-left time-left}))
time-left (- status-expire-time (datetime/timestamp))]
(if (or (nil? status-type)
(and
(not= status-type constants/visibility-status-inactive)
(neg? time-left)))
constants/visibility-status-inactive
status-type)))
(defn dot-color
[{:keys [status-type] :as visibility-status-update} my-icon?]
(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 [{:keys [status-type] :or {status-type constants/visibility-status-inactive}}]
(:color (get visibility-status-type-data status-type)))
(defn dot-color-old
[{:keys [status-type] :as visibility-status-update} my-icon?]
(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 dot-color-old [{:keys [status-type] :or {status-type constants/visibility-status-inactive}}]
(:color (get visibility-status-type-data-old status-type)))
(defn my-icon? [public-key]
(or (string/blank? public-key)
@ -112,7 +93,7 @@
visibility-status-update (visibility-status-update public-key my-icon?)
size (/ container-size 2.4)
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)
:online-profile-photo-dot
:offline-profile-photo-dot)]
@ -127,7 +108,7 @@
visibility-status-update (visibility-status-update public-key my-icon?)
size (/ container-size 4)
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)
:online-profile-photo-dot
:offline-profile-photo-dot)]
@ -140,5 +121,5 @@
(defn visibility-status-order [public-key]
(let [my-icon? (my-icon? public-key)
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)))

View File

@ -13,31 +13,22 @@
constants/visibility-status-inactive
constants/visibility-status-automatic)))
(defn process-visibility-status-update
[acc {:keys [public-key clock] :as visibility-status-update}]
(let [{:keys [real-status-type time-left]}
(utils/calculate-real-status-type-and-time-left visibility-status-update)]
(cond-> (assoc-in acc
[: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]})))))
(defn process-visibility-status-update [acc visibility-status-update]
(let [real-status-type (utils/calculate-real-status-type visibility-status-update)]
(assoc-in
acc [:visibility-status-updates (:public-key visibility-status-update)]
(assoc visibility-status-update :status-type real-status-type))))
(fx/defn load-visibility-status-updates
{:events [:visibility-status-updates/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]
(let [{:keys [public-key] :as visibility-status-update}
(visibility-status-updates-store/<-rpc
visibility-status-update-loaded)]
(let [visibility-status-update (visibility-status-updates-store/<-rpc
visibility-status-update-loaded)]
(process-visibility-status-update acc visibility-status-update)))
{} visibility-status-updates-loaded)]
(merge {:db (assoc db :visibility-status-updates visibility-status-updates)}
(when dispatch-later {:utils/dispatch-later dispatch-later}))))
{:db (assoc db :visibility-status-updates visibility-status-updates)}))
(defn handle-my-visibility-status-updates
[acc my-current-status clock visibility-status-update]
@ -72,9 +63,7 @@
db [:multiaccount :public-key])
my-current-status (get-in
db [:multiaccount :current-user-visibility-status])
{:keys [visibility-status-updates
current-user-visibility-status
dispatch dispatch-later]}
{:keys [visibility-status-updates current-user-visibility-status dispatch]}
(reduce (fn [acc visibility-status-update-received]
(let [{:keys [public-key clock] :as visibility-status-update}
(visibility-status-updates-store/<-rpc
@ -92,8 +81,7 @@
merge visibility-status-updates)
(update-in [:multiaccount :current-user-visibility-status]
merge current-user-visibility-status))}
(when dispatch {:dispatch dispatch})
(when dispatch-later {:utils/dispatch-later dispatch-later}))))
(when dispatch {:dispatch dispatch}))))
(fx/defn update-visibility-status
{:events [:visibility-status-updates/update-visibility-status]}
@ -131,14 +119,6 @@
;; Enable broadcasting for current broadcast
(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
{:events [:visibility-status-updates/delayed-visibility-status-update]}
[{:keys [db]} status-type]

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.103.4",
"commit-sha1": "4aa341395ccd854191e09b854142e65a21ead77c",
"src-sha256": "0w27yxpcqh5lwgqwp7zgm40c37m2lglmvzxckjaccxz174xfqh3f"
"version": "v0.104.1",
"commit-sha1": "60a49fc7d92d8bc28d3fc5a374d0cc798d53c89f",
"src-sha256": "0n4883fpg940jacn2cw7xg8axbhh2yn3inr2fsdwqqqfd8dxfnr4"
}