diff --git a/src/main/dda/masto_embed/api.cljs b/src/main/dda/masto_embed/api.cljs index d1548bd..f27f62d 100644 --- a/src/main/dda/masto_embed/api.cljs +++ b/src/main/dda/masto_embed/api.cljs @@ -16,6 +16,7 @@ (ns dda.masto-embed.api (:require ["mastodon-api" :as Mastodon] + [dda.masto-embed.infra :as infra] [clojure.spec.alpha :as s] [clojure.spec.test.alpha :as st] [orchestra.core :refer-macros [defn-spec]] @@ -25,12 +26,8 @@ (s/def ::account-id string?) (s/def ::host-url string?) -(defn exit-with-error [error] - (js/console.error error) - (js/process.exit 1)) - -(defn js->edn [data] - (js->clj data :keywordize-keys true)) +(defn masto->edn [response] + (-> response .-data infra/js->edn)) (defn-spec mastodon-client any? [host-url ::host-url] @@ -41,30 +38,13 @@ (defn-spec get-account-statuses any? [host-url ::host-url - account-id ::account-id - callback fn?] - (.then (.get (mastodon-client host-url) - (str "accounts/" account-id "/statuses") - #js {}) - #(let [response (-> % .-data js->edn)] - (if-let [error (:error response)] - (exit-with-error error) - (callback response))))) - -(defn-spec get-directory-old any? - [host-url ::host-url - callback fn?] - (.then (.get (mastodon-client host-url) - (str "directory?local=true") - #js {}) - #(let [response (-> % .-data js->edn)] - (callback response)))) + account-id ::account-id] + (.get (mastodon-client host-url) + (str "accounts/" account-id "/statuses") + #js {})) (defn-spec get-directory any? [host-url ::host-url] - (go (let [result ( result - .-data - js->edn)))) + (.get (mastodon-client host-url) + (str "directory?local=true") + #js {})) diff --git a/src/main/dda/masto_embed/app.cljs b/src/main/dda/masto_embed/app.cljs index b2fa001..9b5a000 100644 --- a/src/main/dda/masto_embed/app.cljs +++ b/src/main/dda/masto_embed/app.cljs @@ -16,6 +16,7 @@ (ns dda.masto-embed.app (:require [dda.masto-embed.api :as api] + [dda.masto-embed.infra :as infra] [cljs.core.async :refer [go close! put! take! timeout chan !]] [cljs.core.async.interop :refer-macros [ js/document (.getElementById masto-embed) (.getAttribute "host_url"))) -(defn account-name-from-document [] +(defn account-name-from-document [] (-> js/document (.getElementById masto-embed) (.getAttribute "account_name"))) @@ -44,41 +45,34 @@ (.-innerHTML) (set! input))) -(defn debug [elem] - (print elem) - elem) - - (defn find-account-id [host-url account-name] - (let [in (chan) - out (chan)] + (let [out (chan)] (go - (->> - (! out)) - (do (close! in) - (close! out)) - ) - ;(api/get-directory host-url #(go (>! in %))) + (>! out + (->> + (edn + (filter #(= account-name (:acct %))) + (map :id) + first + ;infra/debug + ))) out)) (defn init [] (go - (let [account-id (or + (let [host-url (host-url-from-document) + account-name (account-name-from-document) + account-id (or (account-id-from-document) - ( + (edn) + ] + (print host-url) + (print account-name) (print account-id) + (print status) + (render-to-document status) ))) diff --git a/src/main/dda/masto_embed/infra.cljs b/src/main/dda/masto_embed/infra.cljs new file mode 100644 index 0000000..4da07e0 --- /dev/null +++ b/src/main/dda/masto_embed/infra.cljs @@ -0,0 +1,30 @@ +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. +(ns dda.masto-embed.infra + (:require + [cljs.core.async :refer [go]] + [cljs.core.async.interop :refer-macros [edn [data] + (js->clj data :keywordize-keys true)) + +(defn debug [elem] + (print elem) + elem) \ No newline at end of file