File indexing completed on 2024-12-01 07:41:21
0001 /* 0002 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "libruqolacore_export.h" 0010 #include "roles/roleinfo.h" 0011 #include <QDateTime> 0012 #include <QDebug> 0013 #include <QString> 0014 0015 class LIBRUQOLACORE_EXPORT User 0016 { 0017 Q_GADGET 0018 public: 0019 enum class PresenceStatus { 0020 PresenceOnline, 0021 PresenceBusy, 0022 PresenceAway, 0023 PresenceOffline, 0024 Unknown, 0025 }; 0026 Q_ENUM(PresenceStatus) 0027 0028 struct LIBRUQOLACORE_EXPORT UserEmailsInfo { 0029 QString email; 0030 bool verified = false; 0031 [[nodiscard]] bool operator==(const UserEmailsInfo &other) const 0032 { 0033 return (email == other.email) && (verified == other.verified); 0034 } 0035 0036 [[nodiscard]] bool isValid() const 0037 { 0038 return !email.isEmpty(); 0039 } 0040 }; 0041 0042 User(); 0043 ~User(); 0044 0045 [[nodiscard]] QString name() const; 0046 void setName(const QString &name); 0047 0048 [[nodiscard]] QString userId() const; 0049 void setUserId(const QString &userId); 0050 0051 [[nodiscard]] User::PresenceStatus status() const; 0052 void setStatus(User::PresenceStatus status); 0053 0054 void parseUser(const QJsonObject &json); 0055 [[nodiscard]] QString iconFromStatus() const; 0056 0057 [[nodiscard]] bool operator==(const User &other) const; 0058 [[nodiscard]] bool operator!=(const User &other) const; 0059 0060 [[nodiscard]] QString userName() const; 0061 void setUserName(const QString &userName); 0062 0063 [[nodiscard]] bool isValid() const; 0064 0065 [[nodiscard]] double utcOffset() const; 0066 void setUtcOffset(double utcOffset); 0067 0068 [[nodiscard]] QString statusText() const; 0069 void setStatusText(const QString &statusText); 0070 0071 void parseUserRestApi(const QJsonObject &object, const QVector<RoleInfo> &roleInfo); 0072 0073 [[nodiscard]] static QVector<User> parseUsersList(const QJsonObject &object, const QVector<RoleInfo> &roleInfo); 0074 void parseUser(const QVariantList &list); 0075 0076 [[nodiscard]] QStringList roles() const; 0077 void setRoles(const QStringList &roles, const QVector<RoleInfo> &roleInfo); 0078 0079 [[nodiscard]] QDateTime createdAt() const; 0080 void setCreatedAt(const QDateTime &createdAt); 0081 0082 [[nodiscard]] QDateTime lastLogin() const; 0083 void setLastLogin(const QDateTime &lastLogin); 0084 0085 [[nodiscard]] UserEmailsInfo userEmailsInfo() const; 0086 void setUserEmailsInfo(const UserEmailsInfo &userEmailsInfo); 0087 0088 [[nodiscard]] QStringList i18nRoles() const; 0089 0090 [[nodiscard]] bool active() const; 0091 void setActive(bool newActive); 0092 0093 [[nodiscard]] QString generateStatusStr() const; 0094 0095 [[nodiscard]] bool requirePasswordChange() const; 0096 void setRequirePasswordChange(bool newRequirePasswordChange); 0097 0098 [[nodiscard]] static QString roleI18n(const QString &roleStr, const QVector<RoleInfo> &roleInfo); 0099 0100 [[nodiscard]] QString bio() const; 0101 void setBio(const QString &newBio); 0102 0103 static QJsonObject serialize(const User &user); 0104 static User deserialize(const QJsonObject &o); 0105 0106 [[nodiscard]] QString nickName() const; 0107 void setNickName(const QString &newNickName); 0108 0109 private: 0110 UserEmailsInfo mUserEmailsInfo; 0111 QDateTime mCreatedAt; 0112 QDateTime mLastLogin; 0113 0114 PresenceStatus mStatus = PresenceStatus::PresenceOffline; 0115 QString mUserId; 0116 QString mName; 0117 QString mUserName; 0118 QString mStatusText; 0119 QString mBio; 0120 QString mNickName; 0121 QStringList mRoles; 0122 QStringList mI18nRoles; 0123 double mUtcOffset = 0.0; 0124 bool mActive = true; 0125 bool mRequirePasswordChange = false; 0126 }; 0127 Q_DECLARE_METATYPE(User) 0128 Q_DECLARE_TYPEINFO(User, Q_RELOCATABLE_TYPE); 0129 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const User &t); 0130 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const User::UserEmailsInfo &t);