2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2017-05-16 21:46:45 +03:00
|
|
|
#pragma once
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2020-05-13 07:35:26 +03:00
|
|
|
#include <QHash>
|
2021-07-15 01:26:39 +03:00
|
|
|
#include <QQuickItem>
|
|
|
|
#include <QQuickTextDocument>
|
2019-11-09 05:06:10 +03:00
|
|
|
#include <QQuickView>
|
|
|
|
#include <QQuickWidget>
|
2017-04-13 04:11:22 +03:00
|
|
|
#include <QSharedPointer>
|
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>
|
2017-11-15 19:38:50 +03:00
|
|
|
|
2019-11-09 05:06:10 +03:00
|
|
|
#include "Cache.h"
|
2020-09-25 17:26:36 +03:00
|
|
|
#include "CallManager.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"
|
2019-06-14 05:33:04 +03:00
|
|
|
#include "Utils.h"
|
2020-09-22 19:07:36 +03:00
|
|
|
#include "WebRTCSession.h"
|
2020-05-13 07:35:26 +03:00
|
|
|
#include "emoji/EmojiModel.h"
|
|
|
|
#include "emoji/Provider.h"
|
2021-06-10 00:52:28 +03:00
|
|
|
#include "timeline/CommunitiesModel.h"
|
2021-05-19 20:34:10 +03:00
|
|
|
#include "timeline/RoomlistModel.h"
|
2019-06-14 05:33:04 +03:00
|
|
|
|
2019-11-09 05:06:10 +03:00
|
|
|
class MxcImageProvider;
|
2020-03-01 21:55:43 +03:00
|
|
|
class BlurhashProvider;
|
2019-11-09 05:06:10 +03:00
|
|
|
class ColorImageProvider;
|
2020-01-27 17:59:25 +03:00
|
|
|
class UserSettings;
|
2020-09-03 18:01:58 +03:00
|
|
|
class ChatPage;
|
2020-10-27 19:45:28 +03:00
|
|
|
class DeviceVerificationFlow;
|
2021-07-21 14:37:57 +03:00
|
|
|
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 MEMBER isWindowFocused_ READ isWindowFocused NOTIFY focusChanged)
|
2017-10-01 19:49:36 +03:00
|
|
|
|
2019-11-09 05:06:10 +03:00
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr);
|
|
|
|
QWidget *getWidget() const { return container; }
|
2017-10-01 19:49:36 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
void sync(const mtx::responses::Rooms &rooms);
|
2021-05-19 20:34:10 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
MxcImageProvider *imageProvider() { return imgProvider; }
|
|
|
|
CallManager *callManager() { return callManager_; }
|
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 { return isWindowFocused_; }
|
|
|
|
Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId);
|
|
|
|
Q_INVOKABLE void openImagePackSettings(QString roomid);
|
|
|
|
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 QString userPresence(QString id) const;
|
|
|
|
Q_INVOKABLE QString userStatus(QString id) const;
|
2020-06-08 02:45:24 +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);
|
2021-07-22 01:56:20 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_INVOKABLE void focusMessageInput();
|
|
|
|
Q_INVOKABLE void openLeaveRoomDialog(QString roomid) const;
|
|
|
|
Q_INVOKABLE void removeVerificationFlow(DeviceVerificationFlow *flow);
|
2020-09-03 18:01:58 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_INVOKABLE void fixImageRendering(QQuickTextDocument *t, QQuickItem *i);
|
2021-07-15 01:26:39 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
void verifyUser(QString userid);
|
|
|
|
void verifyDevice(QString userid, QString deviceid);
|
2020-10-05 23:12:10 +03:00
|
|
|
|
2017-04-15 02:56:04 +03:00
|
|
|
signals:
|
2021-09-18 01:22:33 +03:00
|
|
|
void activeTimelineChanged(TimelineModel *timeline);
|
|
|
|
void initialSyncChanged(bool isInitialSync);
|
|
|
|
void replyingEventChanged(QString replyingEvent);
|
|
|
|
void replyClosed();
|
|
|
|
void newDeviceVerificationRequest(DeviceVerificationFlow *flow);
|
|
|
|
void inviteUsers(QString roomId, QStringList users);
|
|
|
|
void showRoomList();
|
|
|
|
void narrowViewChanged();
|
|
|
|
void focusChanged();
|
|
|
|
void focusInput();
|
|
|
|
void openImageOverlayInternalCb(QString eventId, QImage img);
|
|
|
|
void openRoomMembersDialog(MemberList *members, TimelineModel *room);
|
|
|
|
void openRoomSettingsDialog(RoomSettings *settings);
|
|
|
|
void openInviteUsersDialog(InviteesModel *invitees);
|
|
|
|
void openProfile(UserProfile *profile);
|
|
|
|
void showImagePackSettings(ImagePackListModel *packlist);
|
2017-04-15 02:56:04 +03:00
|
|
|
|
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 chatFocusChanged(bool focused)
|
|
|
|
{
|
|
|
|
isWindowFocused_ = focused;
|
|
|
|
emit focusChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void showEvent(const QString &room_id, const QString &event_id);
|
|
|
|
void focusTimeline();
|
|
|
|
|
|
|
|
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 = "");
|
|
|
|
void forwardMessageToRoom(mtx::events::collections::TimelineEvents *e, QString roomId);
|
|
|
|
|
|
|
|
RoomlistModel *rooms() { return rooms_; }
|
2021-05-28 23:14:59 +03:00
|
|
|
|
2021-04-05 14:58:00 +03:00
|
|
|
private slots:
|
2021-09-18 01:22:33 +03:00
|
|
|
void openImageOverlayInternal(QString eventId, QImage img);
|
2021-04-05 14:58:00 +03:00
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
private:
|
2019-11-09 05:06:10 +03:00
|
|
|
#ifdef USE_QUICK_VIEW
|
2021-09-18 01:22:33 +03:00
|
|
|
QQuickView *view;
|
2019-11-09 05:06:10 +03:00
|
|
|
#else
|
2021-09-18 01:22:33 +03:00
|
|
|
QQuickWidget *view;
|
2019-11-09 05:06:10 +03:00
|
|
|
#endif
|
2021-09-18 01:22:33 +03:00
|
|
|
QWidget *container;
|
2019-11-10 02:30:02 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
MxcImageProvider *imgProvider;
|
|
|
|
ColorImageProvider *colorImgProvider;
|
|
|
|
BlurhashProvider *blurhashProvider;
|
|
|
|
JdenticonProvider *jdenticonProvider;
|
2019-11-09 05:06:10 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
CallManager *callManager_ = nullptr;
|
2020-05-13 07:35:26 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
bool isInitialSync_ = true;
|
|
|
|
bool isWindowFocused_ = false;
|
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
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QHash<QString, QColor> userColors;
|
2020-06-17 21:28:35 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QHash<QString, QSharedPointer<DeviceVerificationFlow>> dvList;
|
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)
|