File indexing completed on 2024-05-12 05:04:09
0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #pragma once 0005 0006 #include <QJsonArray> 0007 0008 class AbstractAccount; 0009 class Relationship; 0010 0011 /// Represents a profile on the server. These are attached to Posts, and even our own Accounts 0012 class Identity : public QObject 0013 { 0014 Q_OBJECT 0015 0016 Q_PROPERTY(QString id READ id NOTIFY identityUpdated) 0017 Q_PROPERTY(QString displayName READ displayName NOTIFY identityUpdated) 0018 Q_PROPERTY(QString displayNameHtml READ displayNameHtml NOTIFY identityUpdated) 0019 Q_PROPERTY(QString username READ username NOTIFY identityUpdated) 0020 Q_PROPERTY(QString bio READ bio NOTIFY identityUpdated) 0021 Q_PROPERTY(QString account READ account NOTIFY identityUpdated) 0022 Q_PROPERTY(QUrl url READ url NOTIFY identityUpdated) 0023 Q_PROPERTY(bool locked READ locked NOTIFY identityUpdated) 0024 Q_PROPERTY(QString visibility READ visibility NOTIFY identityUpdated) 0025 Q_PROPERTY(QUrl avatarUrl READ avatarUrl NOTIFY identityUpdated) 0026 Q_PROPERTY(QUrl backgroundUrl READ backgroundUrl NOTIFY identityUpdated) 0027 Q_PROPERTY(int followersCount READ followersCount NOTIFY identityUpdated) 0028 Q_PROPERTY(int followingCount READ followingCount NOTIFY identityUpdated) 0029 Q_PROPERTY(int statusesCount READ statusesCount NOTIFY identityUpdated) 0030 Q_PROPERTY(int permission READ permission NOTIFY identityUpdated) 0031 Q_PROPERTY(QJsonArray fields READ fields NOTIFY identityUpdated) 0032 Q_PROPERTY(Relationship *relationship READ relationship NOTIFY relationshipChanged) 0033 0034 public: 0035 /// The numeric ID associated with this identity 0036 QString id() const; 0037 0038 /// This identity's display name, if not set then returns the username 0039 QString displayName() const; 0040 0041 /// The username for this identity 0042 QString username() const; 0043 0044 /// This identity's display name, but processed as HTML (for custom emojis). If not set, returns the username 0045 QString displayNameHtml() const; 0046 0047 /// The biography for this identity 0048 QString bio() const; 0049 0050 /// The account ID for this identity 0051 QString account() const; 0052 0053 /// The URL to this identity's profile, which exists on their original server 0054 QUrl url() const; 0055 0056 /// If this identity is locked or not 0057 bool locked() const; 0058 0059 /// The profile visibility 0060 QString visibility() const; 0061 0062 /// URL to this identity's avatar 0063 QUrl avatarUrl() const; 0064 0065 /// URL to this identity's background 0066 QUrl backgroundUrl() const; 0067 0068 /// The number of users following this identity 0069 int followersCount() const; 0070 0071 /// The number of users this identity follows 0072 int followingCount() const; 0073 0074 /// The number of posts written by this identity 0075 int statusesCount() const; 0076 0077 /// The permissions of this identity 0078 int permission() const; 0079 0080 /// Custom fields set by this identity 0081 QJsonArray fields() const; 0082 0083 /// Fills in identity data from JSON 0084 /// \param doc The JSON data to load from 0085 void fromSourceData(const QJsonObject &doc); 0086 0087 /// Sets the parent account for this identity 0088 /// \param parent The account to reparent to 0089 void reparentIdentity(AbstractAccount *parent); 0090 0091 /// Returns the relationship to this identity 0092 Relationship *relationship() const; 0093 0094 /// Replaces the existing relationship with a new one 0095 /// \param r The new relationship 0096 void setRelationship(Relationship *r); 0097 0098 Q_SIGNALS: 0099 void relationshipChanged(); 0100 void identityUpdated(); 0101 0102 private: 0103 QString m_id; 0104 QString m_displayName; 0105 QString m_displayNameHtml; 0106 QString m_username; 0107 QString m_bio; 0108 QString m_account; 0109 bool m_locked; 0110 QString m_visibility; 0111 QUrl m_avatarUrl; 0112 QUrl m_backgroundUrl; 0113 QUrl m_url; 0114 QJsonArray m_fields; 0115 int m_followersCount; 0116 int m_followingCount; 0117 int m_statusesCount; 0118 int m_permission; 0119 Relationship *m_relationship = nullptr; 0120 AbstractAccount *m_parent = nullptr; 0121 };