File indexing completed on 2024-05-12 09:02:19
0001 // SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include <QObject> 0007 #include <QQmlEngine> 0008 0009 #include <QCoroTask> 0010 #include <Quotient/connection.h> 0011 0012 class NeoChatConnection : public Quotient::Connection 0013 { 0014 Q_OBJECT 0015 QML_ELEMENT 0016 QML_UNCREATABLE("") 0017 0018 /** 0019 * @brief The account label for this account. 0020 * 0021 * Account labels are a concept specific to NeoChat, allowing accounts to be 0022 * labelled, e.g. for "Work", "Private", etc. 0023 * 0024 * Set to an empty string to remove the label. 0025 */ 0026 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) 0027 Q_PROPERTY(QString deviceKey READ deviceKey CONSTANT) 0028 Q_PROPERTY(QString encryptionKey READ encryptionKey CONSTANT) 0029 0030 /** 0031 * @brief Whether NeoChat is currently able to connect to the server. 0032 */ 0033 Q_PROPERTY(bool isOnline READ isOnline WRITE setIsOnline NOTIFY isOnlineChanged) 0034 0035 public: 0036 /** 0037 * @brief Defines the status after an attempt to change the password on an account. 0038 */ 0039 enum PasswordStatus { 0040 Success, /**< The password was successfully changed. */ 0041 Wrong, /**< The current password entered was wrong. */ 0042 Other, /**< An unknown problem occurred. */ 0043 }; 0044 Q_ENUM(PasswordStatus) 0045 0046 NeoChatConnection(QObject *parent = nullptr); 0047 NeoChatConnection(const QUrl &server, QObject *parent = nullptr); 0048 0049 Q_INVOKABLE void logout(bool serverSideLogout); 0050 Q_INVOKABLE QVariantList getSupportedRoomVersions() const; 0051 0052 /** 0053 * @brief Change the password for an account. 0054 * 0055 * The function emits a passwordStatus signal with a PasswordStatus value when 0056 * complete. 0057 * 0058 * @sa PasswordStatus, passwordStatus 0059 */ 0060 Q_INVOKABLE void changePassword(const QString ¤tPassword, const QString &newPassword); 0061 0062 /** 0063 * @brief Change the avatar for an account. 0064 */ 0065 Q_INVOKABLE bool setAvatar(const QUrl &avatarSource); 0066 0067 [[nodiscard]] QString label() const; 0068 void setLabel(const QString &label); 0069 0070 Q_INVOKABLE void deactivateAccount(const QString &password); 0071 0072 /** 0073 * @brief Create new room for a group chat. 0074 */ 0075 Q_INVOKABLE void createRoom(const QString &name, const QString &topic, const QString &parent = {}, bool setChildParent = false); 0076 0077 /** 0078 * @brief Create new space. 0079 */ 0080 Q_INVOKABLE void createSpace(const QString &name, const QString &topic, const QString &parent = {}, bool setChildParent = false); 0081 0082 /** 0083 * @brief Join a direct chat with the given user. 0084 * 0085 * If a direct chat with the user doesn't exist one is created and then joined. 0086 */ 0087 Q_INVOKABLE void openOrCreateDirectChat(Quotient::User *user); 0088 0089 // note: this is intentionally a copied QString because 0090 // the reference could be destroyed before the task is finished 0091 QCoro::Task<void> setupPushNotifications(QString endpoint); 0092 0093 QString deviceKey() const; 0094 QString encryptionKey() const; 0095 0096 bool isOnline() const; 0097 0098 Q_SIGNALS: 0099 void labelChanged(); 0100 void isOnlineChanged(); 0101 void passwordStatus(NeoChatConnection::PasswordStatus status); 0102 void userConsentRequired(QUrl url); 0103 0104 private: 0105 bool m_isOnline = true; 0106 void setIsOnline(bool isOnline); 0107 };