@@ -21,12 +21,6 @@ module App =
21 Timestamp: DateTimeOffset
21 Timestamp: DateTimeOffset
22 IsOutgoing: bool }
22 IsOutgoing: bool }
24− type IncomingMessage =
30 [<CLIMutable>]
24 [<CLIMutable>]
31 type TextEnvelope =
25 type TextEnvelope =
32 { ``type``: string
26 { ``type``: string
@@ -47,11 +41,11 @@ module App =
48 type ConnState =
42 type ConnState =
50− | Connecting
44+ | Connecting of Identity
51 | Online of Session
45 | Online of Session
53 type PollResultData =
47 type PollResultData =
54− { Messages: IncomingMessage list
48+ { Messages: (string * ChatMessage) list
55 Status: string
49 Status: string
56 Cursor: uint64 }
50 Cursor: uint64 }
@@ -183,12 +177,12 @@ module App =
183 | DoConnect ->
177 | DoConnect ->
184 match model.Identity with
178 match model.Identity with
185 | Some id ->
179 | Some id ->
186− { model with Conn = Connecting }, [ CmdConnect(model.ServerUrl, id) ]
180+ { model with Conn = Connecting id }, [ CmdConnect(model.ServerUrl, id) ]
187 | None -> { model with Error = Some "No identity generated" }, []
181 | None -> { model with Error = Some "No identity generated" }, []
189 | AuthOk token ->
183 | AuthOk token ->
190− match model.Conn, model.Identity with
184+ match model.Conn with
191− | Connecting, Some id ->
185+ | Connecting id ->
192 let session = { Url = model.ServerUrl; Token = token; Identity = id }
186 let session = { Url = model.ServerUrl; Token = token; Identity = id }
193 { model with Conn = Online session; Page = Conversations; Error = None },
187 { model with Conn = Online session; Page = Conversations; Error = None },
194 [ CmdPoll(session, model.PollCursor) ]
188 [ CmdPoll(session, model.PollCursor) ]
@@ -225,19 +219,13 @@ module App =
225 let model' =
219 let model' =
227 |> List.fold
221 |> List.fold
228− (fun m msg ->
222+ (fun m (fromPubkey, chatMsg) ->
229− if messagesFor msg.FromPubkey m.Messages |> List.exists (fun x -> x.Id = msg.MessageId) then
223+ if messagesFor fromPubkey m.Messages |> List.exists (fun x -> x.Id = chatMsg.Id) then
233− { Id = msg.MessageId
235− Timestamp = DateTimeOffset.FromUnixTimeSeconds(msg.Timestamp)
236− IsOutgoing = false }
239− Contacts = m.Contacts |> addContactIfNew { Pubkey = msg.FromPubkey; Nickname = truncKey msg.FromPubkey }
227+ Contacts = m.Contacts |> addContactIfNew { Pubkey = fromPubkey; Nickname = truncKey fromPubkey }
240− Messages = m.Messages |> appendMessage msg.FromPubkey chatMsg })
228+ Messages = m.Messages |> appendMessage fromPubkey chatMsg })
241 { model with PollStatus = status; PollCursor = newCursor }
229 { model with PollStatus = status; PollCursor = newCursor }
243 let cmds =
231 let cmds =
@@ -276,7 +264,7 @@ module App =
277 | StateLoaded { Identity = None } -> model, []
265 | StateLoaded { Identity = None } -> model, []
278 | StateLoaded { Identity = Some identity; Data = dataOpt } ->
266 | 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 }
281 let model' =
269 let model' =
282 match dataOpt with
270 match dataOpt with
@@ -324,10 +312,11 @@ module App =
324 let envelope = JsonSerializer.Deserialize<TextEnvelope>(plaintext)
312 let envelope = JsonSerializer.Deserialize<TextEnvelope>(plaintext)
326 if envelope.``type`` = "text" then
314 if envelope.``type`` = "text" then
327− Ok { FromPubkey = senderHex
315+ Ok(senderHex,
328 Body = envelope.body
317 Body = envelope.body
329− Timestamp = payload.Timestamp
318+ Timestamp = DateTimeOffset.FromUnixTimeSeconds(payload.Timestamp)
330− MessageId = envelope.id }
319+ IsOutgoing = false })
332 Error "unknown type"
321 Error "unknown type"
333 | None -> Error "decrypt failed"
322 | None -> Error "decrypt failed"
@@ -488,7 +477,7 @@ module App =
489 match model.Conn with
478 match model.Conn with
490 | Offline -> Button("Connect", DoConnect)
479 | Offline -> Button("Connect", DoConnect)
491− | Connecting -> Label("Connecting...").centerTextHorizontal()
480+ | Connecting _ -> Label("Connecting...").centerTextHorizontal()
492 | Online _ ->
481 | Online _ ->
493 Button("Disconnect", DoDisconnect)
482 Button("Disconnect", DoDisconnect)
494 Button("Go to Conversations", Nav Conversations)
483 Button("Go to Conversations", Nav Conversations)
@@ -501,7 +490,7 @@ module App =
501 let connStr =
490 let connStr =
502 match model.Conn with
491 match model.Conn with
503 | Offline -> "OFFLINE"
492 | Offline -> "OFFLINE"
504− | Connecting -> "CONNECTING"
493+ | Connecting _ -> "CONNECTING"
505 | Online _ -> "ONLINE"
494 | Online _ -> "ONLINE"
507 let contactNames =
496 let contactNames =