mirror of
https://github.com/penpot/penpot.git
synced 2025-05-17 23:46:10 +02:00
87 lines
2.4 KiB
Clojure
87 lines
2.4 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS INC
|
|
|
|
(ns app.plugins.user
|
|
(:require
|
|
[app.common.record :as crc]
|
|
[app.config :as cfg]
|
|
[app.plugins.format :as format]
|
|
[app.plugins.utils :as u]
|
|
[app.util.object :as obj]))
|
|
|
|
(deftype CurrentUserProxy [$plugin])
|
|
(deftype ActiveUserProxy [$plugin])
|
|
(deftype UserProxy [$plugin])
|
|
|
|
(defn- add-session-properties
|
|
[user-proxy session-id]
|
|
(let [plugin-id (obj/get user-proxy "$plugin")]
|
|
(crc/add-properties!
|
|
user-proxy
|
|
{:name "$plugin" :enumerable false :get (constantly plugin-id)}
|
|
{:name "$session" :enumerable false :get (constantly session-id)}
|
|
|
|
{:name "id"
|
|
:get (fn [_] (-> (u/locate-profile session-id) :id str))}
|
|
|
|
{:name "name"
|
|
:get (fn [_] (-> (u/locate-profile session-id) :fullname))}
|
|
|
|
{:name "avatarUrl"
|
|
:get (fn [_] (cfg/resolve-profile-photo-url (u/locate-profile session-id)))}
|
|
|
|
{:name "color"
|
|
:get (fn [_] (-> (u/locate-presence session-id) :color))}
|
|
|
|
{:name "sessionId"
|
|
:get (fn [_] (str session-id))})))
|
|
|
|
|
|
(defn current-user-proxy? [p]
|
|
(instance? CurrentUserProxy p))
|
|
|
|
(defn current-user-proxy
|
|
[plugin-id session-id]
|
|
(-> (CurrentUserProxy. plugin-id)
|
|
(add-session-properties session-id)))
|
|
|
|
(defn active-user-proxy? [p]
|
|
(instance? ActiveUserProxy p))
|
|
|
|
(defn active-user-proxy
|
|
[plugin-id session-id]
|
|
(-> (ActiveUserProxy. plugin-id)
|
|
(add-session-properties session-id)
|
|
(crc/add-properties!
|
|
{:name "position" :get (fn [_] (-> (u/locate-presence session-id) :point format/format-point))}
|
|
{:name "zoom" :get (fn [_] (-> (u/locate-presence session-id) :zoom))})))
|
|
|
|
(defn- add-user-properties
|
|
[user-proxy data]
|
|
(let [plugin-id (obj/get user-proxy "$plugin")]
|
|
(crc/add-properties!
|
|
user-proxy
|
|
{:name "$plugin" :enumerable false :get (constantly plugin-id)}
|
|
|
|
{:name "id"
|
|
:get (fn [_] (-> data :id str))}
|
|
|
|
{:name "name"
|
|
:get (fn [_] (-> data :fullname))}
|
|
|
|
{:name "avatarUrl"
|
|
:get (fn [_] (cfg/resolve-profile-photo-url data))})))
|
|
|
|
(defn user-proxy?
|
|
[p]
|
|
(or (instance? UserProxy p)
|
|
(current-user-proxy? p)
|
|
(active-user-proxy? p)))
|
|
|
|
(defn user-proxy
|
|
[plugin-id data]
|
|
(-> (UserProxy. plugin-id)
|
|
(add-user-properties data)))
|