1 | #pragma once |
2 | |
3 | /// @file |
4 | /// @brief Read notifications |
5 | |
6 | #include <map> |
7 | #include <string> |
8 | |
9 | #if __has_include(<nlohmann/json_fwd.hpp>) |
10 | #include <nlohmann/json_fwd.hpp> |
11 | #else |
12 | #include <nlohmann/json.hpp> |
13 | #endif |
14 | |
15 | namespace mtx { |
16 | namespace events { |
17 | namespace ephemeral { |
18 | |
19 | //! An individual receipt, which specifies when the event was read by this user. |
20 | struct IndividualReceipt |
21 | { |
22 | //! The timestamp the receipt was sent at. |
23 | uint64_t ts = 0; |
24 | }; |
25 | |
26 | //! A list of receipts for a single event. |
27 | struct Receipts |
28 | { |
29 | //! The mapping of user ID to receipt. The user ID is the entity who sent this receipt. |
30 | std::map<std::string, IndividualReceipt> users; |
31 | }; |
32 | |
33 | /// @brief Read notifications / `m.receipt` |
34 | /// |
35 | /// These receipts are a form of acknowledgement of an event. This module defines a single |
36 | /// acknowledgement: m.read which indicates that the user has read up to a given event. |
37 | struct Receipt |
38 | { |
39 | //! The type of read receipt, currently public or private |
40 | enum ReceiptType |
41 | { |
42 | //! A public read receipt (m.read) |
43 | Read, |
44 | //! A private read receipt (MSC2285) |
45 | ReadPrivate |
46 | }; |
47 | //! The mapping of event ID to a collection of receipts for this event ID. The event ID is |
48 | //! the ID of the event being acknowledged and not an ID for the receipt itself. |
49 | std::map<std::string, std::map<ReceiptType, Receipts>> receipts; |
50 | |
51 | //! Deserialization method needed by @p nlohmann::json. |
52 | friend void from_json(const nlohmann::json &obj, Receipt &content); |
53 | |
54 | //! Serialization method needed by @p nlohmann::json. |
55 | friend void to_json(nlohmann::json &obj, const Receipt &content); |
56 | }; |
57 | |
58 | } // namespace state |
59 | } // namespace events |
60 | } // namespace mtx |
61 | |