🎉 Add push notifications support

This commit is contained in:
Andrey Antukh 2023-08-10 11:07:28 +02:00
parent 15a9035ed1
commit e5dedb1e3d
8 changed files with 189 additions and 3 deletions

View file

@ -7,7 +7,10 @@
(ns app.main.data.common
"A general purpose events."
(:require
[app.config :as cf]
[app.main.data.messages :as msg]
[app.main.repo :as rp]
[app.util.i18n :refer [tr]]
[beicon.core :as rx]
[potok.core :as ptk]))
@ -43,3 +46,33 @@
(watch [_ _ _]
(->> (rp/cmd! :delete-share-link {:id id})
(rx/ignore)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NOTIFICATIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn force-reload!
[]
(.reload js/location))
(defn handle-notification
[{:keys [message code level] :as params}]
(ptk/reify ::show-notification
ptk/WatchEvent
(watch [_ _ _]
(case code
:upgrade-version
(when (or (not= (:version params) (:full cf/version))
(true? (:force params)))
(rx/of (msg/dialog
:content (tr "notifications.by-code.upgrade-version")
:controls :inline-actions
:type level
:actions [{:label "Refresh" :callback force-reload!}]
:tag :notification)))
(rx/of (msg/dialog
:content message
:controls :close
:type level
:tag :notification))))))

View file

@ -13,10 +13,12 @@
[app.common.uri :as u]
[app.common.uuid :as uuid]
[app.config :as cf]
[app.main.data.common :refer [handle-notification]]
[app.main.data.events :as ev]
[app.main.data.fonts :as df]
[app.main.data.media :as di]
[app.main.data.users :as du]
[app.main.data.websocket :as dws]
[app.main.features :as features]
[app.main.repo :as rp]
[app.util.dom :as dom]
@ -61,7 +63,23 @@
(ptk/watch (fetch-projects) state stream)
(ptk/watch (fetch-team-members) state stream)
(ptk/watch (du/fetch-teams) state stream)
(ptk/watch (du/fetch-users {:team-id id}) state stream)))))
(ptk/watch (du/fetch-users {:team-id id}) state stream)
(let [stoper (rx/filter (ptk/type? ::finalize) stream)
profile-id (:profile-id state)]
(->> stream
(rx/filter (ptk/type? ::dws/message))
(rx/map deref)
(rx/filter (fn [{:keys [subs-id type] :as msg}]
(and (or (= subs-id uuid/zero)
(= subs-id profile-id))
(= :notification type))))
(rx/map handle-notification)
(rx/take-until stoper)))))))
(defn finalize
[params]
(ptk/data-event ::finalize params))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Data Fetching (context aware: current team)

View file

@ -120,6 +120,17 @@
:position :fixed
:timeout timeout})))
(defn dialog
[& {:keys [content controls actions position tag type]
:or {controls :none position :floating type :info}}]
(show (d/without-nils
{:content content
:type type
:position position
:controls controls
:actions actions
:tag tag})))
(defn info-dialog
([content controls actions]
(info-dialog content controls actions nil))

View file

@ -10,6 +10,8 @@
[app.common.data.macros :as dm]
[app.common.pages.changes :as cpc]
[app.common.schema :as sm]
[app.common.uuid :as uuid]
[app.main.data.common :refer [handle-notification]]
[app.main.data.websocket :as dws]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.libraries :as dwl]
@ -57,8 +59,9 @@
(rx/filter (ptk/type? ::dws/message))
(rx/map deref)
(rx/filter (fn [{:keys [subs-id] :as msg}]
(or (= subs-id team-id)
(or (= subs-id uuid/zero)
(= subs-id profile-id)
(= subs-id team-id)
(= subs-id file-id))))
(rx/map process-message))
@ -96,6 +99,7 @@
:pointer-update (handle-pointer-update msg)
:file-change (handle-file-change msg)
:library-change (handle-library-change msg)
:notification (handle-notification msg)
nil))
(defn- handle-pointer-send