| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <QHash> |
| 8 |
#include <QQmlEngine> |
| 9 |
|
| 10 |
#include <unordered_map> |
| 11 |
|
| 12 |
class QQuickItem; |
| 13 |
class QQuickTextDocument; |
| 14 |
|
| 15 |
class UserSettings; |
| 16 |
class ChatPage; |
| 17 |
class ImagePackListModel; |
| 18 |
class TimelineModel; |
| 19 |
class CallManager; |
| 20 |
class VerificationManager; |
| 21 |
class InviteesModel; |
| 22 |
class MemberList; |
| 23 |
class CommunitiesModel; |
| 24 |
class RoomlistModel; |
| 25 |
class PresenceEmitter; |
| 26 |
class UserProfile; |
| 27 |
class RoomSettings; |
| 28 |
class FilteredRoomlistModel; |
| 29 |
class QAbstractItemModel; |
| 30 |
|
| 31 |
namespace mtx::responses { |
| 32 |
struct Sync; |
| 33 |
struct AccountData; |
| 34 |
} |
| 35 |
|
| 36 |
namespace mtx::events::voip { |
| 37 |
struct CallInvite; |
| 38 |
struct CallCandidates; |
| 39 |
struct CallAnswer; |
| 40 |
struct CallHangUp; |
| 41 |
struct CallSelectAnswer; |
| 42 |
struct CallReject; |
| 43 |
struct CallNegotiate; |
| 44 |
} |
| 45 |
namespace mtx::events::collections { |
| 46 |
struct TimelineEvents; |
| 47 |
} |
| 48 |
|
| 49 |
class TimelineViewManager final : public QObject |
| 50 |
{ |
| 51 |
Q_OBJECT |
| 52 |
|
| 53 |
QML_NAMED_ELEMENT(TimelineManager) |
| 54 |
QML_SINGLETON |
| 55 |
|
| 56 |
Q_PROPERTY( |
| 57 |
bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged) |
| 58 |
Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged) |
| 59 |
Q_PROPERTY(QVector<QString> ignoredUsers READ getIgnoredUsers NOTIFY ignoredUsersChanged) |
| 60 |
|
| 61 |
public: |
| 62 |
TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr); |
| 63 |
|
| 64 |
static TimelineViewManager *create(QQmlEngine *qmlEngine, QJSEngine *); |
| 65 |
|
| 66 |
static TimelineViewManager *instance() { return TimelineViewManager::instance_; } |
| 67 |
|
| 68 |
QVector<QString> getIgnoredUsers(); |
| 69 |
|
| 70 |
void sync(const mtx::responses::Sync &sync_); |
| 71 |
|
| 72 |
VerificationManager *verificationManager() { return verificationManager_; } |
| 73 |
|
| 74 |
void clearAll(); |
| 75 |
|
| 76 |
Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; } |
| 77 |
bool isConnected() const { return isConnected_; } |
| 78 |
Q_INVOKABLE void openImageOverlay(TimelineModel *room, |
| 79 |
const QString &mxcUrl, |
| 80 |
const QString &eventId, |
| 81 |
double originalWidth, |
| 82 |
double proportionalHeight); |
| 83 |
Q_INVOKABLE void openImagePackSettings(QString roomid); |
| 84 |
Q_INVOKABLE void saveMedia(QString mxcUrl); |
| 85 |
Q_INVOKABLE void copyImage(const QString &mxcUrl) const; |
| 86 |
Q_INVOKABLE QColor userColor(QString id, QColor background); |
| 87 |
Q_INVOKABLE QString escapeEmoji(QString str) const; |
| 88 |
Q_INVOKABLE QString htmlEscape(QString str) const { return str.toHtmlEscaped(); } |
| 89 |
|
| 90 |
Q_INVOKABLE void openRoomMembers(TimelineModel *room); |
| 91 |
Q_INVOKABLE void openRoomSettings(QString room_id); |
| 92 |
Q_INVOKABLE void openInviteUsers(QString roomId); |
| 93 |
Q_INVOKABLE void openGlobalUserProfile(QString userId); |
| 94 |
Q_INVOKABLE UserProfile *getGlobalUserProfile(QString userId); |
| 95 |
|
| 96 |
Q_INVOKABLE void focusMessageInput(); |
| 97 |
|
| 98 |
Q_INVOKABLE void fixImageRendering(QQuickTextDocument *t, QQuickItem *i); |
| 99 |
|
| 100 |
signals: |
| 101 |
void activeTimelineChanged(TimelineModel *timeline); |
| 102 |
void initialSyncChanged(bool isInitialSync); |
| 103 |
void isConnectedChanged(bool state); |
| 104 |
void replyingEventChanged(QString replyingEvent); |
| 105 |
void replyClosed(); |
| 106 |
void inviteUsers(QString roomId, QStringList users); |
| 107 |
void showRoomList(); |
| 108 |
void narrowViewChanged(); |
| 109 |
void focusInput(); |
| 110 |
void openRoomMembersDialog(MemberList *members, TimelineModel *room); |
| 111 |
void openRoomSettingsDialog(RoomSettings *settings); |
| 112 |
void openInviteUsersDialog(InviteesModel *invitees); |
| 113 |
void openProfile(UserProfile *profile); |
| 114 |
void showImagePackSettings(TimelineModel *room, ImagePackListModel *packlist); |
| 115 |
void openLeaveRoomDialog(QString roomid, QString reason = ""); |
| 116 |
void showImageOverlay(TimelineModel *room, |
| 117 |
QString eventId, |
| 118 |
QString url, |
| 119 |
double originalWidth, |
| 120 |
double proportionalHeight); |
| 121 |
void ignoredUsersChanged(const QVector<QString> &ignoredUsers); |
| 122 |
|
| 123 |
public slots: |
| 124 |
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids); |
| 125 |
void receivedSessionKey(const std::string &room_id, const std::string &session_id); |
| 126 |
void initializeRoomlist(); |
| 127 |
|
| 128 |
void showEvent(const QString &room_id, const QString &event_id); |
| 129 |
|
| 130 |
void updateColorPalette(); |
| 131 |
void queueReply(const QString &roomid, const QString &repliedToEvent, const QString &replyBody); |
| 132 |
void queueCallMessage(const QString &roomid, const mtx::events::voip::CallInvite &); |
| 133 |
void queueCallMessage(const QString &roomid, const mtx::events::voip::CallCandidates &); |
| 134 |
void queueCallMessage(const QString &roomid, const mtx::events::voip::CallAnswer &); |
| 135 |
void queueCallMessage(const QString &roomid, const mtx::events::voip::CallHangUp &); |
| 136 |
void queueCallMessage(const QString &roomid, const mtx::events::voip::CallSelectAnswer &); |
| 137 |
void queueCallMessage(const QString &roomid, const mtx::events::voip::CallReject &); |
| 138 |
void queueCallMessage(const QString &roomid, const mtx::events::voip::CallNegotiate &); |
| 139 |
|
| 140 |
void setVideoCallItem(); |
| 141 |
|
| 142 |
QAbstractItemModel *completerFor(const QString &completerName, |
| 143 |
const QString &roomId = QLatin1String(QLatin1String(""))); |
| 144 |
void forwardMessageToRoom(mtx::events::collections::TimelineEvents const *e, QString roomId); |
| 145 |
|
| 146 |
RoomlistModel *rooms() { return rooms_; } |
| 147 |
|
| 148 |
private: |
| 149 |
bool isInitialSync_ = true; |
| 150 |
bool isConnected_ = true; |
| 151 |
|
| 152 |
RoomlistModel *rooms_ = nullptr; |
| 153 |
FilteredRoomlistModel *frooms_ = nullptr; |
| 154 |
CommunitiesModel *communities_ = nullptr; |
| 155 |
|
| 156 |
|
| 157 |
VerificationManager *verificationManager_ = nullptr; |
| 158 |
PresenceEmitter *presenceEmitter = nullptr; |
| 159 |
|
| 160 |
QHash<std::pair<QString, quint64>, QColor> userColors; |
| 161 |
|
| 162 |
inline static TimelineViewManager *instance_ = nullptr; |
| 163 |
|
| 164 |
void processIgnoredUsers(const mtx::responses::AccountData &data); |
| 165 |
}; |