@@ -21,12 +21,6 @@ module App =
2121 Timestamp: DateTimeOffset
2222 IsOutgoing: bool }
2323
24− type IncomingMessage =
25− { FromPubkey: string
26− Body: string
27− Timestamp: int64
28− MessageId: string }
29−
3024 [<CLIMutable>]
3125 type TextEnvelope =
3226 { ``type``: string
@@ -47,11 +41,11 @@ module App =
4741
4842 type ConnState =
4943 | Offline
50− | Connecting
44+ | Connecting of Identity
5145 | Online of Session
5246
5347 type PollResultData =
54− { Messages: IncomingMessage list
48+ { Messages: (string * ChatMessage) list
5549 Status: string
5650 Cursor: uint64 }
5751
@@ -183,12 +177,12 @@ module App =
183177 | DoConnect ->
184178 match model.Identity with
185179 | Some id ->
186− { model with Conn = Connecting }, [ CmdConnect(model.ServerUrl, id) ]
180+ { model with Conn = Connecting id }, [ CmdConnect(model.ServerUrl, id) ]
187181 | None -> { model with Error = Some "No identity generated" }, []
188182
189183 | AuthOk token ->
190− match model.Conn, model.Identity with
191− | Connecting, Some id ->
184+ match model.Conn with
185+ | Connecting id ->
192186 let session = { Url = model.ServerUrl; Token = token; Identity = id }
193187 { model with Conn = Online session; Page = Conversations; Error = None },
194188 [ CmdPoll(session, model.PollCursor) ]
@@ -225,19 +219,13 @@ module App =
225219 let model' =
226220 incoming
227221 |> List.fold
228− (fun m msg ->
229− if messagesFor msg.FromPubkey m.Messages |> List.exists (fun x -> x.Id = msg.MessageId) then
222+ (fun m (fromPubkey, chatMsg) ->
223+ if messagesFor fromPubkey m.Messages |> List.exists (fun x -> x.Id = chatMsg.Id) then
230224 m
231225 else
232− let chatMsg =
233− { Id = msg.MessageId
234− Body = msg.Body
235− Timestamp = DateTimeOffset.FromUnixTimeSeconds(msg.Timestamp)
236− IsOutgoing = false }
237−
238226 { m with
239− Contacts = m.Contacts |> addContactIfNew { Pubkey = msg.FromPubkey; Nickname = truncKey msg.FromPubkey }
240− Messages = m.Messages |> appendMessage msg.FromPubkey chatMsg })
227+ Contacts = m.Contacts |> addContactIfNew { Pubkey = fromPubkey; Nickname = truncKey fromPubkey }
228+ Messages = m.Messages |> appendMessage fromPubkey chatMsg })
241229 { model with PollStatus = status; PollCursor = newCursor }
242230
243231 let cmds =
@@ -276,7 +264,7 @@ module App =
276264
277265 | StateLoaded { Identity = None } -> model, []
278266 | StateLoaded { Identity = Some identity; Data = dataOpt } ->
279− let model' = { model with Identity = Some identity; Conn = Connecting }
267+ let model' = { model with Identity = Some identity; Conn = Connecting identity }
280268
281269 let model' =
282270 match dataOpt with
@@ -324,10 +312,11 @@ module App =
324312 let envelope = JsonSerializer.Deserialize<TextEnvelope>(plaintext)
325313
326314 if envelope.``type`` = "text" then
327− Ok { FromPubkey = senderHex
315+ Ok(senderHex,
316+ { Id = envelope.id
328317 Body = envelope.body
329− Timestamp = payload.Timestamp
330− MessageId = envelope.id }
318+ Timestamp = DateTimeOffset.FromUnixTimeSeconds(payload.Timestamp)
319+ IsOutgoing = false })
331320 else
332321 Error "unknown type"
333322 | None -> Error "decrypt failed"
@@ -488,7 +477,7 @@ module App =
488477
489478 match model.Conn with
490479 | Offline -> Button("Connect", DoConnect)
491− | Connecting -> Label("Connecting...").centerTextHorizontal()
480+ | Connecting _ -> Label("Connecting...").centerTextHorizontal()
492481 | Online _ ->
493482 Button("Disconnect", DoDisconnect)
494483 Button("Go to Conversations", Nav Conversations)
@@ -501,7 +490,7 @@ module App =
501490 let connStr =
502491 match model.Conn with
503492 | Offline -> "OFFLINE"
504− | Connecting -> "CONNECTING"
493+ | Connecting _ -> "CONNECTING"
505494 | Online _ -> "ONLINE"
506495
507496 let contactNames =