File indexing completed on 2024-12-08 10:25:55
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 "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 RegistrationFormEnabled = 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::AuthMethodTypes serverAuthMethodTypes() const; 0091 0092 [[nodiscard]] bool serverHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType type) const; 0093 0094 [[nodiscard]] bool ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType type) const; 0095 [[nodiscard]] bool canShowAuthMethod(AuthenticationManager::AuthMethodType type) const; 0096 void addRuqolaAuthenticationSupport(AuthenticationManager::AuthMethodType type); 0097 [[nodiscard]] AuthenticationManager::AuthMethodTypes 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 ®istrationFromValue); 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 [[nodiscard]] bool previewEmbed() const; 0196 void setPreviewEmbed(bool newPreviewEmbed); 0197 0198 [[nodiscard]] int embedCacheExpirationDays() const; 0199 void setEmbedCacheExpirationDays(int newEmbedCacheExpirationDays); 0200 0201 private: 0202 Q_DISABLE_COPY(RuqolaServerConfig) 0203 LIBRUQOLACORE_NO_EXPORT void adaptToServerVersion(); 0204 LIBRUQOLACORE_NO_EXPORT void assignSettingValue(bool value, ServerConfigFeatureType type); 0205 LIBRUQOLACORE_NO_EXPORT void loadSettings(const QJsonObject ¤tConfObject); 0206 [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QJsonObject createJsonObject(const QString &identifier, const QString &value); 0207 [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QJsonObject createJsonObject(const QString &identifier, bool value); 0208 [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QJsonObject createJsonObject(const QString &identifier, int value); 0209 [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QJsonObject createJsonObject(const QString &identifier, qint64 value); 0210 [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QJsonObject createJsonObject(const QString &identifier, 0211 const RuqolaServerConfig::ConfigWithDefaultValue &value); 0212 [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static RuqolaServerConfig::ConfigWithDefaultValue parseConfigWithDefaultValue(const QJsonObject &o); 0213 0214 QString mUniqueId; 0215 QString mJitsiMeetUrl; 0216 QString mJitsiMeetPrefix; 0217 QString mFileUploadStorageType; 0218 QString mSiteUrl; 0219 QString mSiteName; 0220 QString mServerVersionStr; 0221 QString mAutoTranslateGoogleKey; 0222 QString mChannelNameValidation; 0223 QString mUserNameValidation; 0224 AuthenticationManager::AuthMethodTypes mServerAuthTypes = AuthenticationManager::AuthMethodType::Unknown; 0225 AuthenticationManager::AuthMethodTypes mRuqolaAuthMethodTypes = AuthenticationManager::AuthMethodType::Unknown; 0226 int mBlockEditingMessageInMinutes = 5; 0227 int mBlockDeletingMessageInMinutes = 5; 0228 int mServerVersionMajor = -1; 0229 int mServerVersionMinor = -1; 0230 int mServerVersionPatch = -1; 0231 qint64 mFileMaxFileSize = -1; 0232 0233 bool mNeedAdaptNewSubscriptionRC60 = false; 0234 bool mMessageAllowConvertLongMessagesToAttachment = false; 0235 bool mUIUseRealName = false; 0236 0237 ServerConfigFeatureTypes mServerConfigFeatureTypes = ServerConfigFeatureType::None; 0238 0239 QStringList mMediaWhiteList; 0240 QStringList mMediaBlackList; 0241 0242 ConfigWithDefaultValue mLogoUrl; 0243 ConfigWithDefaultValue mFaviconUrl; 0244 int mLoginExpiration = -1; 0245 int mMessageMaximumAllowedSize = -1; 0246 int mMessageGroupingPeriod = -1; 0247 int mDirectMessageMaximumUser = -1; 0248 int mMessageQuoteChainLimit = -1; 0249 int mEmbedCacheExpirationDays = 30; // Default value in RC 0250 0251 bool mHasEnterpriseSupport = false; 0252 bool mAccountsAllowInvisibleStatusOption = true; // Default true 0253 bool mUserDataDownloadEnabled = true; 0254 bool mDeviceManagementEnableLoginEmails = false; 0255 bool mDeviceManagementAllowLoginEmailpreference = false; 0256 bool mAllowCustomStatusMessage = false; 0257 bool mPreviewEmbed = false; 0258 }; 0259 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const RuqolaServerConfig &t); 0260 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const RuqolaServerConfig::ConfigWithDefaultValue &t);