Warning, file /network/tokodon/src/admin/accounttoolmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // SPDX-FileCopyrightText: 2023 Rishi Kumar <rsi.dev17@gmail.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #pragma once
0005 
0006 #include "account/abstractaccount.h"
0007 #include "account/identity.h"
0008 #include <QAbstractListModel>
0009 #include <QUrl>
0010 #include <QUrlQuery>
0011 #include <memory>
0012 
0013 class AdminAccountInfo;
0014 
0015 class AccountsToolModel : public QAbstractListModel
0016 {
0017     Q_OBJECT
0018     Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
0019     /// This property holds the "Location" value of account tool.
0020     Q_PROPERTY(QString location READ location WRITE setLocation NOTIFY locationChanged)
0021     /// This property holds the "moderation Status" value of account tool.
0022     Q_PROPERTY(QString moderationStatus READ moderationStatus WRITE setModerationStatus NOTIFY moderationStatusChanged)
0023     /// This property holds the "Role" value of account tool.
0024     Q_PROPERTY(QString role READ role WRITE setRole NOTIFY roleChanged)
0025     /// This property holds the "username" value of account tool.
0026     Q_PROPERTY(QString username READ username WRITE setUsername NOTIFY usernameChanged)
0027     /// This property holds the "displayName" value of account tool.
0028     Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged)
0029     /// This property holds the "email" value of account tool.
0030     Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
0031     /// This property holds the "ip" value of account tool.
0032     Q_PROPERTY(QString ip READ ip WRITE setIp NOTIFY ipChanged)
0033     /// This property holds the position value of the current account which is logged in
0034     Q_PROPERTY(int selectedAccountPosition READ selectedAccountPosition CONSTANT)
0035 
0036 public:
0037     enum CustomRoles {
0038         IdentityRole = Qt::UserRole + 1,
0039     };
0040 
0041     // think about delete implementation
0042     enum AdminAccountAction {
0043         ApproveAccount,
0044         RejectAccount,
0045         ActionAgainstAccount,
0046         EnableDisabledAccount,
0047         UnsilenceAccount,
0048         UnsuspendAccount,
0049         UnmarkSensitiveAccount,
0050     };
0051 
0052     explicit AccountsToolModel(QObject *parent = nullptr);
0053 
0054     QVariant data(const QModelIndex &index, int role) const override;
0055     int rowCount(const QModelIndex &parent) const override;
0056     QHash<int, QByteArray> roleNames() const override;
0057 
0058     bool loading() const;
0059     void setLoading(bool loading);
0060 
0061     QUrlQuery buildQuery() const;
0062 
0063     // location
0064     QString location() const;
0065     void setLocation(const QString &location);
0066 
0067     // moderation status
0068     QString moderationStatus() const;
0069     void setModerationStatus(const QString &moderationStatus);
0070 
0071     // role
0072     QString role() const;
0073     void setRole(const QString &role);
0074 
0075     // UserName
0076     QString username() const;
0077     void setUsername(const QString &username);
0078 
0079     // displayName
0080     QString displayName() const;
0081     void setDisplayName(const QString &displayName);
0082 
0083     // email
0084     QString email() const;
0085     void setEmail(const QString &email);
0086 
0087     // ip
0088     QString ip() const;
0089     void setIp(const QString &role);
0090 
0091     int selectedAccountPosition() const;
0092 
0093     // clearing and relaoding the model
0094     void clear();
0095     // delete account data
0096     Q_INVOKABLE void deleteAccountData(const int row);
0097 
0098     Q_INVOKABLE void approveAccount(const int row);
0099     Q_INVOKABLE void rejectAccount(const int row);
0100     Q_INVOKABLE void enableAccount(const int row);
0101     Q_INVOKABLE void unsilenceAccount(const int row);
0102     Q_INVOKABLE void unsuspendAccount(const int row);
0103     Q_INVOKABLE void unsensitiveAccount(const int row);
0104     Q_INVOKABLE void actionAgainstAccount(const int row, const QString &type, const bool &emailWarning, const QString &note);
0105 
0106 Q_SIGNALS:
0107     void loadingChanged();
0108     void locationChanged();
0109     void moderationStatusChanged();
0110     void roleChanged();
0111     void usernameChanged();
0112     void displayNameChanged();
0113     void emailChanged();
0114     void ipChanged();
0115 
0116 protected:
0117     void fetchSelectedAccountPosition();
0118     void fetchMore(const QModelIndex &parent) override;
0119     bool canFetchMore(const QModelIndex &parent) const override;
0120     void executeAdminAction(const int row, AdminAccountAction accountAction, const QJsonObject &extraArguments = {});
0121 
0122 private:
0123     void fillTimeline();
0124 
0125     QList<std::shared_ptr<AdminAccountInfo>> m_accounts;
0126     bool m_loading = false;
0127     bool m_pagination = true;
0128 
0129     QString m_username;
0130     QString m_displayName;
0131     QString m_email;
0132     QString m_ip;
0133     QString m_location;
0134     QString m_moderationStatus;
0135     QString m_role;
0136     QUrl m_next;
0137     int m_selectedAccountPosition;
0138 };