@@ -165,6 +165,9 @@ module App =
165165 | Some i -> contacts |> List.updateAt i contact
166166 | None -> contacts @ [ contact ]
167167
168+ let private newContact pubkey nickname : Contact =
169+ { Pubkey = pubkey; Nickname = nickname; DisplayName = ""; Bio = ""; PhotoBase64 = "" }
170+
168171 let private trySession model =
169172 match model.Auth with
170173 | Identified(id, Online token) -> Some { Url = model.ServerUrl; Token = token; Identity = id }
@@ -278,7 +281,7 @@ module App =
278281 match evt with
279282 | IncomingChat(senderPubkey, message) ->
280283 { m with
281− Contacts = m.Contacts |> addContactIfNew { Pubkey = senderPubkey; Nickname = truncKey senderPubkey; DisplayName = ""; Bio = ""; PhotoBase64 = "" }
284+ Contacts = m.Contacts |> addContactIfNew (newContact senderPubkey (truncKey senderPubkey))
282285 Messages = m.Messages |> appendMessage senderPubkey message }
283286 | IncomingDeliveryAck(senderPubkey, ackIds) ->
284287 { m with Messages = m.Messages |> markDelivered senderPubkey ackIds }
@@ -308,7 +311,7 @@ module App =
308311 let contact: Contact =
309312 match existing with
310313 | Some e -> { e with Nickname = cnn }
311− | None -> { Pubkey = hex; Nickname = cnn; DisplayName = ""; Bio = ""; PhotoBase64 = "" }
314+ | None -> newContact hex cnn
312315
313316 let model' =
314317 { model with
@@ -400,6 +403,11 @@ module App =
400403 return! sendMessage session.Url session.Token recipientHex (Crypto.toHex blob) ts
401404 }
402405
406+ let private tryGetJsonString (el: JsonElement) (name: string) =
407+ match el.TryGetProperty(name) with
408+ | true, v when v.ValueKind <> JsonValueKind.Null -> Some(v.GetString())
409+ | _ -> None
410+
403411 let private parseEnvelope (json: string) =
404412 use doc = JsonDocument.Parse(json)
405413 let root = doc.RootElement
@@ -411,14 +419,8 @@ module App =
411419 Some(DeliveryAck(root.GetProperty("id").GetString(), ackIds))
412420 | "profile" ->
413421 let displayName = root.GetProperty("display_name").GetString()
414− let bio =
415− match root.TryGetProperty("bio") with
416− | true, el when el.ValueKind <> JsonValueKind.Null -> el.GetString()
417− | _ -> ""
418− let photo =
419− match root.TryGetProperty("photo") with
420− | true, el when el.ValueKind <> JsonValueKind.Null -> Some(el.GetString())
421− | _ -> None
422+ let bio = tryGetJsonString root "bio" |> Option.defaultValue ""
423+ let photo = tryGetJsonString root "photo"
422424 Some(ProfileMessage(root.GetProperty("id").GetString(), displayName, bio, photo))
423425 | _ -> None
424426
@@ -541,8 +543,7 @@ module App =
541543 asyncCmd (async {
542544 try
543545 let! results = Microsoft.Maui.Media.MediaPicker.Default.PickPhotosAsync() |> Async.AwaitTask
544− let file = results |> Seq.tryHead
545− match file with
546+ match results |> Seq.tryHead with
546547 | None -> return PhotoPicked None
547548 | Some file ->
548549 use! stream = file.OpenReadAsync() |> Async.AwaitTask
@@ -619,19 +620,15 @@ module App =
619620 Button("Copy Public Key", CopyPubKey)
620621
621622 Label("Profile:").font(size = 18.)
622− match model.Profile with
623− | Some profile when profile.DisplayName <> "" ->
624− Label($"Name: {profile.DisplayName}").font(size = 14.)
625− | _ -> ()
626− match model.Profile with
627− | Some profile when profile.Bio <> "" ->
628− Label($"Bio: {profile.Bio}").font(size = 14.).textColor(Colors.DimGray)
629− | _ -> ()
630− let profilePage =
623+ let displayName, bio, photo =
631624 match model.Profile with
632− | Some p -> EditProfile(p.DisplayName, p.Bio, p.PhotoBase64)
633− | None -> EditProfile("", "", None)
634− Button("Edit Profile", SetPage profilePage)
625+ | Some p -> p.DisplayName, p.Bio, p.PhotoBase64
626+ | None -> "", "", None
627+ if displayName <> "" then
628+ Label($"Name: {displayName}").font(size = 14.)
629+ if bio <> "" then
630+ Label($"Bio: {bio}").font(size = 14.).textColor(Colors.DimGray)
631+ Button("Edit Profile", SetPage(EditProfile(displayName, bio, photo)))
635632
636633 Label("Server:")
637634