matrixion/src/timeline/TimelineViewManager.h

167 lines
6.4 KiB
C
Raw Normal View History

#pragma once
2017-04-06 02:06:42 +03:00
#include <QHash>
2019-11-09 05:06:10 +03:00
#include <QQuickView>
#include <QQuickWidget>
#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>
2019-11-09 05:06:10 +03:00
#include "Cache.h"
#include "CallManager.h"
2019-11-09 05:06:10 +03:00
#include "Logging.h"
#include "TimelineModel.h"
#include "Utils.h"
2020-09-22 19:07:36 +03:00
#include "WebRTCSession.h"
#include "emoji/EmojiModel.h"
#include "emoji/Provider.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;
2020-10-27 19:45:28 +03:00
class DeviceVerificationFlow;
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)
Q_PROPERTY(
bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged)
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-10-27 20:14:06 +03:00
Q_PROPERTY(bool onVideoCall READ onVideoCall NOTIFY videoCallChanged)
Q_PROPERTY(QString callPartyName READ callPartyName NOTIFY callPartyChanged)
Q_PROPERTY(QString callPartyAvatarUrl READ callPartyAvatarUrl NOTIFY callPartyChanged)
Q_PROPERTY(bool isMicMuted READ isMicMuted NOTIFY micMuteChanged)
2020-11-16 01:14:47 +03:00
Q_PROPERTY(bool isOnCall READ isOnCall NOTIFY onCallChanged)
Q_PROPERTY(bool callsSupported READ callsSupported CONSTANT)
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; }
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_; }
Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; }
bool isNarrowView() const { return isNarrowView_; }
2020-09-22 19:07:36 +03:00
webrtc::State callState() const { return WebRTCSession::instance().state(); }
2020-10-27 20:14:06 +03:00
bool onVideoCall() const { return WebRTCSession::instance().isVideo(); }
Q_INVOKABLE void setVideoCallItem();
QString callPartyName() const { return callManager_->callPartyName(); }
QString callPartyAvatarUrl() const { return callManager_->callPartyAvatarUrl(); }
bool isMicMuted() const { return WebRTCSession::instance().isMicMuted(); }
Q_INVOKABLE void toggleMicMute();
2020-11-09 18:51:17 +03:00
Q_INVOKABLE void toggleCameraView();
2019-12-03 04:26:41 +03:00
Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId) const;
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;
Q_INVOKABLE QString userStatus(QString id) const;
Q_INVOKABLE void openLink(QString link) const;
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);
void verifyUser(QString userid);
void verifyDevice(QString userid, QString deviceid);
signals:
void clearRoomMessageCount(QString roomid);
2019-11-09 05:06:10 +03:00
void updateRoomsLastMessage(QString roomid, const DescInfo &info);
void activeTimelineChanged(TimelineModel *timeline);
void initialSyncChanged(bool isInitialSync);
2020-01-28 07:28:11 +03:00
void replyingEventChanged(QString replyingEvent);
void replyClosed();
void newDeviceVerificationRequest(DeviceVerificationFlow *flow);
void inviteUsers(QStringList users);
void showRoomList();
void narrowViewChanged();
2020-09-22 19:07:36 +03:00
void callStateChanged(webrtc::State);
2020-10-27 20:14:06 +03:00
void videoCallChanged();
void callPartyChanged();
void micMuteChanged();
2020-11-16 01:14:47 +03:00
void onCallChanged();
2017-04-06 02:06:42 +03:00
public slots:
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);
2020-10-28 15:06:28 +03:00
void initWithMessages(const std::vector<QString> &roomIds);
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-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 &);
void updateEncryptedDescriptions();
2020-11-16 01:14:47 +03:00
bool isOnCall() const;
bool callsSupported() const;
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-09 05:06:10 +03:00
MxcImageProvider *imgProvider;
ColorImageProvider *colorImgProvider;
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;
bool isInitialSync_ = true;
bool isNarrowView_ = false;
2020-01-27 17:59:25 +03:00
QHash<QString, QColor> userColors;
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)