@@ -171,7 +171,10 @@ module App =
172 { model with
172 { model with
173 Auth = Identified(id, Online token)
173 Auth = Identified(id, Online token)
174− Page = match model.Page with Setup -> Conversations | p -> p
175+ match model.Page with
176+ | Setup -> Conversations
175 Error = None
178 Error = None
176 PollStatus = "polling..."
179 PollStatus = "polling..."
177 FlushingOutbox = true },
180 FlushingOutbox = true },
@@ -189,7 +192,10 @@ module App =
189 match model.Auth with
192 match model.Auth with
190 | Identified(id, Online _) ->
193 | Identified(id, Online _) ->
191 let m = setConn Connecting model
194 let m = setConn Connecting model
192− { m with FlushingOutbox = false; PollRetries = 0 },
197+ FlushingOutbox = false
193 [ CmdConnect(model.ServerUrl, id) ]
199 [ CmdConnect(model.ServerUrl, id) ]
194 | _ -> model, []
200 | _ -> model, []
@@ -273,17 +279,17 @@ module App =
273 | Some bytes ->
279 | Some bytes ->
274 let hex = Crypto.toHex bytes
280 let hex = Crypto.toHex bytes
277− match Map.tryFind hex model.Contacts with
282+ match Map.tryFind hex model.Contacts with
278− | Some e -> { e with Nickname = cpk }
283+ | Some e -> model, []
279− | None -> newContact hex cpk
285+ let contact = newContact hex cpk
281− let model' =
287+ let model' =
282− { model with
288+ { model with
283− Contacts = Map.add hex contact model.Contacts
289+ Contacts = Map.add hex contact model.Contacts
284− Page = Conversations }
290+ Page = Conversations }
286− model', [ saveCmdMsg model' ]
292+ model', [ saveCmdMsg model' ]
287 | None ->
293 | None ->
288 { model with
294 { model with
289 Error = Some "Invalid public key" },
295 Error = Some "Invalid public key" },
@@ -519,68 +525,68 @@ module App =
519 dispatch TokenExpired
525 dispatch TokenExpired
522− let ackIds = response.Events |> Array.map _.Id |> Array.toList
528+ let ackIds = response.Events |> Array.map _.Id |> Array.toList
526− |> Array.choose (fun evt ->
527− match evt.EventType with
528− | Message -> Some(decryptEvent session.Identity.PrivKey evt.Payload)
530− log $"unknown event type: {s}"
533− let events = results |> Array.choose Result.toOption |> Array.toList
537− |> Array.choose (function
543− log $"decrypt error: {e}"
545− if not ackIds.IsEmpty then
547− do! ackMessages session.Url session.Token ackIds
549− log $"ack error: {ex.Message}"
551− if not events.IsEmpty then
554− |> List.choose (fun evt ->
555− match evt.Envelope with
556− | Envelope.TextMessage(id, _) -> Some(evt.Sender, id)
559− |> List.map (fun (sender, pairs) -> sender, List.map snd pairs)
561− for sender, msgIds in acksBySender do
530+ let results =
562− try
531+ response.Events
563− do! sendEnvelope session sender (Envelope.DeliveryAck msgIds)
532+ |> Array.choose (fun evt ->
564− with ex ->
533+ match evt.EventType with
565− log $"delivery ack error: {ex.Message}"
534+ | Message -> Some(decryptEvent session.Identity.PrivKey evt.Payload)
536+ log $"unknown event type: {s}"
567− if response.Events.Length = 0 then
539+ let events = results |> Array.choose Result.toOption |> Array.toList
568− do! Async.Sleep Constants.pollEmptyDelayMs
570− let chatCount =
541+ let errors =
572− |> List.sumBy (fun e ->
543+ |> Array.choose (function
573− match e.Envelope with
544+ | Error e -> Some e
574− | Envelope.TextMessage _ -> 1
545+ | _ -> None)
575− | _ -> 0)
546+ |> Array.toList
577− let status =
548+ for e in errors do
578− $"evts:{response.Events.Length} msgs:{chatCount} errs:{errors.Length}"
549+ log $"decrypt error: {e}"
579− + (match List.tryHead errors with
580− | Some e -> $" [{e}]"
551+ if not ackIds.IsEmpty then
553+ do! ackMessages session.Url session.Token ackIds
555+ log $"ack error: {ex.Message}"
557+ if not events.IsEmpty then
560+ |> List.choose (fun evt ->
561+ match evt.Envelope with
562+ | Envelope.TextMessage(id, _) -> Some(evt.Sender, id)
565+ |> List.map (fun (sender, pairs) -> sender, List.map snd pairs)
567+ for sender, msgIds in acksBySender do
569+ do! sendEnvelope session sender (Envelope.DeliveryAck msgIds)
571+ log $"delivery ack error: {ex.Message}"
573+ if response.Events.Length = 0 then
574+ do! Async.Sleep Constants.pollEmptyDelayMs
578+ |> List.sumBy (fun e ->
579+ match e.Envelope with
580+ | Envelope.TextMessage _ -> 1
584+ $"evts:{response.Events.Length} msgs:{chatCount} errs:{errors.Length}"
585+ + (match List.tryHead errors with
586+ | Some e -> $" [{e}]"
583− dispatch (PollResult(events, status, response.Cursor))
589+ dispatch (PollResult(events, status, response.Cursor))
585 | :? TimeoutException ->
591 | :? TimeoutException ->
586 log "poll timeout"
592 log "poll timeout"