File indexing completed on 2023-11-26 08:17:55

0001 /*
0002    SPDX-FileCopyrightText: 2017-2023 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "authenticationmanager.h"
0010 #include "libruqolacore_export.h"
0011 #include <QString>
0012 
0013 class LIBRUQOLACORE_EXPORT RuqolaServerConfig
0014 {
0015     Q_GADGET
0016 public:
0017     struct LIBRUQOLACORE_EXPORT ConfigWithDefaultValue {
0018         QString url;
0019         QString defaultUrl;
0020         [[nodiscard]] bool isEmpty() const
0021         {
0022             return url.isEmpty() || defaultUrl.isEmpty();
0023         }
0024         [[nodiscard]] bool operator==(const RuqolaServerConfig::ConfigWithDefaultValue &other) const;
0025     };
0026 
0027     RuqolaServerConfig();
0028 
0029     enum ServerConfigFeatureType {
0030         None = 0,
0031         AllowEditingMessage = 1,
0032         OtrEnabled = 2,
0033         // NeedAdaptNewSubscriptionRC60 = 4,
0034         EncryptionEnabled = 8,
0035         AllowMessagePinning = 0x10,
0036         AllowMessageStarring = 0x40,
0037         AllowMessageDeleting = 0x80,
0038         JitsiEnabled = 0x100,
0039         ThreadsEnabled = 0x200,
0040         DiscussionEnabled = 0x400,
0041         AutoTranslateEnabled = 0x800,
0042         UploadFileEnabled = 0x1000,
0043         BroadCastEnabled = 0x2000,
0044         VideoRecorderEnabled = 0x4000,
0045         AudioRecorderEnabled = 0x8000,
0046         AllowDeleteOwnAccount = 0x10000,
0047         RegistrationFromEnabled = 0x20000,
0048         AllowPasswordReset = 0x40000,
0049         AllowEmailChange = 0x80000,
0050         AllowPasswordChange = 0x100000,
0051         AllowUsernameChange = 0x200000,
0052         AllowUserProfileChange = 0x400000,
0053         AllowUserAvatarChange = 0x800000,
0054         LdapEnabled = 0x1000000,
0055         JitsiEnabledTeams = 0x2000000,
0056         JitsiEnabledChannels = 0x4000000,
0057         TwoFactorAuthenticationEnabled = 0x8000000,
0058         TwoFactorAuthenticationByEmailEnabled = 0x10000000,
0059         TwoFactorAuthenticationByTOTPEnabled = 0x20000000,
0060         TwoFactorAuthenticationEnforcePasswordFallback = 0x40000000,
0061     };
0062     Q_DECLARE_FLAGS(ServerConfigFeatureTypes, ServerConfigFeatureType)
0063     Q_FLAG(ServerConfigFeatureTypes)
0064 
0065     [[nodiscard]] QString uniqueId() const;
0066     void setUniqueId(const QString &uniqueId);
0067 
0068     [[nodiscard]] QString jitsiMeetUrl() const;
0069     void setJitsiMeetUrl(const QString &jitsiMeetUrl);
0070 
0071     [[nodiscard]] QString jitsiMeetPrefix() const;
0072     void setJitsiMeetPrefix(const QString &jitsiMeetPrefix);
0073 
0074     [[nodiscard]] QString fileUploadStorageType() const;
0075     void setFileUploadStorageType(const QString &type);
0076 
0077     void setBlockEditingMessageInMinutes(int minutes);
0078     [[nodiscard]] int blockEditingMessageInMinutes() const;
0079 
0080     void setBlockDeletingMessageInMinutes(int minutes);
0081     [[nodiscard]] int blockDeletingMessageInMinutes() const;
0082 
0083     [[nodiscard]] bool needAdaptNewSubscriptionRC60() const;
0084 
0085     void setServerVersion(const QString &version);
0086     [[nodiscard]] QString serverVersion() const;
0087 
0088     void addOauthService(const QString &service);
0089 
0090     [[nodiscard]] AuthenticationManager::OauthTypes serverOauthTypes() const;
0091 
0092     [[nodiscard]] bool serverHasSupportForOauthType(AuthenticationManager::OauthType type) const;
0093 
0094     [[nodiscard]] bool ruqolaHasSupportForOauthType(AuthenticationManager::OauthType type) const;
0095     [[nodiscard]] bool canShowOauthService(AuthenticationManager::OauthType type) const;
0096     void addRuqolaAuthenticationSupport(AuthenticationManager::OauthType type);
0097     [[nodiscard]] AuthenticationManager::OauthTypes ruqolaOauthTypes() const;
0098 
0099     [[nodiscard]] QString siteUrl() const;
0100     void setSiteUrl(const QString &siteUrl);
0101 
0102     [[nodiscard]] QString siteName() const;
0103     void setSiteName(const QString &siteName);
0104 
0105     [[nodiscard]] bool hasAtLeastVersion(int major, int minor, int patch) const;
0106 
0107     [[nodiscard]] QString serverVersionStr() const;
0108 
0109     [[nodiscard]] int serverVersionMajor() const;
0110 
0111     [[nodiscard]] int serverVersionMinor() const;
0112 
0113     [[nodiscard]] int serverVersionPatch() const;
0114 
0115     [[nodiscard]] QString autoTranslateGoogleKey() const;
0116     void setAutoTranslateGoogleKey(const QString &autoTranslateGoogleKey);
0117 
0118     void parsePublicSettings(const QJsonObject &obj, bool update);
0119 
0120     [[nodiscard]] qint64 fileMaxFileSize() const;
0121     void setFileMaxFileSize(qint64 fileMaxFileSize);
0122 
0123     [[nodiscard]] RuqolaServerConfig::ConfigWithDefaultValue logoUrl() const;
0124     void setLogoUrl(const ConfigWithDefaultValue &logoUrl);
0125 
0126     [[nodiscard]] RuqolaServerConfig::ConfigWithDefaultValue faviconUrl() const;
0127     void setFaviconUrl(const RuqolaServerConfig::ConfigWithDefaultValue &faviconUrl);
0128 
0129     void setAllowRegistrationFrom(const QString &registrationFromValue);
0130 
0131     [[nodiscard]] RuqolaServerConfig::ServerConfigFeatureTypes serverConfigFeatureTypes() const;
0132     void setServerConfigFeatureTypes(ServerConfigFeatureTypes serverConfigFeatureTypes);
0133 
0134     [[nodiscard]] int loginExpiration() const;
0135     void setLoginExpiration(int loginExpiration);
0136 
0137     void setUserNameValidation(const QString &str);
0138     [[nodiscard]] const QString &userNameValidation() const;
0139 
0140     void setChannelNameValidation(const QString &str);
0141     [[nodiscard]] const QString &channelNameValidation() const;
0142 
0143     [[nodiscard]] int messageMaximumAllowedSize() const;
0144     void setMessageMaximumAllowedSize(int newMessageMaximumAllowedSize);
0145 
0146     [[nodiscard]] bool messageAllowConvertLongMessagesToAttachment() const;
0147     void setMessageAllowConvertLongMessagesToAttachment(bool newMessageAllowConvertLongMessagesToAttachment);
0148 
0149     void privateSettingsUpdated(const QJsonArray &replyArray);
0150 
0151     [[nodiscard]] bool useRealName() const;
0152     void setUseRealName(bool newUIUseRealName);
0153 
0154     [[nodiscard]] bool hasEnterpriseSupport() const;
0155     void setHasEnterpriseSupport(bool newHasEnterpriseSupport);
0156 
0157     [[nodiscard]] bool accountsAllowInvisibleStatusOption() const;
0158     void setAccountsAllowInvisibleStatusOption(bool newAccountsAllowInvisibleStatusOption);
0159 
0160     [[nodiscard]] bool userDataDownloadEnabled() const;
0161     void setUserDataDownloadEnabled(bool newUserDataDownloadEnabled);
0162 
0163     [[nodiscard]] bool deviceManagementEnableLoginEmails() const;
0164     void setDeviceManagementEnableLoginEmails(bool newDeviceManagementEnableLoginEmails);
0165 
0166     [[nodiscard]] bool deviceManagementAllowLoginEmailpreference() const;
0167     void setDeviceManagementAllowLoginEmailpreference(bool newDeviceManagementAllowLoginEmailpreference);
0168 
0169     [[nodiscard]] int messageGroupingPeriod() const;
0170     void setMessageGroupingPeriod(int newMessageGroupingPeriod);
0171 
0172     [[nodiscard]] int directMessageMaximumUser() const;
0173     void setDirectMessageMaximumUser(int newDirectMessageMaximumUser);
0174 
0175     [[nodiscard]] int messageQuoteChainLimit() const;
0176     void setMessageQuoteChainLimit(int newMessageQuoteChainLimit);
0177 
0178     [[nodiscard]] bool allowCustomStatusMessage() const;
0179     void setAllowCustomStatusMessage(bool newAllowCustomStatusMessage);
0180 
0181     [[nodiscard]] QStringList mediaWhiteList() const;
0182     void setMediaWhiteList(const QStringList &newMediaWhiteList);
0183 
0184     [[nodiscard]] QStringList mediaBlackList() const;
0185     void setMediaBlackList(const QStringList &newMediaBlackList);
0186 
0187     [[nodiscard]] QByteArray serialize(bool toBinary = true);
0188 
0189     void deserialize(const QJsonObject &source);
0190 
0191     [[nodiscard]] bool operator==(const RuqolaServerConfig &other) const;
0192 
0193     void loadAccountSettingsFromLocalDataBase(const QByteArray &ba);
0194 
0195 private:
0196     Q_DISABLE_COPY(RuqolaServerConfig)
0197     LIBRUQOLACORE_NO_EXPORT void adaptToServerVersion();
0198     LIBRUQOLACORE_NO_EXPORT void assignSettingValue(bool value, ServerConfigFeatureType type);
0199     LIBRUQOLACORE_NO_EXPORT void loadSettings(const QJsonObject &currentConfObject);
0200     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QJsonObject createJsonObject(const QString &identifier, const QString &value);
0201     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QJsonObject createJsonObject(const QString &identifier, bool value);
0202     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QJsonObject createJsonObject(const QString &identifier, int value);
0203     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QJsonObject createJsonObject(const QString &identifier, qint64 value);
0204     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QJsonObject createJsonObject(const QString &identifier,
0205                                                                               const RuqolaServerConfig::ConfigWithDefaultValue &value);
0206     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static RuqolaServerConfig::ConfigWithDefaultValue parseConfigWithDefaultValue(const QJsonObject &o);
0207 
0208     QString mUniqueId;
0209     QString mJitsiMeetUrl;
0210     QString mJitsiMeetPrefix;
0211     QString mFileUploadStorageType;
0212     QString mSiteUrl;
0213     QString mSiteName;
0214     QString mServerVersionStr;
0215     QString mAutoTranslateGoogleKey;
0216     QString mChannelNameValidation;
0217     QString mUserNameValidation;
0218     AuthenticationManager::OauthTypes mServerOauthTypes = AuthenticationManager::OauthType::Password;
0219     AuthenticationManager::OauthTypes mRuqolaOauthTypes = AuthenticationManager::OauthType::Password;
0220     int mBlockEditingMessageInMinutes = 5;
0221     int mBlockDeletingMessageInMinutes = 5;
0222     int mServerVersionMajor = -1;
0223     int mServerVersionMinor = -1;
0224     int mServerVersionPatch = -1;
0225     qint64 mFileMaxFileSize = -1;
0226 
0227     bool mNeedAdaptNewSubscriptionRC60 = false;
0228     bool mMessageAllowConvertLongMessagesToAttachment = false;
0229     bool mUIUseRealName = false;
0230 
0231     ServerConfigFeatureTypes mServerConfigFeatureTypes = ServerConfigFeatureType::None;
0232 
0233     QStringList mMediaWhiteList;
0234     QStringList mMediaBlackList;
0235 
0236     ConfigWithDefaultValue mLogoUrl;
0237     ConfigWithDefaultValue mFaviconUrl;
0238     int mLoginExpiration = -1;
0239     int mMessageMaximumAllowedSize = -1;
0240     int mMessageGroupingPeriod = -1;
0241     int mDirectMessageMaximumUser = -1;
0242     int mMessageQuoteChainLimit = -1;
0243 
0244     bool mHasEnterpriseSupport = false;
0245     bool mAccountsAllowInvisibleStatusOption = true; // Default true
0246     bool mUserDataDownloadEnabled = true;
0247     bool mDeviceManagementEnableLoginEmails = false;
0248     bool mDeviceManagementAllowLoginEmailpreference = false;
0249     bool mAllowCustomStatusMessage = false;
0250 };
0251 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const RuqolaServerConfig &t);
0252 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const RuqolaServerConfig::ConfigWithDefaultValue &t);