@@ -48,7 +48,12 @@ federationEnabled = federationSecret != ""
49-- ============================================
49-- ============================================
51+data PollEventType = PtMessage {}
53+impl ToJSON PollEventType where
54+ toJson _ = toJson "message"
51−type PollEvent = {id: MessageIdHex, eventType: Text, payload: {encryptedBlob: BlobHex, fromKey: PubkeyHex, timestamp: Timestamp, toKey: PubkeyHex}}
56+type PollEvent = {id: MessageIdHex, eventType: PollEventType, payload: {encryptedBlob: BlobHex, fromKey: PubkeyHex, timestamp: Timestamp, toKey: PubkeyHex}}
53data GossipEventType = GossipOnline {} | GossipOffline {} | GossipUnknown {}
58data GossipEventType = GossipOnline {} | GossipOffline {} | GossipUnknown {}
@@ -73,15 +78,15 @@ type GossipEvent = {eventType: GossipEventType, pubkey: PubkeyHex, server: Serve
74type ValidGossipEntry = {eventType: GossipEventType, pubkey: PubkeyHex, server: ServerName, expiresAt: Timestamp, timestamp: Timestamp, ttl: Int<S>}
79type ValidGossipEntry = {eventType: GossipEventType, pubkey: PubkeyHex, server: ServerName, expiresAt: Timestamp, timestamp: Timestamp, ttl: Int<S>}
76−data MessageStatus = MsDelivered {} | MsFederated {} | MsQueued {}
81+data MessageStatus = MsDelivered {} | MsFederated {} | MsQueued {} | MsUnauthorized {} | MsRejected {}
78−messageStatusText = \ms -> case ms of
79− MsDelivered {} -> "delivered"
80− MsFederated {} -> "federated"
81− MsQueued {} -> "queued"
83impl ToJSON MessageStatus where
83impl ToJSON MessageStatus where
84− toJson ms = toJson (messageStatusText ms)
84+ toJson ms = toJson (case ms of
85+ MsDelivered {} -> "delivered"
86+ MsFederated {} -> "federated"
87+ MsQueued {} -> "queued"
88+ MsUnauthorized {} -> "unauthorized"
89+ MsRejected {} -> "rejected")
86type PubkeyHex = Text where \s -> isValidHex s && not (tooLong s maxPubkeyLen) && s == normalizeHex s
91type PubkeyHex = Text where \s -> isValidHex s && not (tooLong s maxPubkeyLen) && s == normalizeHex s
87type BlobHex = Text where \s -> isValidHex s && not (tooLong s maxBlobLen) && s == normalizeHex s
92type BlobHex = Text where \s -> isValidHex s && not (tooLong s maxBlobLen) && s == normalizeHex s
@@ -150,7 +155,7 @@ route ClientApi where
151 /messages
156 /messages
152 POST {to: PubkeyHex, encryptedBlob: BlobHex, timestamp: Timestamp} / headers {authorization: Text}
157 POST {to: PubkeyHex, encryptedBlob: BlobHex, timestamp: Timestamp} / headers {authorization: Text}
153− -> {status: Text, messageId: OptionalMessageId}
158+ -> {status: MessageStatus, messageId: OptionalMessageId}
154 = SendMessage
159 = SendMessage
155 POST {messageIds: [MessageIdHex]} /ack headers {authorization: Text}
160 POST {messageIds: [MessageIdHex]} /ack headers {authorization: Text}
156 -> {ok: Bool}
161 -> {ok: Bool}
@@ -727,7 +732,7 @@ pollOnce = \token cursor -> do
727 let limitedMsgs = boundedSmallest matchingMsgs maxPollEvents (\m -> m.receivedAt)
732 let limitedMsgs = boundedSmallest matchingMsgs maxPollEvents (\m -> m.receivedAt)
728 let evts = do
733 let evts = do
729 m <- limitedMsgs
734 m <- limitedMsgs
730− yield {id: m.messageId, eventType: "message",
735+ yield {id: m.messageId, eventType: PtMessage {},
731 payload: {toKey: m.toKey, fromKey: m.fromKey,
736 payload: {toKey: m.toKey, fromKey: m.fromKey,
732 encryptedBlob: m.encryptedBlob,
737 encryptedBlob: m.encryptedBlob,
733 timestamp: m.timestamp}}
738 timestamp: m.timestamp}}
@@ -872,9 +877,9 @@ serve = \req -> case req of
872 _ -> yield {}
877 _ -> yield {}
873 broadcastOfflineGossip t result.pr.peerServers result.pr.expiredLocal)
878 broadcastOfflineGossip t result.pr.peerServers result.pr.expiredLocal)
874 yield (case result.send of
879 yield (case result.send of
875− SendUnauthorized {} -> respond {status: "unauthorized", messageId: ""}
880+ SendUnauthorized {} -> respond {status: MsUnauthorized {}, messageId: ""}
876− SendRejected {} -> respond {status: "rejected", messageId: ""}
881+ SendRejected {} -> respond {status: MsRejected {}, messageId: ""}
877− SendDone {status} -> respond {status: messageStatusText status, messageId: msgId})
882+ SendDone {status} -> respond {status: status, messageId: msgId})
879 AckMessages {messageIds, authorization, respond} -> do
884 AckMessages {messageIds, authorization, respond} -> do
@@ -892,9 +897,11 @@ serve = \req -> case req of
892 where m.toKey == pubkey && any dedupedIds (\mid -> m.messageId == mid)
897 where m.toKey == pubkey && any dedupedIds (\mid -> m.messageId == mid)
894 set *messages = diff messages ackedMessages
899 set *messages = diff messages ackedMessages
895− let ackedFederated = fold (\acc m -> case m.origin of
900+ let ackedFederated = do
896− FederatedOrigin {server} -> union acc [{messageId: m.messageId, toKey: m.toKey, ackedAt: t, originServer: server}]
903+ FederatedOrigin {server} -> yield {messageId: m.messageId, toKey: m.toKey, ackedAt: t, originServer: server}
897− LocalOrigin {} -> acc) [] ackedMessages
904+ LocalOrigin {} -> []
898 ackedIds <- *ackedIds
905 ackedIds <- *ackedIds
899 let combinedAckedIds = union ackedIds ackedFederated
906 let combinedAckedIds = union ackedIds ackedFederated
900 let evictedEntries = let excessCount = count combinedAckedIds - maxAckedIds in
907 let evictedEntries = let excessCount = count combinedAckedIds - maxAckedIds in