@@ -297,6 +297,11 @@ update msg model =
297 timestamp =
297 timestamp =
298 model.currentTime
298 model.currentTime
302+ |> Maybe.map X.publicKeyToHex
303+ |> Maybe.withDefault ""
300 plaintextJson =
305 plaintextJson =
301 Encode.encode 0
306 Encode.encode 0
302 (Encode.object
307 (Encode.object
@@ -304,11 +309,12 @@ update msg model =
304 , ( "id", Encode.string msgId )
309 , ( "id", Encode.string msgId )
305 , ( "timestamp", Encode.int timestamp )
310 , ( "timestamp", Encode.int timestamp )
306 , ( "body", Encode.string model.draft )
311 , ( "body", Encode.string model.draft )
312+ , ( "xpub", Encode.string senderXPubHex )
311− encryptMessage edPriv edPub c.xPubHex ephSeedHex nonceHex plaintextJson
317+ encryptMessage edPriv edPub senderXPubHex c.xPubHex ephSeedHex nonceHex plaintextJson
314 { id = msgId
320 { id = msgId
@@ -390,36 +396,42 @@ update msg model =
391 updatedMessages =
397 updatedMessages =
392 List.foldl
398 List.foldl
393− (\( from, chatMsg ) dict ->
399+ (\im dict ->
395 existing =
401 existing =
396− Dict.get from dict |> Maybe.withDefault []
402+ Dict.get im.senderEdPubHex dict |> Maybe.withDefault []
398− Dict.insert from (existing ++ [ chatMsg ]) dict
404+ Dict.insert im.senderEdPubHex (existing ++ [ im.chatMsg ]) dict
400 model.messages
406 model.messages
401 newMessages
407 newMessages
403 updatedContacts =
409 updatedContacts =
404 List.foldl
410 List.foldl
405− (\( from, chatMsg ) dict ->
411+ (\im dict ->
406− Dict.update from
412+ Dict.update im.senderEdPubHex
407 (\existing ->
413 (\existing ->
408 case existing of
414 case existing of
409 Just c ->
415 Just c ->
412− | lastMessage = chatMsg.body
418+ | lastMessage = im.chatMsg.body
413− , lastTime = chatMsg.timestamp
419+ , lastTime = im.chatMsg.timestamp
421+ if String.isEmpty c.xPubHex && not (String.isEmpty im.senderXPubHex) then
416 Nothing ->
428 Nothing ->
418− { edPubHex = from
430+ { edPubHex = im.senderEdPubHex
419− , xPubHex = ""
431+ , xPubHex = im.senderXPubHex
420− , name = String.left 8 from ++ "..."
432+ , name = String.left 8 im.senderEdPubHex ++ "..."
421− , lastMessage = chatMsg.body
433+ , lastMessage = im.chatMsg.body
422− , lastTime = chatMsg.timestamp
434+ , lastTime = im.chatMsg.timestamp
423 , online = True
435 , online = True
@@ -1267,8 +1279,9 @@ encryptMessage :
1267 -> String
1279 -> String
1268 -> String
1280 -> String
1269 -> String
1281 -> String
1270 -> Maybe String
1283 -> Maybe String
1271−encryptMessage edPriv edPub recipientXPubHex ephSeedHex nonceHex plaintextJson =
1284+encryptMessage edPriv edPub senderXPubHex recipientXPubHex ephSeedHex nonceHex plaintextJson =
1272 case ( X.privateKeyFromHex ephSeedHex, X.publicKeyFromHex recipientXPubHex, Cipher.nonce24FromHex nonceHex ) of
1285 case ( X.privateKeyFromHex ephSeedHex, X.publicKeyFromHex recipientXPubHex, Cipher.nonce24FromHex nonceHex ) of
1273 ( Just ephPriv, Just recipientXPub, Just nonce ) ->
1286 ( Just ephPriv, Just recipientXPub, Just nonce ) ->
@@ -1379,6 +1392,15 @@ decryptMessage xPriv blob =
1395+{-| Incoming message with sender info.
1397+type alias IncomingMessage =
1398+ { senderEdPubHex : String
1399+ , senderXPubHex : String
1400+ , chatMsg : ChatMessage
1382{-| Process poll events: decrypt, dedup, collect ACK IDs.
1404{-| Process poll events: decrypt, dedup, collect ACK IDs.
1384processEvents :
1406processEvents :
@@ -1386,7 +1408,7 @@ processEvents :
1386 -> String
1408 -> String
1387 -> List PollEvent
1409 -> List PollEvent
1388 -> Set String
1410 -> Set String
1389− -> ( List ( String, ChatMessage ), Set String, List String )
1411+ -> ( List IncomingMessage, Set String, List String )
1390processEvents xPriv myEdHex events seenIds =
1412processEvents xPriv myEdHex events seenIds =
1391 List.foldl
1413 List.foldl
1392 (\event ( msgs, seen, acks ) ->
1414 (\event ( msgs, seen, acks ) ->
@@ -1418,13 +1440,15 @@ processEvents xPriv myEdHex events seenIds =
1418 ( msgs, seen, event.id :: acks )
1440 ( msgs, seen, event.id :: acks )
1421− ( ( senderPub
1443+ ( { senderEdPubHex = senderPub
1444+ , senderXPubHex = payload.xpub
1422− , { id = payload.id
1446+ { id = payload.id
1423− , body = payload.body
1447+ , body = payload.body
1424− , timestamp = payload.timestamp
1448+ , timestamp = payload.timestamp
1425− , outgoing = False
1449+ , outgoing = False
1429 , Set.insert payload.id seen
1453 , Set.insert payload.id seen
1430 , event.id :: acks
1454 , event.id :: acks
@@ -1525,16 +1549,22 @@ type alias MessagePayload =
1525 , id : String
1549 , id : String
1526 , timestamp : Int
1550 , timestamp : Int
1527 , body : String
1551 , body : String
1531messagePayloadDecoder : Decoder MessagePayload
1556messagePayloadDecoder : Decoder MessagePayload
1532messagePayloadDecoder =
1557messagePayloadDecoder =
1533− Decode.map4 MessagePayload
1558+ Decode.map5 MessagePayload
1534 (Decode.field "type" Decode.string)
1559 (Decode.field "type" Decode.string)
1535 (Decode.field "id" Decode.string)
1560 (Decode.field "id" Decode.string)
1536 (Decode.field "timestamp" Decode.int)
1561 (Decode.field "timestamp" Decode.int)
1537 (Decode.field "body" Decode.string)
1562 (Decode.field "body" Decode.string)
1564+ [ Decode.field "xpub" Decode.string
1565+ , Decode.succeed ""
1540type alias LookupResponse =
1570type alias LookupResponse =