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>
|
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>
|
2019-11-09 05:06:10 +03:00
|
|
|
#include <mtx/responses.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-03-13 23:05:18 +03:00
|
|
|
#include "DeviceVerificationFlow.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"
|
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;
|
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
|
|
|
{
|
2017-08-26 11:33:26 +03:00
|
|
|
Q_OBJECT
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2019-11-09 05:06:10 +03:00
|
|
|
Q_PROPERTY(
|
|
|
|
TimelineModel *timeline MEMBER timeline_ READ activeTimeline NOTIFY activeTimelineChanged)
|
2019-11-10 02:30:02 +03:00
|
|
|
Q_PROPERTY(
|
|
|
|
bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged)
|
2020-09-03 18:01:58 +03:00
|
|
|
Q_PROPERTY(
|
|
|
|
bool isNarrowView MEMBER isNarrowView_ READ isNarrowView NOTIFY narrowViewChanged)
|
2020-09-22 19:14:15 +03:00
|
|
|
Q_PROPERTY(webrtc::State callState READ callState NOTIFY callStateChanged)
|
2020-09-25 17:26:36 +03:00
|
|
|
Q_PROPERTY(QString callPartyName READ callPartyName NOTIFY callPartyChanged)
|
|
|
|
Q_PROPERTY(QString callPartyAvatarUrl READ callPartyAvatarUrl NOTIFY callPartyChanged)
|
|
|
|
Q_PROPERTY(bool isMicMuted READ isMicMuted NOTIFY micMuteChanged)
|
2017-10-01 19:49:36 +03:00
|
|
|
|
2019-11-09 05:06:10 +03:00
|
|
|
public:
|
2020-10-17 01:57:29 +03:00
|
|
|
TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr);
|
2019-11-09 05:06:10 +03:00
|
|
|
QWidget *getWidget() const { return container; }
|
2017-10-01 19:49:36 +03:00
|
|
|
|
2017-12-04 19:41:19 +03:00
|
|
|
void sync(const mtx::responses::Rooms &rooms);
|
2019-11-09 05:06:10 +03:00
|
|
|
void addRoom(const QString &room_id);
|
2017-10-07 20:50:32 +03:00
|
|
|
|
2019-11-09 05:06:10 +03:00
|
|
|
void clearAll() { models.clear(); }
|
|
|
|
|
|
|
|
Q_INVOKABLE TimelineModel *activeTimeline() const { return timeline_; }
|
2019-11-10 02:30:02 +03:00
|
|
|
Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; }
|
2020-09-03 18:01:58 +03:00
|
|
|
bool isNarrowView() const { return isNarrowView_; }
|
2020-09-22 19:07:36 +03:00
|
|
|
webrtc::State callState() const { return WebRTCSession::instance().state(); }
|
2020-09-25 17:26:36 +03:00
|
|
|
QString callPartyName() const { return callManager_->callPartyName(); }
|
|
|
|
QString callPartyAvatarUrl() const { return callManager_->callPartyAvatarUrl(); }
|
|
|
|
bool isMicMuted() const { return WebRTCSession::instance().isMicMuted(); }
|
|
|
|
Q_INVOKABLE void toggleMicMute();
|
2019-12-03 04:26:41 +03:00
|
|
|
Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId) const;
|
2020-02-20 22:51:07 +03:00
|
|
|
Q_INVOKABLE QColor userColor(QString id, QColor background);
|
2020-09-03 20:51:50 +03:00
|
|
|
Q_INVOKABLE QString escapeEmoji(QString str) const;
|
2017-04-11 22:48:02 +03:00
|
|
|
|
2020-06-24 17:24:22 +03:00
|
|
|
Q_INVOKABLE QString userPresence(QString id) const;
|
2020-06-08 02:45:24 +03:00
|
|
|
Q_INVOKABLE QString userStatus(QString id) const;
|
|
|
|
|
2020-07-09 01:45:37 +03:00
|
|
|
Q_INVOKABLE void openLink(QString link) const;
|
|
|
|
|
2020-09-03 18:01:58 +03:00
|
|
|
Q_INVOKABLE void openInviteUsersDialog();
|
|
|
|
Q_INVOKABLE void openMemberListDialog() const;
|
|
|
|
Q_INVOKABLE void openLeaveRoomDialog() const;
|
|
|
|
Q_INVOKABLE void openRoomSettings() const;
|
2020-10-05 23:58:07 +03:00
|
|
|
Q_INVOKABLE void removeVerificationFlow(DeviceVerificationFlow *flow);
|
2020-09-03 18:01:58 +03:00
|
|
|
|
2020-10-05 23:12:10 +03:00
|
|
|
void verifyUser(QString userid);
|
|
|
|
void verifyDevice(QString userid, QString deviceid);
|
|
|
|
|
2017-04-15 02:56:04 +03:00
|
|
|
signals:
|
2017-11-24 01:10:58 +03:00
|
|
|
void clearRoomMessageCount(QString roomid);
|
2019-11-09 05:06:10 +03:00
|
|
|
void updateRoomsLastMessage(QString roomid, const DescInfo &info);
|
|
|
|
void activeTimelineChanged(TimelineModel *timeline);
|
2019-11-10 02:30:02 +03:00
|
|
|
void initialSyncChanged(bool isInitialSync);
|
2020-01-28 07:28:11 +03:00
|
|
|
void replyingEventChanged(QString replyingEvent);
|
2020-02-05 02:17:14 +03:00
|
|
|
void replyClosed();
|
2020-10-05 23:12:10 +03:00
|
|
|
void newDeviceVerificationRequest(DeviceVerificationFlow *flow);
|
2020-09-03 18:01:58 +03:00
|
|
|
void inviteUsers(QStringList users);
|
|
|
|
void showRoomList();
|
|
|
|
void narrowViewChanged();
|
2020-09-22 19:07:36 +03:00
|
|
|
void callStateChanged(webrtc::State);
|
2020-09-25 17:26:36 +03:00
|
|
|
void callPartyChanged();
|
|
|
|
void micMuteChanged();
|
2017-04-15 02:56:04 +03:00
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
public slots:
|
2018-07-17 23:50:18 +03:00
|
|
|
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
|
2020-10-20 20:46:37 +03:00
|
|
|
void receivedSessionKey(const std::string &room_id, const std::string &session_id);
|
2018-06-28 16:16:43 +03:00
|
|
|
void initWithMessages(const std::map<QString, mtx::responses::Timeline> &msgs);
|
2018-06-09 16:03:14 +03:00
|
|
|
|
2017-08-26 11:33:26 +03:00
|
|
|
void setHistoryView(const QString &room_id);
|
2019-11-09 05:06:10 +03:00
|
|
|
void updateColorPalette();
|
2020-07-20 01:42:48 +03:00
|
|
|
void queueReactionMessage(const QString &reactedEvent, const QString &reactionKey);
|
2020-04-13 17:22:30 +03:00
|
|
|
void queueTextMessage(const QString &msg);
|
2017-11-15 19:38:50 +03:00
|
|
|
void queueEmoteMessage(const QString &msg);
|
2018-01-10 10:52:59 +03:00
|
|
|
void queueImageMessage(const QString &roomid,
|
|
|
|
const QString &filename,
|
2019-12-14 19:08:36 +03:00
|
|
|
const std::optional<mtx::crypto::EncryptedFile> &file,
|
2018-02-18 23:52:31 +03:00
|
|
|
const QString &url,
|
|
|
|
const QString &mime,
|
2018-07-10 23:31:51 +03:00
|
|
|
uint64_t dsize,
|
2020-01-12 18:39:01 +03:00
|
|
|
const QSize &dimensions,
|
2020-04-13 17:22:30 +03:00
|
|
|
const QString &blurhash);
|
2018-02-18 23:52:31 +03:00
|
|
|
void queueFileMessage(const QString &roomid,
|
|
|
|
const QString &filename,
|
2019-12-14 19:08:36 +03:00
|
|
|
const std::optional<mtx::crypto::EncryptedFile> &file,
|
2018-02-18 23:52:31 +03:00
|
|
|
const QString &url,
|
|
|
|
const QString &mime,
|
2020-04-13 17:22:30 +03:00
|
|
|
uint64_t dsize);
|
2018-02-18 23:52:31 +03:00
|
|
|
void queueAudioMessage(const QString &roomid,
|
|
|
|
const QString &filename,
|
2019-12-14 19:08:36 +03:00
|
|
|
const std::optional<mtx::crypto::EncryptedFile> &file,
|
2018-02-18 23:52:31 +03:00
|
|
|
const QString &url,
|
|
|
|
const QString &mime,
|
2020-04-13 17:22:30 +03:00
|
|
|
uint64_t dsize);
|
2018-02-18 23:52:31 +03:00
|
|
|
void queueVideoMessage(const QString &roomid,
|
|
|
|
const QString &filename,
|
2019-12-14 19:08:36 +03:00
|
|
|
const std::optional<mtx::crypto::EncryptedFile> &file,
|
2018-02-18 23:52:31 +03:00
|
|
|
const QString &url,
|
|
|
|
const QString &mime,
|
2020-04-13 17:22:30 +03:00
|
|
|
uint64_t dsize);
|
2020-07-11 02:19:48 +03:00
|
|
|
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 &);
|
|
|
|
|
2020-04-23 02:52:30 +03:00
|
|
|
void updateEncryptedDescriptions();
|
2017-04-13 04:11:22 +03:00
|
|
|
|
2020-08-10 00:36:47 +03:00
|
|
|
void clearCurrentRoomTimeline()
|
|
|
|
{
|
|
|
|
if (timeline_)
|
|
|
|
timeline_->clearTimeline();
|
|
|
|
}
|
|
|
|
|
2020-09-03 18:01:58 +03:00
|
|
|
void enableBackButton()
|
|
|
|
{
|
|
|
|
if (isNarrowView_)
|
|
|
|
return;
|
|
|
|
isNarrowView_ = true;
|
|
|
|
emit narrowViewChanged();
|
|
|
|
}
|
|
|
|
void disableBackButton()
|
|
|
|
{
|
|
|
|
if (!isNarrowView_)
|
|
|
|
return;
|
|
|
|
isNarrowView_ = false;
|
|
|
|
emit narrowViewChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void backToRooms() { emit showRoomList(); }
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
private:
|
2019-11-09 05:06:10 +03:00
|
|
|
#ifdef USE_QUICK_VIEW
|
|
|
|
QQuickView *view;
|
|
|
|
#else
|
|
|
|
QQuickWidget *view;
|
|
|
|
#endif
|
|
|
|
QWidget *container;
|
2019-11-10 02:30:02 +03:00
|
|
|
|
2019-11-09 05:06:10 +03:00
|
|
|
MxcImageProvider *imgProvider;
|
|
|
|
ColorImageProvider *colorImgProvider;
|
2020-03-01 21:55:43 +03:00
|
|
|
BlurhashProvider *blurhashProvider;
|
2019-11-09 05:06:10 +03:00
|
|
|
|
|
|
|
QHash<QString, QSharedPointer<TimelineModel>> models;
|
2020-07-11 02:19:48 +03:00
|
|
|
TimelineModel *timeline_ = nullptr;
|
|
|
|
CallManager *callManager_ = nullptr;
|
2020-05-13 07:35:26 +03:00
|
|
|
|
|
|
|
bool isInitialSync_ = true;
|
2020-09-03 18:01:58 +03:00
|
|
|
bool isNarrowView_ = false;
|
2020-01-27 17:59:25 +03:00
|
|
|
|
2020-02-20 22:51:07 +03:00
|
|
|
QHash<QString, QColor> userColors;
|
2020-06-17 21:28:35 +03:00
|
|
|
|
2020-10-05 23:12:10 +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)
|