libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
eventstats.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021 Quotient contributors
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include "room.h"
7
8namespace Quotient {
9
10//! \brief Counters of unread events and highlights with a precision flag
11//!
12//! This structure contains a static snapshot with values of unread counters
13//! returned by Room::partiallyReadStats and Room::unreadStats (properties
14//! or methods).
15//!
16//! \note It's just a simple grouping of counters and is not automatically
17//! updated from the room as subsequent syncs arrive.
18//! \sa Room::unreadStats, Room::partiallyReadStats, Room::isEventNotable
23
27public:
28 //! The number of "notable" events in an events range
29 //! \sa Room::isEventNotable
32 //! \brief Whether the counter values above are exact
33 //!
34 //! This is false when the end marker (m.read receipt or m.fully_read) used
35 //! to collect the stats points to an event loaded locally and the counters
36 //! can therefore be calculated exactly using the locally available segment
37 //! of the timeline; true when the marker points to an event outside of
38 //! the local timeline (in which case the estimation is made basing on
39 //! the data supplied by the homeserver as well as counters saved from
40 //! the previous run of the client).
41 bool isEstimate = true;
42
43 // TODO: replace with = default once C++20 becomes a requirement on clients
44 bool operator==(const EventStats& rhs) const
45 {
49 }
50 bool operator!=(const EventStats& rhs) const { return !operator==(rhs); }
51
52 //! \brief Check whether the event statistics are empty
53 //!
54 //! Empty statistics have notable and highlight counters of zero and
55 //! isEstimate set to false.
56 Q_INVOKABLE bool empty() const
57 {
58 return notableCount == 0 && !isEstimate && highlightCount == 0;
59 }
60
62
63 //! \brief Build event statistics on a range of events
64 //!
65 //! This is a factory that returns an EventStats instance with counts of
66 //! notable and highlighted events between \p from and \p to reverse
67 //! timeline iterators; the \p init parameter allows to override
68 //! the initial statistics object and start from other values.
69 static EventStats fromRange(const Room* room, const marker_t& from,
70 const marker_t& to,
71 const EventStats& init = { 0, 0, false });
72
73 //! \brief Build event statistics on a range from sync edge to marker
74 //!
75 //! This is mainly a shortcut for \code
76 //! <tt>fromRange(room, marker_t(room->syncEdge()), marker)</tt>
77 //! \endcode except that it also sets isEstimate to true if (and only if)
78 //! <tt>to == room->historyEdge()</tt>.
79 static EventStats fromMarker(const Room* room, const marker_t& marker);
80
81 //! \brief Loads a statistics object from the cached counters
82 //!
83 //! Sets isEstimate to `true` unless both notableCount and highlightCount
84 //! are equal to -1.
86 std::optional<int> highlightCount = {});
87
88 //! \brief Update statistics when a read marker moves down the timeline
89 //!
90 //! Removes events between oldMarker and newMarker from statistics
91 //! calculation if \p oldMarker points to an existing event in the timeline,
92 //! or recalculates the statistics entirely if \p oldMarker points
93 //! to <tt>room->historyEdge()</tt>. Always results in exact statistics
94 //! (<tt>isEstimate == false</tt>.
95 //! \param oldMarker Must point correspond to the _current_ statistics
96 //! isEstimate state, i.e. it should point to
97 //! <tt>room->historyEdge()</tt> if <tt>isEstimate == true</tt>, or
98 //! to a valid position within the timeline otherwise
99 //! \param newMarker Must point to a valid position in the timeline (not to
100 //! <tt>room->historyEdge()</tt> that is equal to or closer to
101 //! the sync edge than \p oldMarker
102 //! \return true if either notableCount or highlightCount changed, or if
103 //! the statistics was completely recalculated; false otherwise
105 const marker_t& newMarker);
106
107 //! \brief Validate the statistics object against the given marker
108 //!
109 //! Checks whether the statistics object data are valid for a given marker.
110 //! No stats recalculation takes place, only isEstimate and zero-ness
111 //! of notableCount are checked.
112 bool isValidFor(const Room* room, const marker_t& marker) const;
113};
114
116
117}
QUOTIENT_API QDebug operator<<(QDebug dbg, const EventStats &es)
#define QUOTIENT_API
Counters of unread events and highlights with a precision flag.
Definition eventstats.h:19