Changeset View
Changeset View
Standalone View
Standalone View
src/client/room/room-model.hpp
| Show All 16 Lines | |||||
| #include <serialization/immer-box.hpp> | #include <serialization/immer-box.hpp> | ||||
| #include <serialization/immer-map.hpp> | #include <serialization/immer-map.hpp> | ||||
| #include <serialization/immer-array.hpp> | #include <serialization/immer-array.hpp> | ||||
| #include <csapi/sync.hpp> | #include <csapi/sync.hpp> | ||||
| #include <event.hpp> | #include <event.hpp> | ||||
| #include <crypto.hpp> | #include <crypto.hpp> | ||||
| #include "push-rules-desc.hpp" | |||||
| #include "local-echo.hpp" | #include "local-echo.hpp" | ||||
| #include "clientutil.hpp" | #include "clientutil.hpp" | ||||
| namespace Kazv | namespace Kazv | ||||
| { | { | ||||
| struct PendingRoomKeyEvent | struct PendingRoomKeyEvent | ||||
| { | { | ||||
| std::string txnId; | std::string txnId; | ||||
| ▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | struct UpdateJoinedMemberCountAction | ||||
| std::size_t joinedMemberCount; | std::size_t joinedMemberCount; | ||||
| }; | }; | ||||
| struct UpdateInvitedMemberCountAction | struct UpdateInvitedMemberCountAction | ||||
| { | { | ||||
| std::size_t invitedMemberCount; | std::size_t invitedMemberCount; | ||||
| }; | }; | ||||
| /// Update local notifications to include the new events | |||||
| /// | |||||
| /// Precondition: newEvents are already in room.messages | |||||
| struct AddLocalNotificationsAction | |||||
| { | |||||
| EventList newEvents; | |||||
| PushRulesDesc pushRulesDesc; | |||||
| std::string myUserId; | |||||
| }; | |||||
| /// Remove local notifications that are already read | |||||
| struct RemoveReadLocalNotificationsAction | |||||
| { | |||||
| std::string myUserId; | |||||
| }; | |||||
| inline bool operator==(const PendingRoomKeyEvent &a, const PendingRoomKeyEvent &b) | inline bool operator==(const PendingRoomKeyEvent &a, const PendingRoomKeyEvent &b) | ||||
| { | { | ||||
| return a.txnId == b.txnId && a.messages == b.messages; | return a.txnId == b.txnId && a.messages == b.messages; | ||||
| } | } | ||||
| inline bool operator!=(const PendingRoomKeyEvent &a, const PendingRoomKeyEvent &b) | inline bool operator!=(const PendingRoomKeyEvent &a, const PendingRoomKeyEvent &b) | ||||
| { | { | ||||
| return !(a == b); | return !(a == b); | ||||
| Show All 12 Lines | void serialize(Archive &ar, PendingRoomKeyEvent &e, std::uint32_t const version) | ||||
| ar & txnId & event & devices; | ar & txnId & event & devices; | ||||
| e = makePendingRoomKeyEventV0( | e = makePendingRoomKeyEventV0( | ||||
| std::move(txnId), std::move(event), std::move(devices)); | std::move(txnId), std::move(event), std::move(devices)); | ||||
| } else { | } else { | ||||
| ar & e.txnId & e.messages; | ar & e.txnId & e.messages; | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Get the sort key for a timeline event. | |||||
| * | |||||
| * If the key is larger, the event should be placed | |||||
| * at the more recent end of the timeline. | |||||
| * | |||||
| * @param e The event to get the sort key for. | |||||
| * @return The sort key. You MUST use `auto` to store the | |||||
| * result. | |||||
| */ | |||||
| auto sortKeyForTimelineEvent(Event e) -> std::tuple<Timestamp, std::string>; | |||||
| struct RoomModel | struct RoomModel | ||||
| { | { | ||||
| using Membership = RoomMembership; | using Membership = RoomMembership; | ||||
| using ReverseEventRelationshipMap = immer::map< | using ReverseEventRelationshipMap = immer::map< | ||||
| std::string /* related event id */, | std::string /* related event id */, | ||||
| immer::map<std::string /* relation type */, immer::flex_vector<std::string /* relater event id */>>>; | immer::map<std::string /* relation type */, immer::flex_vector<std::string /* relater event id */>>>; | ||||
| std::string roomId; | std::string roomId; | ||||
| Show All 35 Lines | struct RoomModel | ||||
| std::size_t invitedMemberCount{0}; | std::size_t invitedMemberCount{0}; | ||||
| /// The local read marker for this room. Indicates that | /// The local read marker for this room. Indicates that | ||||
| /// you have read up to this event. | /// you have read up to this event. | ||||
| std::string localReadMarker; | std::string localReadMarker; | ||||
| /// The local unread count for this room. | /// The local unread count for this room. | ||||
| std::size_t localUnreadCount{0}; | std::size_t localUnreadCount{0}; | ||||
| /// The local unread notification count for this room. | /// The local unread notification count for this room. | ||||
| /// XXX this is never used. | |||||
| std::size_t localNotificationCount{0}; | std::size_t localNotificationCount{0}; | ||||
| /// Read receipts for all users | /// Read receipts for all users | ||||
| immer::map<std::string /* userId */, ReadReceipt> readReceipts; | immer::map<std::string /* userId */, ReadReceipt> readReceipts; | ||||
| /// A map from event id to a list of users that has read | /// A map from event id to a list of users that has read | ||||
| /// receipt at that point | /// receipt at that point | ||||
| immer::map< | immer::map< | ||||
| std::string /* eventId */, | std::string /* eventId */, | ||||
| immer::flex_vector<std::string /* userId */>> eventReadUsers; | immer::flex_vector<std::string /* userId */>> eventReadUsers; | ||||
| /// A map from the session id to a list of event ids of events | /// A map from the session id to a list of event ids of events | ||||
| /// that cannot (yet) be decrypted. | /// that cannot (yet) be decrypted. | ||||
| immer::map< | immer::map< | ||||
| std::string /* sessionId */, | std::string /* sessionId */, | ||||
| immer::flex_vector<std::string /* eventId */>> undecryptedEvents; | immer::flex_vector<std::string /* eventId */>> undecryptedEvents; | ||||
| immer::flex_vector<std::string> unreadNotificationEventIds; | |||||
| immer::flex_vector<std::string> joinedMemberIds() const; | immer::flex_vector<std::string> joinedMemberIds() const; | ||||
| immer::flex_vector<std::string> invitedMemberIds() const; | immer::flex_vector<std::string> invitedMemberIds() const; | ||||
| immer::flex_vector<std::string> knockedMemberIds() const; | immer::flex_vector<std::string> knockedMemberIds() const; | ||||
| immer::flex_vector<std::string> leftMemberIds() const; | immer::flex_vector<std::string> leftMemberIds() const; | ||||
| immer::flex_vector<std::string> bannedMemberIds() const; | immer::flex_vector<std::string> bannedMemberIds() const; | ||||
| EventList joinedMemberEvents() const; | EventList joinedMemberEvents() const; | ||||
| EventList invitedMemberEvents() const; | EventList invitedMemberEvents() const; | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | struct RoomModel | ||||
| SetRoomEncryptionAction, | SetRoomEncryptionAction, | ||||
| MarkMembersFullyLoadedAction, | MarkMembersFullyLoadedAction, | ||||
| SetHeroIdsAction, | SetHeroIdsAction, | ||||
| AddLocalEchoAction, | AddLocalEchoAction, | ||||
| RemoveLocalEchoAction, | RemoveLocalEchoAction, | ||||
| AddPendingRoomKeyAction, | AddPendingRoomKeyAction, | ||||
| RemovePendingRoomKeyAction, | RemovePendingRoomKeyAction, | ||||
| UpdateJoinedMemberCountAction, | UpdateJoinedMemberCountAction, | ||||
| UpdateInvitedMemberCountAction | UpdateInvitedMemberCountAction, | ||||
| AddLocalNotificationsAction, | |||||
| RemoveReadLocalNotificationsAction | |||||
| >; | >; | ||||
| static RoomModel update(RoomModel r, Action a); | static RoomModel update(RoomModel r, Action a); | ||||
| }; | }; | ||||
| using RoomAction = RoomModel::Action; | using RoomAction = RoomModel::Action; | ||||
| inline bool operator==(const RoomModel &a, const RoomModel &b) | inline bool operator==(const RoomModel &a, const RoomModel &b) | ||||
| Show All 19 Lines | inline bool operator==(const RoomModel &a, const RoomModel &b) | ||||
| && a.reverseEventRelationships == b.reverseEventRelationships | && a.reverseEventRelationships == b.reverseEventRelationships | ||||
| && a.joinedMemberCount == b.joinedMemberCount | && a.joinedMemberCount == b.joinedMemberCount | ||||
| && a.localReadMarker == b.localReadMarker | && a.localReadMarker == b.localReadMarker | ||||
| && a.localUnreadCount == b.localUnreadCount | && a.localUnreadCount == b.localUnreadCount | ||||
| && a.localNotificationCount == b.localNotificationCount | && a.localNotificationCount == b.localNotificationCount | ||||
| && a.readReceipts == b.readReceipts | && a.readReceipts == b.readReceipts | ||||
| && a.eventReadUsers == b.eventReadUsers | && a.eventReadUsers == b.eventReadUsers | ||||
| && a.undecryptedEvents == b.undecryptedEvents | && a.undecryptedEvents == b.undecryptedEvents | ||||
| && a.unreadNotificationEventIds == b.unreadNotificationEventIds | |||||
| ; | ; | ||||
| } | } | ||||
| struct UpdateRoomAction | struct UpdateRoomAction | ||||
| { | { | ||||
| std::string roomId; | std::string roomId; | ||||
| RoomAction roomAction; | RoomAction roomAction; | ||||
| }; | }; | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | void serialize(Archive &ar, RoomModel &r, std::uint32_t const version) | ||||
| } | } | ||||
| if (version >= 7) { | if (version >= 7) { | ||||
| ar & r.undecryptedEvents; | ar & r.undecryptedEvents; | ||||
| } else { | } else { | ||||
| if constexpr (typename Archive::is_loading()) { | if constexpr (typename Archive::is_loading()) { | ||||
| r.recalculateUndecryptedEvents(); | r.recalculateUndecryptedEvents(); | ||||
| } | } | ||||
| } | } | ||||
| if (version >= 8) { | |||||
| ar & r.unreadNotificationEventIds; | |||||
| } | } | ||||
| } | |||||
| template<class Archive> | template<class Archive> | ||||
| void serialize(Archive &ar, RoomListModel &l, std::uint32_t const /*version*/) | void serialize(Archive &ar, RoomListModel &l, std::uint32_t const /*version*/) | ||||
| { | { | ||||
| ar & l.rooms; | ar & l.rooms; | ||||
| } | } | ||||
| } | } | ||||
| BOOST_CLASS_VERSION(Kazv::PendingRoomKeyEvent, 1) | BOOST_CLASS_VERSION(Kazv::PendingRoomKeyEvent, 1) | ||||
| BOOST_CLASS_VERSION(Kazv::ReadReceipt, 0) | BOOST_CLASS_VERSION(Kazv::ReadReceipt, 0) | ||||
| BOOST_CLASS_VERSION(Kazv::RoomModel, 7) | BOOST_CLASS_VERSION(Kazv::RoomModel, 8) | ||||
| BOOST_CLASS_VERSION(Kazv::RoomListModel, 0) | BOOST_CLASS_VERSION(Kazv::RoomListModel, 0) | ||||