@@ -77,6 +77,11 @@ module App =
7777
7878 // ── Msg ──
7979
80+ type StateLoadResult =
81+ | IdentityAndData of Identity * Data
82+ | IdentityOnly of Identity
83+ | NothingSaved
84+
8085 type Msg =
8186 | SetPage of Page
8287 | SetCompose of string
@@ -95,7 +100,7 @@ module App =
95100 | PollResult of messages: (string * ChatMessage) list * status: string * cursor: int64
96101 | CopyPubKey
97102 | DismissError
98− | StateLoaded of (Identity * Data option) option
103+ | StateLoaded of StateLoadResult
99104
100105 // ── CmdMsg ──
101106
@@ -157,11 +162,6 @@ module App =
157162 | Some i -> contacts |> List.updateAt i contact
158163 | None -> contacts @ [ contact ]
159164
160− let private pubKeyHex model =
161− match model.Auth with
162− | Identified(id, _) -> id.PubKeyHex
163− | NoIdentity -> ""
164−
165165 let private trySession model =
166166 match model.Auth with
167167 | Identified(id, Online token) -> Some { Url = model.ServerUrl; Token = token; Identity = id }
@@ -293,7 +293,7 @@ module App =
293293
294294 | DismissError -> { model with Error = None }, []
295295
296− | StateLoaded(Some(identity, Some data)) ->
296+ | StateLoaded(IdentityAndData(identity, data)) ->
297297 let model' =
298298 { model with
299299 Auth = Identified(identity, Connecting)
@@ -303,9 +303,9 @@ module App =
303303 PollCursor = data.PollCursor
304304 Page = Conversations }
305305 model', [ CmdConnect(model'.ServerUrl, identity) ]
306− | StateLoaded(Some(identity, None)) ->
306+ | StateLoaded(IdentityOnly identity) ->
307307 { model with Auth = Identified(identity, Offline); Page = Settings }, []
308− | StateLoaded None -> model, []
308+ | StateLoaded NothingSaved -> model, []
309309
310310 // ── mapCmd ──
311311
@@ -411,8 +411,12 @@ module App =
411411 | CmdLoadState ->
412412 asyncCmd (async {
413413 match! Store.loadIdentity () with
414− | Some id -> return StateLoaded(Some(id, Store.loadData ()))
415− | None -> return StateLoaded None
414+ | Some id ->
415+ return StateLoaded(
416+ match Store.loadData () with
417+ | Some data -> IdentityAndData(id, data)
418+ | None -> IdentityOnly id)
419+ | None -> return StateLoaded NothingSaved
416420 })
417421
418422 | CmdSaveIdentity identity ->
@@ -449,32 +453,34 @@ module App =
449453 .font(size = 24.)
450454 .centerTextHorizontal()
451455
452− Label("Your Public Key:")
456+ match model.Auth with
457+ | Identified(id, conn) ->
458+ Label("Your Public Key:")
453459
454− Label(truncOb (hexToOb (pubKeyHex model)))
455− .font(size = 14.)
460+ Label(truncOb (hexToOb id.PubKeyHex))
461+ .font(size = 14.)
456462
457− Button("Copy Public Key", CopyPubKey)
463+ Button("Copy Public Key", CopyPubKey)
458464
459− Label("Server:")
465+ Label("Server:")
460466
461− Entry(model.ServerUrl, SetServerUrl)
467+ Entry(model.ServerUrl, SetServerUrl)
462468
463− match model.Error with
464− | Some err ->
465− Label(err)
466− .textColor(Colors.Red)
467− .font(size = 12.)
469+ match model.Error with
470+ | Some err ->
471+ Label(err)
472+ .textColor(Colors.Red)
473+ .font(size = 12.)
468474
469− Button("Dismiss", DismissError)
470− | None -> ()
475+ Button("Dismiss", DismissError)
476+ | None -> ()
471477
472− match model.Auth with
473− | Identified(_, Offline) -> Button("Connect", DoConnect)
474− | Identified(_, Connecting) -> Label("Connecting...").centerTextHorizontal()
475− | Identified(_, Online _) ->
476− Button("Disconnect", DoDisconnect)
477− Button("Go to Conversations", SetPage Conversations)
478+ match conn with
479+ | Offline -> Button("Connect", DoConnect)
480+ | Connecting -> Label("Connecting...").centerTextHorizontal()
481+ | Online _ ->
482+ Button("Disconnect", DoDisconnect)
483+ Button("Go to Conversations", SetPage Conversations)
478484 | NoIdentity -> ()
479485 })
480486 .padding(20.)