diff --git a/README.md b/README.md index de9147f..551f72c 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,18 @@ -# whisper +# Whisper -FIXME: description +Whisper is a client for signald. In combination, the two represent a complete replacement for the official Signal desktop client. Additionally, Whisper and Signald can be run on any mobile device supporting the Java Runtime Environment. + +**Whisper is in early stages of development.** ## Installation -Download from http://example.com/FIXME. +Currently: use lein run +TODO: package, wrap with a nice makefile ## Usage +Call `lein run` in a freshly cloned repository to run Whisper. Make sure Signald is already running. + FIXME: explanation $ java -jar whisper-0.1.0-standalone.jar [args] @@ -30,7 +35,7 @@ FIXME: listing of options this app accepts. ## License -Copyright © 2019 FIXME +Copyright © 2019 Aidan Hahn This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at diff --git a/src/whisper/core.clj b/src/whisper/core.clj index 0038a83..1ae48f0 100644 --- a/src/whisper/core.clj +++ b/src/whisper/core.clj @@ -12,7 +12,7 @@ [whisper.signald])) (def sockpath "/var/run/signald/signald.sock") -(def user (atom {})) +(def user (atom {"username" "" "filename" ""})) ;; TODO: handle multi users (with list ui) (defn handle-users @@ -20,8 +20,7 @@ (let [users (get-in data ["data" "accounts"])] (if (> (count users) 1) (log/info "Alert, multi account not supported yet. picking first on list")) - (swap! user (first users)) - (get @user "username"))) + (swap! user (first users)))) (defn -main "packs and shows main window with signald version string" @@ -55,14 +54,30 @@ ;; handle login basically (assoc-callback-type "account_list" (fn [x] - (if (< (count x) 1) + (if (< (count (get-in x ["data" "accounts"])) 1) (do (make-link-data-req sigd-input) (make-list-accounts-req sigd-input) - (let [username (handle-users x)] - (make-subscription-req sigd-input username) - ;; list_contacts? - ;; TODO: sync/list groups - (make-contact-sync-req sigd-input username)))))) + (handle-users x))))) + + ;; log in every time username changes + (add-watch user :login-manager + (fn [key atom old-state new-state] + (let [old-user (get old-state "username") + new-user (get new-state "username")] + + (log/info key " changed state from " + old-user " to " new-user) + + ;; unsub from old acc + (if (some? old-user) + ;; TODO: make this a do statement + ;; add a call to reset the UI + (make-unsubscribe-req sigd-input old-user)) + + ;; sub to new account + (if (some? new-user) + (make-subscribe-req sigd-input new-user) + (make-contact-sync-req sigd-input new-user))))) ;; find avail accounts (make-list-accounts-req sigd-input) diff --git a/src/whisper/signald.clj b/src/whisper/signald.clj index 4aa9917..dccb59f 100644 --- a/src/whisper/signald.clj +++ b/src/whisper/signald.clj @@ -59,6 +59,12 @@ (json/write-str {"type" "subscribe" "username" username}))) +(defn make-unsubscribe-req + [output-stream username] + (-make-req output-stream + (json/write-str {"type" "unsubscribe" + "username" username}))) + (defn make-contact-sync-req [output-stream username] (-make-req output-stream