matrixion/src/timeline/TimelineViewManager.h

137 lines
5.1 KiB
C
Raw Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-03-05 02:35:15 +03:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
2017-04-06 02:06:42 +03:00
#include <QHash>
#include <QQuickItem>
#include <QQuickTextDocument>
2019-11-09 05:06:10 +03:00
#include <QWidget>
2017-04-06 02:06:42 +03:00
2019-12-05 17:31:53 +03:00
#include <mtx/common.hpp>
2020-10-27 19:45:28 +03:00
#include <mtx/responses/messages.hpp>
#include <mtx/responses/sync.hpp>
2019-11-09 05:06:10 +03:00
#include "Cache.h"
2020-12-25 17:14:00 +03:00
#include "JdenticonProvider.h"
2019-11-09 05:06:10 +03:00
#include "Logging.h"
#include "TimelineModel.h"
#include "Utils.h"
#include "emoji/EmojiModel.h"
#include "emoji/Provider.h"
#include "encryption/VerificationManager.h"
2021-06-10 00:52:28 +03:00
#include "timeline/CommunitiesModel.h"
#include "timeline/PresenceEmitter.h"
2021-05-19 20:34:10 +03:00
#include "timeline/RoomlistModel.h"
#include "voip/CallManager.h"
#include "voip/WebRTCSession.h"
2019-11-09 05:06:10 +03:00
class MxcImageProvider;
class BlurhashProvider;
2019-11-09 05:06:10 +03:00
class ColorImageProvider;
2020-01-27 17:59:25 +03:00
class UserSettings;
class ChatPage;
class ImagePackListModel;
2017-04-06 02:06:42 +03:00
2019-11-09 05:06:10 +03:00
class TimelineViewManager : public QObject
2017-04-06 02:06:42 +03:00
{
2021-09-18 01:22:33 +03:00
Q_OBJECT
2017-04-06 02:06:42 +03:00
2021-09-18 01:22:33 +03:00
Q_PROPERTY(
bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged)
Q_PROPERTY(bool isWindowFocused READ isWindowFocused NOTIFY focusChanged)
2022-01-26 04:16:06 +03:00
Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged)
2019-11-09 05:06:10 +03:00
public:
2021-09-18 01:22:33 +03:00
TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr);
void sync(const mtx::responses::Sync &sync_);
2021-05-19 20:34:10 +03:00
VerificationManager *verificationManager() { return verificationManager_; }
2017-10-07 20:50:32 +03:00
2021-09-18 01:22:33 +03:00
void clearAll() { rooms_->clear(); }
2019-11-09 05:06:10 +03:00
2021-09-18 01:22:33 +03:00
Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; }
bool isWindowFocused() const;
2022-01-26 04:16:06 +03:00
bool isConnected() const { return isConnected_; }
Q_INVOKABLE void openImageOverlay(TimelineModel *room, QString mxcUrl, QString eventId);
2021-09-18 01:22:33 +03:00
Q_INVOKABLE void openImagePackSettings(QString roomid);
Q_INVOKABLE void saveMedia(QString mxcUrl);
2021-09-18 01:22:33 +03:00
Q_INVOKABLE QColor userColor(QString id, QColor background);
Q_INVOKABLE QString escapeEmoji(QString str) const;
Q_INVOKABLE QString htmlEscape(QString str) const { return str.toHtmlEscaped(); }
2017-04-11 22:48:02 +03:00
2021-09-18 01:22:33 +03:00
Q_INVOKABLE void openRoomMembers(TimelineModel *room);
Q_INVOKABLE void openRoomSettings(QString room_id);
Q_INVOKABLE void openInviteUsers(QString roomId);
Q_INVOKABLE void openGlobalUserProfile(QString userId);
2022-03-27 00:28:31 +03:00
Q_INVOKABLE UserProfile *getGlobalUserProfile(QString userId);
2021-09-18 01:22:33 +03:00
Q_INVOKABLE void focusMessageInput();
2021-09-18 01:22:33 +03:00
Q_INVOKABLE void fixImageRendering(QQuickTextDocument *t, QQuickItem *i);
signals:
2021-09-18 01:22:33 +03:00
void activeTimelineChanged(TimelineModel *timeline);
void initialSyncChanged(bool isInitialSync);
2022-01-26 04:16:06 +03:00
void isConnectedChanged(bool state);
2021-09-18 01:22:33 +03:00
void replyingEventChanged(QString replyingEvent);
void replyClosed();
void inviteUsers(QString roomId, QStringList users);
void showRoomList();
void narrowViewChanged();
void focusChanged();
void focusInput();
void openRoomMembersDialog(MemberList *members, TimelineModel *room);
void openRoomSettingsDialog(RoomSettings *settings);
void openInviteUsersDialog(InviteesModel *invitees);
void openProfile(UserProfile *profile);
void showImagePackSettings(TimelineModel *room, ImagePackListModel *packlist);
void openLeaveRoomDialog(QString roomid);
void showImageOverlay(TimelineModel *room, QString eventId, QString url);
2017-04-06 02:06:42 +03:00
public slots:
2021-09-18 01:22:33 +03:00
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
void receivedSessionKey(const std::string &room_id, const std::string &session_id);
void initializeRoomlist();
void showEvent(const QString &room_id, const QString &event_id);
void updateColorPalette();
void queueReply(const QString &roomid, const QString &repliedToEvent, const QString &replyBody);
void queueCallMessage(const QString &roomid, const mtx::events::msg::CallInvite &);
void queueCallMessage(const QString &roomid, const mtx::events::msg::CallCandidates &);
void queueCallMessage(const QString &roomid, const mtx::events::msg::CallAnswer &);
void queueCallMessage(const QString &roomid, const mtx::events::msg::CallHangUp &);
void setVideoCallItem();
QObject *completerFor(QString completerName, QString roomId = QLatin1String(QLatin1String("")));
2021-09-18 01:22:33 +03:00
void forwardMessageToRoom(mtx::events::collections::TimelineEvents *e, QString roomId);
RoomlistModel *rooms() { return rooms_; }
2017-04-06 02:06:42 +03:00
private:
2022-01-24 02:41:55 +03:00
bool isInitialSync_ = true;
2022-01-26 04:16:06 +03:00
bool isConnected_ = true;
2020-01-27 17:59:25 +03:00
2021-09-18 01:22:33 +03:00
RoomlistModel *rooms_ = nullptr;
CommunitiesModel *communities_ = nullptr;
2021-05-19 20:34:10 +03:00
// don't move this above the rooms_
VerificationManager *verificationManager_ = nullptr;
PresenceEmitter *presenceEmitter = nullptr;
2021-11-19 00:33:45 +03:00
QHash<QPair<QString, quint64>, QColor> userColors;
2017-04-06 02:06:42 +03:00
};
2020-07-17 23:16:30 +03:00
Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationAccept)
Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationCancel)
Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationDone)
Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationKey)
Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationMac)
Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationReady)
Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationRequest)
Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationStart)