2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
2022-01-01 06:57:53 +03:00
|
|
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
2021-03-05 02:35:15 +03:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2019-11-09 05:06:10 +03:00
|
|
|
#include "TimelineViewManager.h"
|
|
|
|
|
2020-11-25 19:02:23 +03:00
|
|
|
#include <QDropEvent>
|
2022-01-02 23:46:29 +03:00
|
|
|
#include <QFileDialog>
|
2019-11-09 05:06:10 +03:00
|
|
|
#include <QMetaType>
|
|
|
|
#include <QPalette>
|
|
|
|
#include <QQmlContext>
|
2020-05-27 11:49:26 +03:00
|
|
|
#include <QQmlEngine>
|
2022-01-02 23:46:29 +03:00
|
|
|
#include <QStandardPaths>
|
2020-07-11 02:19:48 +03:00
|
|
|
#include <QString>
|
2019-11-09 05:06:10 +03:00
|
|
|
|
2020-03-01 21:55:43 +03:00
|
|
|
#include "BlurhashProvider.h"
|
2019-11-09 05:06:10 +03:00
|
|
|
#include "ChatPage.h"
|
2021-04-29 22:46:49 +03:00
|
|
|
#include "Clipboard.h"
|
2019-11-09 05:06:10 +03:00
|
|
|
#include "ColorImageProvider.h"
|
2021-07-21 02:03:38 +03:00
|
|
|
#include "CombinedImagePackModel.h"
|
2021-02-21 20:40:21 +03:00
|
|
|
#include "CompletionProxyModel.h"
|
2019-11-09 05:06:10 +03:00
|
|
|
#include "DelegateChooser.h"
|
2021-04-27 12:33:46 +03:00
|
|
|
#include "EventAccessors.h"
|
2021-07-21 14:37:57 +03:00
|
|
|
#include "ImagePackListModel.h"
|
2021-06-11 03:13:12 +03:00
|
|
|
#include "InviteesModel.h"
|
2018-07-17 16:37:25 +03:00
|
|
|
#include "Logging.h"
|
2020-09-03 18:01:58 +03:00
|
|
|
#include "MainWindow.h"
|
2020-01-17 03:25:14 +03:00
|
|
|
#include "MatrixClient.h"
|
2019-11-09 05:06:10 +03:00
|
|
|
#include "MxcImageProvider.h"
|
2021-07-24 01:11:33 +03:00
|
|
|
#include "ReadReceiptsModel.h"
|
2021-07-29 05:29:57 +03:00
|
|
|
#include "RoomDirectoryModel.h"
|
2021-02-21 20:40:21 +03:00
|
|
|
#include "RoomsModel.h"
|
2021-07-21 14:37:57 +03:00
|
|
|
#include "SingleImagePackModel.h"
|
2019-11-09 05:06:10 +03:00
|
|
|
#include "UserSettingsPage.h"
|
2021-02-21 20:40:21 +03:00
|
|
|
#include "UsersModel.h"
|
2020-05-13 07:35:26 +03:00
|
|
|
#include "emoji/EmojiModel.h"
|
|
|
|
#include "emoji/Provider.h"
|
2021-10-14 23:53:11 +03:00
|
|
|
#include "encryption/DeviceVerificationFlow.h"
|
|
|
|
#include "encryption/SelfVerificationStatus.h"
|
2021-08-29 06:20:23 +03:00
|
|
|
#include "ui/MxcAnimatedImage.h"
|
2021-08-28 01:38:33 +03:00
|
|
|
#include "ui/MxcMediaProxy.h"
|
2021-02-14 03:28:28 +03:00
|
|
|
#include "ui/NhekoCursorShape.h"
|
2020-11-25 19:02:23 +03:00
|
|
|
#include "ui/NhekoDropArea.h"
|
2021-05-13 09:23:56 +03:00
|
|
|
#include "ui/NhekoGlobalObject.h"
|
2021-09-18 01:21:14 +03:00
|
|
|
#include "ui/UIA.h"
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2020-01-11 20:53:32 +03:00
|
|
|
Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents)
|
2020-07-04 05:24:28 +03:00
|
|
|
Q_DECLARE_METATYPE(std::vector<DeviceInfo>)
|
2021-07-29 05:29:57 +03:00
|
|
|
Q_DECLARE_METATYPE(std::vector<mtx::responses::PublicRoomsChunk>)
|
2020-01-11 20:53:32 +03:00
|
|
|
|
2020-06-17 21:28:35 +03:00
|
|
|
namespace msgs = mtx::events::msg;
|
|
|
|
|
2021-04-27 12:33:46 +03:00
|
|
|
namespace {
|
|
|
|
template<template<class...> class Op, class... Args>
|
|
|
|
using is_detected = typename nheko::detail::detector<nheko::nonesuch, void, Op, Args...>::value_t;
|
|
|
|
|
|
|
|
template<class Content>
|
|
|
|
using file_t = decltype(Content::file);
|
|
|
|
|
|
|
|
template<class Content>
|
|
|
|
using url_t = decltype(Content::url);
|
|
|
|
|
|
|
|
template<class Content>
|
|
|
|
using body_t = decltype(Content::body);
|
|
|
|
|
|
|
|
template<class Content>
|
|
|
|
using formatted_body_t = decltype(Content::formatted_body);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static constexpr bool
|
|
|
|
messageWithFileAndUrl(const mtx::events::Event<T> &)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
return is_detected<file_t, T>::value && is_detected<url_t, T>::value;
|
2021-04-27 12:33:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static constexpr void
|
|
|
|
removeReplyFallback(mtx::events::Event<T> &e)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if constexpr (is_detected<body_t, T>::value) {
|
|
|
|
if constexpr (std::is_same_v<std::optional<std::string>,
|
|
|
|
std::remove_cv_t<decltype(e.content.body)>>) {
|
|
|
|
if (e.content.body) {
|
|
|
|
e.content.body = utils::stripReplyFromBody(e.content.body);
|
|
|
|
}
|
|
|
|
} else if constexpr (std::is_same_v<std::string,
|
|
|
|
std::remove_cv_t<decltype(e.content.body)>>) {
|
|
|
|
e.content.body = utils::stripReplyFromBody(e.content.body);
|
2021-04-27 12:33:46 +03:00
|
|
|
}
|
2021-09-18 01:22:33 +03:00
|
|
|
}
|
2021-04-27 12:33:46 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
if constexpr (is_detected<formatted_body_t, T>::value) {
|
|
|
|
if (e.content.format == "org.matrix.custom.html") {
|
|
|
|
e.content.formatted_body = utils::stripReplyFromFormattedBody(e.content.formatted_body);
|
2021-04-27 12:33:46 +03:00
|
|
|
}
|
2021-09-18 01:22:33 +03:00
|
|
|
}
|
2021-04-27 12:33:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-17 23:50:18 +03:00
|
|
|
void
|
2019-11-09 05:06:10 +03:00
|
|
|
TimelineViewManager::updateColorPalette()
|
2018-07-17 23:50:18 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
userColors.clear();
|
2020-02-20 22:51:07 +03:00
|
|
|
|
2021-12-29 06:28:08 +03:00
|
|
|
if (ChatPage::instance()->userSettings()->theme() == QLatin1String("light")) {
|
|
|
|
view->rootContext()->setContextProperty(QStringLiteral("currentActivePalette"), QPalette());
|
2021-12-29 08:01:38 +03:00
|
|
|
view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"),
|
|
|
|
QPalette());
|
2021-12-29 06:28:08 +03:00
|
|
|
} else if (ChatPage::instance()->userSettings()->theme() == QLatin1String("dark")) {
|
|
|
|
view->rootContext()->setContextProperty(QStringLiteral("currentActivePalette"), QPalette());
|
2021-12-29 08:01:38 +03:00
|
|
|
view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"),
|
|
|
|
QPalette());
|
2021-09-18 01:22:33 +03:00
|
|
|
} else {
|
2021-12-29 06:28:08 +03:00
|
|
|
view->rootContext()->setContextProperty(QStringLiteral("currentActivePalette"), QPalette());
|
|
|
|
view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"), nullptr);
|
2021-09-18 01:22:33 +03:00
|
|
|
}
|
2018-07-17 23:50:18 +03:00
|
|
|
}
|
|
|
|
|
2020-02-20 22:51:07 +03:00
|
|
|
QColor
|
|
|
|
TimelineViewManager::userColor(QString id, QColor background)
|
|
|
|
{
|
2021-11-19 00:33:45 +03:00
|
|
|
QPair<QString, quint64> idx{id, background.rgba64()};
|
|
|
|
if (!userColors.contains(idx))
|
|
|
|
userColors.insert(idx, QColor(utils::generateContrastingHexColor(id, background)));
|
|
|
|
return userColors.value(idx);
|
2020-02-20 22:51:07 +03:00
|
|
|
}
|
|
|
|
|
2020-10-17 01:57:29 +03:00
|
|
|
TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *parent)
|
2021-05-30 01:23:57 +03:00
|
|
|
: QObject(parent)
|
|
|
|
, imgProvider(new MxcImageProvider())
|
2019-11-09 05:06:10 +03:00
|
|
|
, colorImgProvider(new ColorImageProvider())
|
2020-03-01 21:55:43 +03:00
|
|
|
, blurhashProvider(new BlurhashProvider())
|
2020-12-25 17:14:00 +03:00
|
|
|
, jdenticonProvider(new JdenticonProvider())
|
2021-05-28 23:14:59 +03:00
|
|
|
, rooms_(new RoomlistModel(this))
|
2021-06-10 00:52:28 +03:00
|
|
|
, communities_(new CommunitiesModel(this))
|
2021-10-15 03:44:48 +03:00
|
|
|
, callManager_(callManager)
|
|
|
|
, verificationManager_(new VerificationManager(this))
|
2021-12-30 06:54:03 +03:00
|
|
|
, presenceEmitter(new PresenceEmitter(this))
|
2017-04-13 04:11:22 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
qRegisterMetaType<mtx::events::msg::KeyVerificationAccept>();
|
|
|
|
qRegisterMetaType<mtx::events::msg::KeyVerificationCancel>();
|
|
|
|
qRegisterMetaType<mtx::events::msg::KeyVerificationDone>();
|
|
|
|
qRegisterMetaType<mtx::events::msg::KeyVerificationKey>();
|
|
|
|
qRegisterMetaType<mtx::events::msg::KeyVerificationMac>();
|
|
|
|
qRegisterMetaType<mtx::events::msg::KeyVerificationReady>();
|
|
|
|
qRegisterMetaType<mtx::events::msg::KeyVerificationRequest>();
|
|
|
|
qRegisterMetaType<mtx::events::msg::KeyVerificationStart>();
|
|
|
|
qRegisterMetaType<CombinedImagePackModel *>();
|
|
|
|
|
|
|
|
qRegisterMetaType<std::vector<mtx::responses::PublicRoomsChunk>>();
|
|
|
|
|
2021-12-29 08:01:38 +03:00
|
|
|
qmlRegisterUncreatableMetaObject(qml_mtx_events::staticMetaObject,
|
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"MtxEvent",
|
|
|
|
QStringLiteral("Can't instantiate enum!"));
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterUncreatableMetaObject(
|
2021-12-29 06:28:08 +03:00
|
|
|
olm::staticMetaObject, "im.nheko", 1, 0, "Olm", QStringLiteral("Can't instantiate enum!"));
|
2021-12-29 08:01:38 +03:00
|
|
|
qmlRegisterUncreatableMetaObject(crypto::staticMetaObject,
|
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"Crypto",
|
|
|
|
QStringLiteral("Can't instantiate enum!"));
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterUncreatableMetaObject(verification::staticMetaObject,
|
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"VerificationStatus",
|
2021-12-29 06:28:08 +03:00
|
|
|
QStringLiteral("Can't instantiate enum!"));
|
2021-09-18 01:22:33 +03:00
|
|
|
|
|
|
|
qmlRegisterType<DelegateChoice>("im.nheko", 1, 0, "DelegateChoice");
|
|
|
|
qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser");
|
|
|
|
qmlRegisterType<NhekoDropArea>("im.nheko", 1, 0, "NhekoDropArea");
|
|
|
|
qmlRegisterType<NhekoCursorShape>("im.nheko", 1, 0, "CursorShape");
|
|
|
|
qmlRegisterType<MxcAnimatedImage>("im.nheko", 1, 0, "MxcAnimatedImage");
|
|
|
|
qmlRegisterType<MxcMediaProxy>("im.nheko", 1, 0, "MxcMedia");
|
|
|
|
qmlRegisterUncreatableType<DeviceVerificationFlow>(
|
2021-12-29 08:01:38 +03:00
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"DeviceVerificationFlow",
|
|
|
|
QStringLiteral("Can't create verification flow from QML!"));
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterUncreatableType<UserProfile>(
|
2021-12-29 08:01:38 +03:00
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"UserProfileModel",
|
|
|
|
QStringLiteral("UserProfile needs to be instantiated on the C++ side"));
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterUncreatableType<MemberList>(
|
2021-12-29 08:01:38 +03:00
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"MemberList",
|
|
|
|
QStringLiteral("MemberList needs to be instantiated on the C++ side"));
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterUncreatableType<RoomSettings>(
|
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"RoomSettingsModel",
|
2021-12-29 06:28:08 +03:00
|
|
|
QStringLiteral("Room Settings needs to be instantiated on the C++ side"));
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterUncreatableType<TimelineModel>(
|
2021-12-29 06:28:08 +03:00
|
|
|
"im.nheko", 1, 0, "Room", QStringLiteral("Room needs to be instantiated on the C++ side"));
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterUncreatableType<ImagePackListModel>(
|
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"ImagePackListModel",
|
2021-12-29 06:28:08 +03:00
|
|
|
QStringLiteral("ImagePackListModel needs to be instantiated on the C++ side"));
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterUncreatableType<SingleImagePackModel>(
|
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"SingleImagePackModel",
|
2021-12-29 06:28:08 +03:00
|
|
|
QStringLiteral("SingleImagePackModel needs to be instantiated on the C++ side"));
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterUncreatableType<InviteesModel>(
|
2021-12-29 08:01:38 +03:00
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"InviteesModel",
|
|
|
|
QStringLiteral("InviteesModel needs to be instantiated on the C++ side"));
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterUncreatableType<ReadReceiptsProxy>(
|
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"ReadReceiptsProxy",
|
2021-12-29 06:28:08 +03:00
|
|
|
QStringLiteral("ReadReceiptsProxy needs to be instantiated on the C++ side"));
|
2021-09-18 01:22:33 +03:00
|
|
|
|
|
|
|
static auto self = this;
|
2021-09-18 01:21:14 +03:00
|
|
|
qmlRegisterSingletonInstance("im.nheko", 1, 0, "MainWindow", MainWindow::instance());
|
|
|
|
qmlRegisterSingletonInstance("im.nheko", 1, 0, "TimelineManager", self);
|
|
|
|
qmlRegisterSingletonInstance("im.nheko", 1, 0, "UIA", UIA::instance());
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterSingletonType<RoomlistModel>(
|
|
|
|
"im.nheko", 1, 0, "Rooms", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
|
|
|
auto ptr = new FilteredRoomlistModel(self->rooms_);
|
|
|
|
|
|
|
|
connect(self->communities_,
|
|
|
|
&CommunitiesModel::currentTagIdChanged,
|
|
|
|
ptr,
|
|
|
|
&FilteredRoomlistModel::updateFilterTag);
|
|
|
|
connect(self->communities_,
|
|
|
|
&CommunitiesModel::hiddenTagsChanged,
|
|
|
|
ptr,
|
|
|
|
&FilteredRoomlistModel::updateHiddenTagsAndSpaces);
|
|
|
|
return ptr;
|
|
|
|
});
|
2021-09-18 01:21:14 +03:00
|
|
|
qmlRegisterSingletonInstance("im.nheko", 1, 0, "Communities", self->communities_);
|
|
|
|
qmlRegisterSingletonInstance(
|
|
|
|
"im.nheko", 1, 0, "Settings", ChatPage::instance()->userSettings().data());
|
|
|
|
qmlRegisterSingletonInstance(
|
|
|
|
"im.nheko", 1, 0, "CallManager", ChatPage::instance()->callManager());
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterSingletonType<Clipboard>(
|
|
|
|
"im.nheko", 1, 0, "Clipboard", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
|
|
|
return new Clipboard();
|
|
|
|
});
|
|
|
|
qmlRegisterSingletonType<Nheko>(
|
|
|
|
"im.nheko", 1, 0, "Nheko", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
|
|
|
return new Nheko();
|
|
|
|
});
|
2022-01-09 02:28:03 +03:00
|
|
|
qmlRegisterSingletonType<UserSettingsModel>(
|
|
|
|
"im.nheko", 1, 0, "UserSettingsModel", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
|
|
|
return new UserSettingsModel();
|
|
|
|
});
|
2021-10-15 03:44:48 +03:00
|
|
|
qmlRegisterSingletonInstance("im.nheko", 1, 0, "VerificationManager", verificationManager_);
|
2021-12-30 06:54:03 +03:00
|
|
|
qmlRegisterSingletonInstance("im.nheko", 1, 0, "Presence", presenceEmitter);
|
2021-09-18 01:21:14 +03:00
|
|
|
qmlRegisterSingletonType<SelfVerificationStatus>(
|
|
|
|
"im.nheko", 1, 0, "SelfVerificationStatus", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
2021-11-07 05:38:48 +03:00
|
|
|
auto ptr = new SelfVerificationStatus();
|
|
|
|
QObject::connect(ChatPage::instance(),
|
|
|
|
&ChatPage::initializeEmptyViews,
|
|
|
|
ptr,
|
|
|
|
&SelfVerificationStatus::invalidate);
|
|
|
|
return ptr;
|
2021-09-18 01:21:14 +03:00
|
|
|
});
|
2021-09-18 01:22:33 +03:00
|
|
|
|
|
|
|
qRegisterMetaType<mtx::events::collections::TimelineEvents>();
|
|
|
|
qRegisterMetaType<std::vector<DeviceInfo>>();
|
|
|
|
|
2021-12-01 02:02:41 +03:00
|
|
|
qmlRegisterUncreatableType<FilteredCommunitiesModel>(
|
|
|
|
"im.nheko",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"FilteredCommunitiesModel",
|
2021-12-29 06:28:08 +03:00
|
|
|
QStringLiteral("Use Communities.filtered() to create a FilteredCommunitiesModel"));
|
2021-12-01 02:02:41 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
qmlRegisterType<emoji::EmojiModel>("im.nheko.EmojiModel", 1, 0, "EmojiModel");
|
|
|
|
qmlRegisterUncreatableType<emoji::Emoji>(
|
2021-12-29 06:28:08 +03:00
|
|
|
"im.nheko.EmojiModel", 1, 0, "Emoji", QStringLiteral("Used by emoji models"));
|
2021-12-29 08:01:38 +03:00
|
|
|
qmlRegisterUncreatableMetaObject(emoji::staticMetaObject,
|
|
|
|
"im.nheko.EmojiModel",
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
"EmojiCategory",
|
|
|
|
QStringLiteral("Error: Only enums"));
|
2021-09-18 01:22:33 +03:00
|
|
|
|
|
|
|
qmlRegisterType<RoomDirectoryModel>("im.nheko", 1, 0, "RoomDirectoryModel");
|
2021-07-29 05:29:57 +03:00
|
|
|
|
2019-11-09 05:06:10 +03:00
|
|
|
#ifdef USE_QUICK_VIEW
|
2021-09-18 01:22:33 +03:00
|
|
|
view = new QQuickView(parent);
|
|
|
|
container = QWidget::createWindowContainer(view, parent);
|
2019-11-09 05:06:10 +03:00
|
|
|
#else
|
2021-09-18 01:22:33 +03:00
|
|
|
view = new QQuickWidget(parent);
|
|
|
|
container = view;
|
|
|
|
view->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
|
|
|
container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
connect(view, &QQuickWidget::statusChanged, this, [](QQuickWidget::Status status) {
|
|
|
|
nhlog::ui()->debug("Status changed to {}", status);
|
|
|
|
});
|
2019-11-09 05:06:10 +03:00
|
|
|
#endif
|
2021-09-18 01:22:33 +03:00
|
|
|
container->setMinimumSize(200, 200);
|
|
|
|
updateColorPalette();
|
2021-12-29 06:28:08 +03:00
|
|
|
view->engine()->addImageProvider(QStringLiteral("MxcImage"), imgProvider);
|
|
|
|
view->engine()->addImageProvider(QStringLiteral("colorimage"), colorImgProvider);
|
|
|
|
view->engine()->addImageProvider(QStringLiteral("blurhash"), blurhashProvider);
|
2021-09-18 01:22:33 +03:00
|
|
|
if (JdenticonProvider::isAvailable())
|
2021-12-29 06:28:08 +03:00
|
|
|
view->engine()->addImageProvider(QStringLiteral("jdenticon"), jdenticonProvider);
|
|
|
|
view->setSource(QUrl(QStringLiteral("qrc:///qml/Root.qml")));
|
2021-09-18 01:22:33 +03:00
|
|
|
|
|
|
|
connect(parent, &ChatPage::themeChanged, this, &TimelineViewManager::updateColorPalette);
|
2021-12-29 08:10:08 +03:00
|
|
|
connect(parent,
|
2021-09-18 01:22:33 +03:00
|
|
|
&ChatPage::receivedRoomDeviceVerificationRequest,
|
2021-10-15 03:44:48 +03:00
|
|
|
verificationManager_,
|
|
|
|
&VerificationManager::receivedRoomDeviceVerificationRequest);
|
2021-12-29 08:10:08 +03:00
|
|
|
connect(parent,
|
2021-09-18 01:22:33 +03:00
|
|
|
&ChatPage::receivedDeviceVerificationRequest,
|
2021-10-15 03:44:48 +03:00
|
|
|
verificationManager_,
|
|
|
|
&VerificationManager::receivedDeviceVerificationRequest);
|
2021-12-29 08:10:08 +03:00
|
|
|
connect(parent,
|
2021-09-18 01:22:33 +03:00
|
|
|
&ChatPage::receivedDeviceVerificationStart,
|
2021-10-15 03:44:48 +03:00
|
|
|
verificationManager_,
|
|
|
|
&VerificationManager::receivedDeviceVerificationStart);
|
2021-09-18 01:22:33 +03:00
|
|
|
connect(parent, &ChatPage::loggedOut, this, [this]() {
|
|
|
|
isInitialSync_ = true;
|
|
|
|
emit initialSyncChanged(true);
|
|
|
|
});
|
2020-10-27 20:14:06 +03:00
|
|
|
}
|
|
|
|
|
2021-07-22 01:56:20 +03:00
|
|
|
void
|
2021-08-14 00:58:26 +03:00
|
|
|
TimelineViewManager::openRoomMembers(TimelineModel *room)
|
2021-07-22 01:56:20 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (!room)
|
|
|
|
return;
|
|
|
|
MemberList *memberList = new MemberList(room->roomId(), this);
|
|
|
|
emit openRoomMembersDialog(memberList, room);
|
2021-07-22 01:56:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineViewManager::openRoomSettings(QString room_id)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
RoomSettings *settings = new RoomSettings(room_id, this);
|
|
|
|
connect(rooms_->getRoomById(room_id).data(),
|
|
|
|
&TimelineModel::roomAvatarUrlChanged,
|
|
|
|
settings,
|
|
|
|
&RoomSettings::avatarChanged);
|
|
|
|
emit openRoomSettingsDialog(settings);
|
2021-07-22 01:56:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineViewManager::openInviteUsers(QString roomId)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
InviteesModel *model = new InviteesModel{this};
|
|
|
|
connect(model, &InviteesModel::accept, this, [this, model, roomId]() {
|
|
|
|
emit inviteUsers(roomId, model->mxids());
|
|
|
|
});
|
|
|
|
emit openInviteUsersDialog(model);
|
2021-07-22 01:56:20 +03:00
|
|
|
}
|
|
|
|
|
2021-07-22 14:55:12 +03:00
|
|
|
void
|
|
|
|
TimelineViewManager::openGlobalUserProfile(QString userId)
|
2021-07-22 03:38:18 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
UserProfile *profile = new UserProfile{QString{}, userId, this};
|
|
|
|
emit openProfile(profile);
|
2021-07-22 03:38:18 +03:00
|
|
|
}
|
|
|
|
|
2020-10-27 20:14:06 +03:00
|
|
|
void
|
|
|
|
TimelineViewManager::setVideoCallItem()
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
WebRTCSession::instance().setVideoItem(
|
2021-12-29 06:28:08 +03:00
|
|
|
view->rootObject()->findChild<QQuickItem *>(QStringLiteral("videoCallItem")));
|
2017-11-15 19:38:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-11-21 00:48:04 +03:00
|
|
|
TimelineViewManager::sync(const mtx::responses::Sync &sync_)
|
2021-05-19 20:34:10 +03:00
|
|
|
{
|
2021-11-21 00:48:04 +03:00
|
|
|
this->rooms_->sync(sync_);
|
|
|
|
this->communities_->sync(sync_);
|
2021-12-30 06:54:03 +03:00
|
|
|
this->presenceEmitter->sync(sync_.presence);
|
2017-09-03 11:43:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
if (isInitialSync_) {
|
|
|
|
this->isInitialSync_ = false;
|
|
|
|
emit initialSyncChanged(false);
|
|
|
|
}
|
2017-04-13 04:11:22 +03:00
|
|
|
}
|
|
|
|
|
2021-04-29 20:09:16 +03:00
|
|
|
void
|
|
|
|
TimelineViewManager::showEvent(const QString &room_id, const QString &event_id)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (auto room = rooms_->getRoomById(room_id)) {
|
|
|
|
if (rooms_->currentRoom() != room) {
|
|
|
|
rooms_->setCurrentRoom(room_id);
|
|
|
|
container->setFocus();
|
|
|
|
nhlog::ui()->info("Activated room {}", room_id.toStdString());
|
2021-04-29 20:09:16 +03:00
|
|
|
}
|
2021-09-18 01:22:33 +03:00
|
|
|
|
|
|
|
room->showEvent(event_id);
|
|
|
|
}
|
2021-04-29 20:09:16 +03:00
|
|
|
}
|
|
|
|
|
2020-09-03 20:51:50 +03:00
|
|
|
QString
|
|
|
|
TimelineViewManager::escapeEmoji(QString str) const
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
return utils::replaceEmoji(str);
|
2020-09-03 20:51:50 +03:00
|
|
|
}
|
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
void
|
2022-01-02 23:46:29 +03:00
|
|
|
TimelineViewManager::openImageOverlay(TimelineModel *room, QString mxcUrl, QString eventId)
|
2017-09-10 12:58:00 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (mxcUrl.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-05 14:58:00 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
emit showImageOverlay(room, eventId, mxcUrl);
|
2021-04-05 14:58:00 +03:00
|
|
|
}
|
|
|
|
|
2021-07-21 14:37:57 +03:00
|
|
|
void
|
|
|
|
TimelineViewManager::openImagePackSettings(QString roomid)
|
|
|
|
{
|
2021-12-14 01:25:42 +03:00
|
|
|
auto room = rooms_->getRoomById(roomid).get();
|
|
|
|
emit showImagePackSettings(room, new ImagePackListModel(roomid.toStdString(), this));
|
2021-07-21 14:37:57 +03:00
|
|
|
}
|
|
|
|
|
2021-04-05 14:58:00 +03:00
|
|
|
void
|
2022-01-02 23:46:29 +03:00
|
|
|
TimelineViewManager::saveMedia(QString mxcUrl)
|
2021-04-05 14:58:00 +03:00
|
|
|
{
|
2022-01-02 23:46:29 +03:00
|
|
|
const QString downloadsFolder =
|
|
|
|
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
|
|
|
const QString openLocation = downloadsFolder + "/" + mxcUrl.splitRef(u'/').constLast();
|
2021-04-05 14:58:00 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
const QString filename = QFileDialog::getSaveFileName(getWidget(), {}, openLocation);
|
2021-05-28 23:14:59 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
2021-06-11 22:25:06 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
const auto url = mxcUrl.toStdString();
|
|
|
|
|
|
|
|
http::client()->download(url,
|
|
|
|
[filename, url](const std::string &data,
|
|
|
|
const std::string &,
|
|
|
|
const std::string &,
|
|
|
|
mtx::http::RequestErr err) {
|
|
|
|
if (err) {
|
|
|
|
nhlog::net()->warn("failed to retrieve image {}: {} {}",
|
|
|
|
url,
|
|
|
|
err->matrix_error.error,
|
|
|
|
static_cast<int>(err->status_code));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
QFile file(filename);
|
|
|
|
|
|
|
|
if (!file.open(QIODevice::WriteOnly))
|
|
|
|
return;
|
|
|
|
|
|
|
|
file.write(QByteArray(data.data(), (int)data.size()));
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
return;
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
nhlog::ui()->warn("Error while saving file to: {}", e.what());
|
|
|
|
}
|
|
|
|
});
|
2017-12-01 18:33:49 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
2019-11-09 05:06:10 +03:00
|
|
|
TimelineViewManager::updateReadReceipts(const QString &room_id,
|
|
|
|
const std::vector<QString> &event_ids)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (auto room = rooms_->getRoomById(room_id)) {
|
|
|
|
room->markEventsAsRead(event_ids);
|
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2020-10-20 20:46:37 +03:00
|
|
|
void
|
|
|
|
TimelineViewManager::receivedSessionKey(const std::string &room_id, const std::string &session_id)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (auto room = rooms_->getRoomById(QString::fromStdString(room_id))) {
|
|
|
|
room->receivedSessionKey(session_id);
|
|
|
|
}
|
2020-10-20 20:46:37 +03:00
|
|
|
}
|
|
|
|
|
2018-06-28 16:16:43 +03:00
|
|
|
void
|
2021-05-24 15:04:07 +03:00
|
|
|
TimelineViewManager::initializeRoomlist()
|
2018-06-28 16:16:43 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
rooms_->initializeRooms();
|
|
|
|
communities_->initializeSidebar();
|
2018-06-28 16:16:43 +03:00
|
|
|
}
|
|
|
|
|
2021-01-07 12:44:59 +03:00
|
|
|
void
|
|
|
|
TimelineViewManager::queueReply(const QString &roomid,
|
|
|
|
const QString &repliedToEvent,
|
|
|
|
const QString &replyBody)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (auto room = rooms_->getRoomById(roomid)) {
|
|
|
|
room->setReply(repliedToEvent);
|
|
|
|
room->input()->message(replyBody);
|
|
|
|
}
|
2021-01-07 12:44:59 +03:00
|
|
|
}
|
|
|
|
|
2020-07-11 02:19:48 +03:00
|
|
|
void
|
|
|
|
TimelineViewManager::queueCallMessage(const QString &roomid,
|
|
|
|
const mtx::events::msg::CallInvite &callInvite)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (auto room = rooms_->getRoomById(roomid))
|
|
|
|
room->sendMessageEvent(callInvite, mtx::events::EventType::CallInvite);
|
2020-07-11 02:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineViewManager::queueCallMessage(const QString &roomid,
|
|
|
|
const mtx::events::msg::CallCandidates &callCandidates)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (auto room = rooms_->getRoomById(roomid))
|
|
|
|
room->sendMessageEvent(callCandidates, mtx::events::EventType::CallCandidates);
|
2020-07-11 02:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineViewManager::queueCallMessage(const QString &roomid,
|
|
|
|
const mtx::events::msg::CallAnswer &callAnswer)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (auto room = rooms_->getRoomById(roomid))
|
|
|
|
room->sendMessageEvent(callAnswer, mtx::events::EventType::CallAnswer);
|
2020-07-11 02:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineViewManager::queueCallMessage(const QString &roomid,
|
|
|
|
const mtx::events::msg::CallHangUp &callHangUp)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (auto room = rooms_->getRoomById(roomid))
|
|
|
|
room->sendMessageEvent(callHangUp, mtx::events::EventType::CallHangUp);
|
2017-10-07 20:50:32 +03:00
|
|
|
}
|
2021-02-05 20:12:08 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
TimelineViewManager::focusMessageInput()
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
emit focusInput();
|
2021-02-14 03:28:28 +03:00
|
|
|
}
|
2021-02-21 20:40:21 +03:00
|
|
|
|
|
|
|
QObject *
|
|
|
|
TimelineViewManager::completerFor(QString completerName, QString roomId)
|
|
|
|
{
|
2021-12-29 06:28:08 +03:00
|
|
|
if (completerName == QLatin1String("user")) {
|
2021-09-18 01:22:33 +03:00
|
|
|
auto userModel = new UsersModel(roomId.toStdString());
|
|
|
|
auto proxy = new CompletionProxyModel(userModel);
|
|
|
|
userModel->setParent(proxy);
|
|
|
|
return proxy;
|
2021-12-29 06:28:08 +03:00
|
|
|
} else if (completerName == QLatin1String("emoji")) {
|
2021-09-18 01:22:33 +03:00
|
|
|
auto emojiModel = new emoji::EmojiModel();
|
|
|
|
auto proxy = new CompletionProxyModel(emojiModel);
|
|
|
|
emojiModel->setParent(proxy);
|
|
|
|
return proxy;
|
2021-12-29 06:28:08 +03:00
|
|
|
} else if (completerName == QLatin1String("allemoji")) {
|
2021-09-18 01:22:33 +03:00
|
|
|
auto emojiModel = new emoji::EmojiModel();
|
|
|
|
auto proxy = new CompletionProxyModel(emojiModel, 1, static_cast<size_t>(-1) / 4);
|
|
|
|
emojiModel->setParent(proxy);
|
|
|
|
return proxy;
|
2021-12-29 06:28:08 +03:00
|
|
|
} else if (completerName == QLatin1String("room")) {
|
2021-09-18 01:22:33 +03:00
|
|
|
auto roomModel = new RoomsModel(false);
|
|
|
|
auto proxy = new CompletionProxyModel(roomModel, 4);
|
|
|
|
roomModel->setParent(proxy);
|
|
|
|
return proxy;
|
2021-12-29 06:28:08 +03:00
|
|
|
} else if (completerName == QLatin1String("roomAliases")) {
|
2021-09-18 01:22:33 +03:00
|
|
|
auto roomModel = new RoomsModel(true);
|
|
|
|
auto proxy = new CompletionProxyModel(roomModel);
|
|
|
|
roomModel->setParent(proxy);
|
|
|
|
return proxy;
|
2021-12-29 06:28:08 +03:00
|
|
|
} else if (completerName == QLatin1String("stickers")) {
|
2021-09-18 01:22:33 +03:00
|
|
|
auto stickerModel = new CombinedImagePackModel(roomId.toStdString(), true);
|
|
|
|
auto proxy = new CompletionProxyModel(stickerModel, 1, static_cast<size_t>(-1) / 4);
|
|
|
|
stickerModel->setParent(proxy);
|
|
|
|
return proxy;
|
2021-12-29 06:28:08 +03:00
|
|
|
} else if (completerName == QLatin1String("customEmoji")) {
|
2021-12-27 08:23:36 +03:00
|
|
|
auto stickerModel = new CombinedImagePackModel(roomId.toStdString(), false);
|
|
|
|
auto proxy = new CompletionProxyModel(stickerModel);
|
|
|
|
stickerModel->setParent(proxy);
|
|
|
|
return proxy;
|
2021-09-18 01:22:33 +03:00
|
|
|
}
|
|
|
|
return nullptr;
|
2021-02-22 22:16:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineViewManager::focusTimeline()
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
getWidget()->setFocus();
|
2021-04-05 14:58:00 +03:00
|
|
|
}
|
2021-04-11 17:31:49 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEvents *e,
|
2021-04-17 20:28:04 +03:00
|
|
|
QString roomId)
|
2021-04-11 17:31:49 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
auto room = rooms_->getRoomById(roomId);
|
|
|
|
auto content = mtx::accessors::url(*e);
|
|
|
|
std::optional<mtx::crypto::EncryptedFile> encryptionInfo = mtx::accessors::file(*e);
|
|
|
|
|
|
|
|
if (encryptionInfo) {
|
|
|
|
http::client()->download(
|
|
|
|
content,
|
|
|
|
[this, roomId, e, encryptionInfo](const std::string &res,
|
|
|
|
const std::string &content_type,
|
|
|
|
const std::string &originalFilename,
|
|
|
|
mtx::http::RequestErr err) {
|
|
|
|
if (err)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto data =
|
|
|
|
mtx::crypto::to_string(mtx::crypto::decrypt_file(res, encryptionInfo.value()));
|
|
|
|
|
|
|
|
http::client()->upload(
|
|
|
|
data,
|
|
|
|
content_type,
|
|
|
|
originalFilename,
|
|
|
|
[this, roomId, e](const mtx::responses::ContentURI &res,
|
|
|
|
mtx::http::RequestErr err) mutable {
|
|
|
|
if (err) {
|
|
|
|
nhlog::net()->warn("failed to upload media: {} {} ({})",
|
|
|
|
err->matrix_error.error,
|
|
|
|
to_string(err->matrix_error.errcode),
|
|
|
|
static_cast<int>(err->status_code));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::visit(
|
|
|
|
[this, roomId, url = res.content_uri](auto ev) {
|
|
|
|
using namespace mtx::events;
|
|
|
|
if constexpr (EventType::RoomMessage ==
|
|
|
|
message_content_to_type<decltype(ev.content)> ||
|
|
|
|
EventType::Sticker ==
|
|
|
|
message_content_to_type<decltype(ev.content)>) {
|
|
|
|
if constexpr (messageWithFileAndUrl(ev)) {
|
|
|
|
ev.content.relations.relations.clear();
|
|
|
|
ev.content.file.reset();
|
|
|
|
ev.content.url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto room = rooms_->getRoomById(roomId)) {
|
|
|
|
removeReplyFallback(ev);
|
|
|
|
ev.content.relations.relations.clear();
|
|
|
|
room->sendMessageEvent(ev.content,
|
|
|
|
mtx::events::EventType::RoomMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
*e);
|
|
|
|
});
|
2021-04-17 19:58:17 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
return;
|
|
|
|
});
|
2021-04-17 19:58:17 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
return;
|
|
|
|
}
|
2021-04-11 17:31:49 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
std::visit(
|
|
|
|
[room](auto e) {
|
|
|
|
if constexpr (mtx::events::message_content_to_type<decltype(e.content)> ==
|
|
|
|
mtx::events::EventType::RoomMessage) {
|
|
|
|
e.content.relations.relations.clear();
|
|
|
|
removeReplyFallback(e);
|
|
|
|
room->sendMessageEvent(e.content, mtx::events::EventType::RoomMessage);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
*e);
|
2021-04-27 12:33:46 +03:00
|
|
|
}
|
2021-07-15 01:26:39 +03:00
|
|
|
|
|
|
|
//! WORKAROUND(Nico): for https://bugreports.qt.io/browse/QTBUG-93281
|
|
|
|
void
|
|
|
|
TimelineViewManager::fixImageRendering(QQuickTextDocument *t, QQuickItem *i)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (t) {
|
|
|
|
QObject::connect(t->textDocument(), SIGNAL(imagesLoaded()), i, SLOT(updateWholeDocument()));
|
|
|
|
}
|
2021-07-15 01:26:39 +03:00
|
|
|
}
|