aboutsummaryrefslogtreecommitdiff
path: root/lib/quotient_common.h
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-07-16 20:03:06 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-07-18 20:09:43 +0200
commitc05b5c2b79f9ab301fee587ee781b9c8e18b8a2f (patch)
tree95de5d26893652593fdf0a583378c31795a0d432 /lib/quotient_common.h
parent110190d48a80a471e6d10d048602390b35e7ed07 (diff)
downloadlibquotient-c05b5c2b79f9ab301fee587ee781b9c8e18b8a2f.tar.gz
libquotient-c05b5c2b79f9ab301fee587ee781b9c8e18b8a2f.zip
MembershipType -> Membership, also used for JoinState
Instead of being defined independently, JoinState now uses values from the Membership enumeration (former MemberEventContent::MembershipType) that was moved to quotient_common.h for that purpose. Both enumerations gained a Q_FLAG_NS decoration and operator<< overrides that strip "Quotient::" prefix when dumping member/join state values to the log - obviating toCString(JoinState) along the way. Quotient::MembershipType alias is deprecated from now.
Diffstat (limited to 'lib/quotient_common.h')
-rw-r--r--lib/quotient_common.h67
1 files changed, 60 insertions, 7 deletions
diff --git a/lib/quotient_common.h b/lib/quotient_common.h
index 22fdbe94..789128cf 100644
--- a/lib/quotient_common.h
+++ b/lib/quotient_common.h
@@ -8,15 +8,62 @@
namespace Quotient {
Q_NAMESPACE
-/** Enumeration with flags defining the network job running policy
- * So far only background/foreground flags are available.
- *
- * \sa Connection::callApi, Connection::run
- */
+// TODO: code like this should be generated from the CS API definition
+
+//! \brief Membership states
+//!
+//! These are used for member events. The names here are case-insensitively
+//! equal to state names used on the wire.
+//! \sa MemberEventContent, RoomMemberEvent
+enum class Membership : unsigned int {
+ // Specific power-of-2 values (1,2,4,...) are important here as syncdata.cpp
+ // depends on that, as well as Join being the first in line
+ Invalid = 0x0,
+ Join = 0x1,
+ Leave = 0x2,
+ Invite = 0x4,
+ Knock = 0x8,
+ Ban = 0x10,
+ Undefined = Invalid
+};
+Q_DECLARE_FLAGS(MembershipMask, Membership)
+Q_FLAG_NS(MembershipMask)
+
+constexpr inline std::array MembershipStrings = {
+ // The order MUST be the same as the order in the original enum
+ "join", "leave", "invite", "knock", "ban"
+};
+
+//! \brief Local user join-state names
+//!
+//! This represents a subset of Membership values that may arrive as the local
+//! user's state grouping for the sync response.
+//! \sa SyncData
+enum class JoinState : std::underlying_type_t<Membership> {
+ Invalid = std::underlying_type_t<Membership>(Membership::Invalid),
+ Join = std::underlying_type_t<Membership>(Membership::Join),
+ Leave = std::underlying_type_t<Membership>(Membership::Leave),
+ Invite = std::underlying_type_t<Membership>(Membership::Invite),
+ Knock = std::underlying_type_t<Membership>(Membership::Knock),
+};
+Q_DECLARE_FLAGS(JoinStates, JoinState)
+Q_FLAG_NS(JoinStates)
+
+constexpr inline std::array JoinStateStrings {
+ MembershipStrings[0], MembershipStrings[1], MembershipStrings[2],
+ MembershipStrings[3] /* same as MembershipStrings, sans "ban" */
+};
+
+//! \brief Network job running policy flags
+//!
+//! So far only background/foreground flags are available.
+//! \sa Connection::callApi, Connection::run
enum RunningPolicy { ForegroundRequest = 0x0, BackgroundRequest = 0x1 };
Q_ENUM_NS(RunningPolicy)
+//! \brief The result of URI resolution using UriResolver
+//! \sa UriResolver
enum UriResolveResult : short {
StillResolving = -1,
UriResolved = 0,
@@ -28,5 +75,11 @@ enum UriResolveResult : short {
Q_ENUM_NS(UriResolveResult)
} // namespace Quotient
-/// \deprecated Use namespace Quotient instead
-namespace QMatrixClient = Quotient;
+Q_DECLARE_OPERATORS_FOR_FLAGS(Quotient::MembershipMask)
+Q_DECLARE_OPERATORS_FOR_FLAGS(Quotient::JoinStates)
+
+class QDebug;
+QDebug operator<<(QDebug dbg, Quotient::Membership m);
+QDebug operator<<(QDebug dbg, Quotient::MembershipMask m);
+QDebug operator<<(QDebug dbg, Quotient::JoinState js);
+QDebug operator<<(QDebug dbg, Quotient::JoinStates js);