 (ns pc.http.sente
   (:require [clojure.core.async :as async]
             [clojure.set :as set]
+            [clojure.string :as str]
             [clojure.tools.logging :as log]
             [taoensso.sente :as sente])
   (:import java.util.UUID))

(defmethod ws-handler :frontend/subscribe [{:keys [client-uuid ?data] :as req}]
  (let [document-id (-> ?data :document-id)]
    (log/infof "subscribing %s to %s" client-uuid document-id)
    (subscribe-to-doc document-id client-uuid)))

(defn setup-ws-handlers [sente-state]
  (let [tap (async/chan (async/sliding-buffer 100))

;; TODO: find a way to restart sente
(defonce sente-state (atom {}))

(defn user-id-fn
  "Have to remove - so that we can parse it out of the client-uuid"
  [ring-req]
  (str/replace (UUID/randomUUID) "-" ""))

;; hash-map of document-id to set of connected user-ids
;; Used to keep track of which transactions to send to which user
