make subscribe and contact sync requests once user is chosen

This commit is contained in:
Aidan 2020-11-25 21:31:05 -08:00
parent 3ed3b2a6d3
commit 3b409dd7fb
No known key found for this signature in database
GPG key ID: 327711E983899316
2 changed files with 25 additions and 7 deletions

View file

@ -20,7 +20,8 @@
(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"
@ -35,8 +36,7 @@
;; register callbacks between the UI and signald ;; register callbacks between the UI and signald
(assoc-callback-type "version" (fn [x] (add-str-flag (get-version-from-version-message x)))) (assoc-callback-type "version" (fn [x] (add-str-flag (get-version-from-version-message x))))
(assoc-callback-type "linking_uri" (fn [x] (paint-linking x))) (assoc-callback-type "linking_uri" (fn [x] (paint-linking x)))
(assoc-callback-type "linking_successful" (fn [_] (assoc-callback-type "linking_successful" (fn [_] (paint-linking nil)))
(paint-linking nil)))
(assoc-callback-type "linking_error" (fn [_] (assoc-callback-type "linking_error" (fn [_]
(paint-linking nil) (paint-linking nil)
(add-str-flag "Linking returned Error"))) (add-str-flag "Linking returned Error")))
@ -53,10 +53,16 @@
sigd-loop (thread (callback-loop sigd-output))] sigd-loop (thread (callback-loop sigd-output))]
;; handle login basically ;; handle login basically
(assoc-callback-type "account_list" (fn [x] (if (< (count x) 1) (assoc-callback-type "account_list"
(fn [x]
(if (< (count x) 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)
(handle-users x)))) (let [username (handle-users x)]
(make-subscription-req sigd-input username)
;; list_contacts?
;; TODO: sync/list groups
(make-contact-sync-req sigd-input username))))))
;; find avail accounts ;; find avail accounts
(make-list-accounts-req sigd-input) (make-list-accounts-req sigd-input)

View file

@ -52,3 +52,15 @@
(defn make-list-accounts-req (defn make-list-accounts-req
[output-stream] [output-stream]
(-make-req output-stream "{\"type\": \"list_accounts\"}\n")) (-make-req output-stream "{\"type\": \"list_accounts\"}\n"))
(defn make-subscribe-req
[output-stream username]
(-make-req output-stream
(json/write-str {"type" "subscribe"
"username" username})))
(defn make-contact-sync-req
[output-stream username]
(-make-req output-stream
(json/write-str {"type" "sync_contacts"
"username" username})))