refactor login process

This commit is contained in:
Aidan 2020-11-25 22:06:20 -08:00
parent 3b409dd7fb
commit 60580189ae
No known key found for this signature in database
GPG key ID: 327711E983899316
3 changed files with 39 additions and 13 deletions

View file

@ -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 ## Installation
Download from http://example.com/FIXME. Currently: use lein run
TODO: package, wrap with a nice makefile
## Usage ## Usage
Call `lein run` in a freshly cloned repository to run Whisper. Make sure Signald is already running.
FIXME: explanation FIXME: explanation
$ java -jar whisper-0.1.0-standalone.jar [args] $ java -jar whisper-0.1.0-standalone.jar [args]
@ -30,7 +35,7 @@ FIXME: listing of options this app accepts.
## License ## License
Copyright © 2019 FIXME Copyright © 2019 Aidan Hahn
This program and the accompanying materials are made available under the This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at terms of the Eclipse Public License 2.0 which is available at

View file

@ -12,7 +12,7 @@
[whisper.signald])) [whisper.signald]))
(def sockpath "/var/run/signald/signald.sock") (def sockpath "/var/run/signald/signald.sock")
(def user (atom {})) (def user (atom {"username" "" "filename" ""}))
;; TODO: handle multi users (with list ui) ;; TODO: handle multi users (with list ui)
(defn handle-users (defn handle-users
@ -20,8 +20,7 @@
(let [users (get-in data ["data" "accounts"])] (let [users (get-in data ["data" "accounts"])]
(if (> (count users) 1) (if (> (count users) 1)
(log/info "Alert, multi account not supported yet. picking first on list")) (log/info "Alert, multi account not supported yet. picking first on list"))
(swap! user (first users)) (swap! user (first users))))
(get @user "username")))
(defn -main (defn -main
"packs and shows main window with signald version string" "packs and shows main window with signald version string"
@ -55,14 +54,30 @@
;; handle login basically ;; handle login basically
(assoc-callback-type "account_list" (assoc-callback-type "account_list"
(fn [x] (fn [x]
(if (< (count x) 1) (if (< (count (get-in x ["data" "accounts"])) 1)
(do (make-link-data-req sigd-input) (do (make-link-data-req sigd-input)
(make-list-accounts-req sigd-input) (make-list-accounts-req sigd-input)
(let [username (handle-users x)] (handle-users x)))))
(make-subscription-req sigd-input username)
;; list_contacts? ;; log in every time username changes
;; TODO: sync/list groups (add-watch user :login-manager
(make-contact-sync-req sigd-input username)))))) (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 ;; find avail accounts
(make-list-accounts-req sigd-input) (make-list-accounts-req sigd-input)

View file

@ -59,6 +59,12 @@
(json/write-str {"type" "subscribe" (json/write-str {"type" "subscribe"
"username" username}))) "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 (defn make-contact-sync-req
[output-stream username] [output-stream username]
(-make-req output-stream (-make-req output-stream