2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2019-08-31 00:20:53 +03:00
|
|
|
#include "TimelineModel.h"
|
|
|
|
|
2019-09-09 22:42:33 +03:00
|
|
|
#include <algorithm>
|
2020-01-25 03:06:01 +03:00
|
|
|
#include <thread>
|
2019-09-03 00:28:05 +03:00
|
|
|
#include <type_traits>
|
|
|
|
|
2020-04-14 21:15:11 +03:00
|
|
|
#include <QCache>
|
2021-04-29 22:46:49 +03:00
|
|
|
#include <QClipboard>
|
2021-01-24 03:29:30 +03:00
|
|
|
#include <QDesktopServices>
|
2019-12-03 04:26:41 +03:00
|
|
|
#include <QFileDialog>
|
2021-04-29 22:46:49 +03:00
|
|
|
#include <QGuiApplication>
|
2019-12-03 04:26:41 +03:00
|
|
|
#include <QMimeDatabase>
|
2019-09-01 23:58:26 +03:00
|
|
|
#include <QRegularExpression>
|
2020-04-22 04:42:17 +03:00
|
|
|
#include <QSettings>
|
2019-12-03 04:26:41 +03:00
|
|
|
#include <QStandardPaths>
|
2019-09-01 23:58:26 +03:00
|
|
|
|
2021-04-29 22:46:49 +03:00
|
|
|
#include "Cache_p.h"
|
2019-09-11 01:54:40 +03:00
|
|
|
#include "ChatPage.h"
|
2021-03-15 22:59:18 +03:00
|
|
|
#include "Config.h"
|
2019-12-27 23:49:55 +03:00
|
|
|
#include "EventAccessors.h"
|
2019-08-31 23:43:31 +03:00
|
|
|
#include "Logging.h"
|
2019-09-19 00:37:30 +03:00
|
|
|
#include "MainWindow.h"
|
2019-12-15 05:19:33 +03:00
|
|
|
#include "MatrixClient.h"
|
2019-12-03 04:26:41 +03:00
|
|
|
#include "MxcImageProvider.h"
|
2019-09-08 17:50:32 +03:00
|
|
|
#include "Olm.h"
|
2019-10-03 19:07:01 +03:00
|
|
|
#include "TimelineViewManager.h"
|
2019-08-31 00:20:53 +03:00
|
|
|
#include "Utils.h"
|
2019-09-08 16:26:46 +03:00
|
|
|
#include "dialogs/RawMessage.h"
|
2019-08-31 00:20:53 +03:00
|
|
|
|
2019-11-05 19:16:04 +03:00
|
|
|
Q_DECLARE_METATYPE(QModelIndex)
|
|
|
|
|
2020-04-14 21:15:11 +03:00
|
|
|
namespace std {
|
|
|
|
inline uint
|
|
|
|
qHash(const std::string &key, uint seed = 0)
|
|
|
|
{
|
2020-12-25 03:08:06 +03:00
|
|
|
return qHash(QByteArray::fromRawData(key.data(), (int)key.length()), seed);
|
2020-04-14 21:15:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-31 23:43:31 +03:00
|
|
|
namespace {
|
2019-12-27 23:49:55 +03:00
|
|
|
struct RoomEventType
|
2019-09-03 00:28:05 +03:00
|
|
|
{
|
2019-12-27 23:49:55 +03:00
|
|
|
template<class T>
|
|
|
|
qml_mtx_events::EventType operator()(const mtx::events::Event<T> &e)
|
|
|
|
{
|
|
|
|
using mtx::events::EventType;
|
|
|
|
switch (e.type) {
|
|
|
|
case EventType::RoomKeyRequest:
|
|
|
|
return qml_mtx_events::EventType::KeyRequest;
|
2020-05-06 13:52:13 +03:00
|
|
|
case EventType::Reaction:
|
|
|
|
return qml_mtx_events::EventType::Reaction;
|
2019-12-27 23:49:55 +03:00
|
|
|
case EventType::RoomAliases:
|
|
|
|
return qml_mtx_events::EventType::Aliases;
|
|
|
|
case EventType::RoomAvatar:
|
|
|
|
return qml_mtx_events::EventType::Avatar;
|
|
|
|
case EventType::RoomCanonicalAlias:
|
|
|
|
return qml_mtx_events::EventType::CanonicalAlias;
|
|
|
|
case EventType::RoomCreate:
|
2020-02-29 03:27:51 +03:00
|
|
|
return qml_mtx_events::EventType::RoomCreate;
|
2019-12-27 23:49:55 +03:00
|
|
|
case EventType::RoomEncrypted:
|
|
|
|
return qml_mtx_events::EventType::Encrypted;
|
|
|
|
case EventType::RoomEncryption:
|
|
|
|
return qml_mtx_events::EventType::Encryption;
|
|
|
|
case EventType::RoomGuestAccess:
|
2020-02-29 03:27:51 +03:00
|
|
|
return qml_mtx_events::EventType::RoomGuestAccess;
|
2019-12-27 23:49:55 +03:00
|
|
|
case EventType::RoomHistoryVisibility:
|
2020-02-29 03:27:51 +03:00
|
|
|
return qml_mtx_events::EventType::RoomHistoryVisibility;
|
2019-12-27 23:49:55 +03:00
|
|
|
case EventType::RoomJoinRules:
|
2020-02-29 03:27:51 +03:00
|
|
|
return qml_mtx_events::EventType::RoomJoinRules;
|
2019-12-27 23:49:55 +03:00
|
|
|
case EventType::RoomMember:
|
|
|
|
return qml_mtx_events::EventType::Member;
|
|
|
|
case EventType::RoomMessage:
|
|
|
|
return qml_mtx_events::EventType::UnknownMessage;
|
|
|
|
case EventType::RoomName:
|
|
|
|
return qml_mtx_events::EventType::Name;
|
|
|
|
case EventType::RoomPowerLevels:
|
|
|
|
return qml_mtx_events::EventType::PowerLevels;
|
|
|
|
case EventType::RoomTopic:
|
|
|
|
return qml_mtx_events::EventType::Topic;
|
|
|
|
case EventType::RoomTombstone:
|
|
|
|
return qml_mtx_events::EventType::Tombstone;
|
|
|
|
case EventType::RoomRedaction:
|
|
|
|
return qml_mtx_events::EventType::Redaction;
|
|
|
|
case EventType::RoomPinnedEvents:
|
|
|
|
return qml_mtx_events::EventType::PinnedEvents;
|
|
|
|
case EventType::Sticker:
|
|
|
|
return qml_mtx_events::EventType::Sticker;
|
|
|
|
case EventType::Tag:
|
|
|
|
return qml_mtx_events::EventType::Tag;
|
|
|
|
case EventType::Unsupported:
|
|
|
|
return qml_mtx_events::EventType::Unsupported;
|
2020-01-11 20:53:32 +03:00
|
|
|
default:
|
|
|
|
return qml_mtx_events::EventType::UnknownMessage;
|
2019-12-27 23:49:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Audio> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::AudioMessage;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Emote> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::EmoteMessage;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::File> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::FileMessage;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Image> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::ImageMessage;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Notice> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::NoticeMessage;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Text> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::TextMessage;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Video> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::VideoMessage;
|
2019-10-04 02:10:46 +03:00
|
|
|
}
|
2020-07-17 23:16:30 +03:00
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::KeyVerificationRequest> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::KeyVerificationRequest;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::KeyVerificationStart> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::KeyVerificationStart;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::KeyVerificationMac> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::KeyVerificationMac;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::KeyVerificationAccept> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::KeyVerificationAccept;
|
|
|
|
}
|
2020-07-29 00:55:47 +03:00
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::KeyVerificationReady> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::KeyVerificationReady;
|
|
|
|
}
|
2020-07-17 23:16:30 +03:00
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::KeyVerificationCancel> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::KeyVerificationCancel;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::KeyVerificationKey> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::KeyVerificationKey;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::KeyVerificationDone> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::KeyVerificationDone;
|
|
|
|
}
|
2019-12-27 23:49:55 +03:00
|
|
|
qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Redacted> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::Redacted;
|
2019-09-03 00:28:05 +03:00
|
|
|
}
|
2020-07-11 02:19:48 +03:00
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::CallInvite> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::CallInvite;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::CallAnswer> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::CallAnswer;
|
|
|
|
}
|
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::CallHangUp> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::CallHangUp;
|
|
|
|
}
|
2020-08-18 00:30:36 +03:00
|
|
|
qml_mtx_events::EventType operator()(
|
|
|
|
const mtx::events::Event<mtx::events::msg::CallCandidates> &)
|
|
|
|
{
|
|
|
|
return qml_mtx_events::EventType::CallCandidates;
|
|
|
|
}
|
2019-12-27 23:49:55 +03:00
|
|
|
// ::EventType::Type operator()(const Event<mtx::events::msg::Location> &e) { return
|
|
|
|
// ::EventType::LocationMessage; }
|
|
|
|
};
|
2019-09-03 00:28:05 +03:00
|
|
|
}
|
2019-09-09 22:42:33 +03:00
|
|
|
|
|
|
|
qml_mtx_events::EventType
|
2019-12-27 23:49:55 +03:00
|
|
|
toRoomEventType(const mtx::events::collections::TimelineEvents &event)
|
2019-09-08 13:44:46 +03:00
|
|
|
{
|
2019-12-27 23:49:55 +03:00
|
|
|
return std::visit(RoomEventType{}, event);
|
2019-08-31 23:43:31 +03:00
|
|
|
}
|
|
|
|
|
2020-01-23 22:59:17 +03:00
|
|
|
QString
|
|
|
|
toRoomEventTypeString(const mtx::events::collections::TimelineEvents &event)
|
|
|
|
{
|
|
|
|
return std::visit([](const auto &e) { return QString::fromStdString(to_string(e.type)); },
|
|
|
|
event);
|
|
|
|
}
|
|
|
|
|
2021-05-02 19:01:18 +03:00
|
|
|
mtx::events::EventType
|
|
|
|
qml_mtx_events::fromRoomEventType(qml_mtx_events::EventType t)
|
|
|
|
{
|
|
|
|
switch (t) {
|
|
|
|
// Unsupported event
|
|
|
|
case qml_mtx_events::Unsupported:
|
|
|
|
return mtx::events::EventType::Unsupported;
|
|
|
|
|
|
|
|
/// m.room_key_request
|
|
|
|
case qml_mtx_events::KeyRequest:
|
|
|
|
return mtx::events::EventType::RoomKeyRequest;
|
|
|
|
/// m.reaction:
|
|
|
|
case qml_mtx_events::Reaction:
|
|
|
|
return mtx::events::EventType::Reaction;
|
|
|
|
/// m.room.aliases
|
|
|
|
case qml_mtx_events::Aliases:
|
|
|
|
return mtx::events::EventType::RoomAliases;
|
|
|
|
/// m.room.avatar
|
|
|
|
case qml_mtx_events::Avatar:
|
|
|
|
return mtx::events::EventType::RoomAvatar;
|
|
|
|
/// m.call.invite
|
|
|
|
case qml_mtx_events::CallInvite:
|
|
|
|
return mtx::events::EventType::CallInvite;
|
|
|
|
/// m.call.answer
|
|
|
|
case qml_mtx_events::CallAnswer:
|
|
|
|
return mtx::events::EventType::CallAnswer;
|
|
|
|
/// m.call.hangup
|
|
|
|
case qml_mtx_events::CallHangUp:
|
|
|
|
return mtx::events::EventType::CallHangUp;
|
|
|
|
/// m.call.candidates
|
|
|
|
case qml_mtx_events::CallCandidates:
|
|
|
|
return mtx::events::EventType::CallCandidates;
|
|
|
|
/// m.room.canonical_alias
|
|
|
|
case qml_mtx_events::CanonicalAlias:
|
|
|
|
return mtx::events::EventType::RoomCanonicalAlias;
|
|
|
|
/// m.room.create
|
|
|
|
case qml_mtx_events::RoomCreate:
|
|
|
|
return mtx::events::EventType::RoomCreate;
|
|
|
|
/// m.room.encrypted.
|
|
|
|
case qml_mtx_events::Encrypted:
|
|
|
|
return mtx::events::EventType::RoomEncrypted;
|
|
|
|
/// m.room.encryption.
|
|
|
|
case qml_mtx_events::Encryption:
|
|
|
|
return mtx::events::EventType::RoomEncryption;
|
|
|
|
/// m.room.guest_access
|
|
|
|
case qml_mtx_events::RoomGuestAccess:
|
|
|
|
return mtx::events::EventType::RoomGuestAccess;
|
|
|
|
/// m.room.history_visibility
|
|
|
|
case qml_mtx_events::RoomHistoryVisibility:
|
|
|
|
return mtx::events::EventType::RoomHistoryVisibility;
|
|
|
|
/// m.room.join_rules
|
|
|
|
case qml_mtx_events::RoomJoinRules:
|
|
|
|
return mtx::events::EventType::RoomJoinRules;
|
|
|
|
/// m.room.member
|
|
|
|
case qml_mtx_events::Member:
|
|
|
|
return mtx::events::EventType::RoomMember;
|
|
|
|
/// m.room.name
|
|
|
|
case qml_mtx_events::Name:
|
|
|
|
return mtx::events::EventType::RoomName;
|
|
|
|
/// m.room.power_levels
|
|
|
|
case qml_mtx_events::PowerLevels:
|
|
|
|
return mtx::events::EventType::RoomPowerLevels;
|
|
|
|
/// m.room.tombstone
|
|
|
|
case qml_mtx_events::Tombstone:
|
|
|
|
return mtx::events::EventType::RoomTombstone;
|
|
|
|
/// m.room.topic
|
|
|
|
case qml_mtx_events::Topic:
|
|
|
|
return mtx::events::EventType::RoomTopic;
|
|
|
|
/// m.room.redaction
|
|
|
|
case qml_mtx_events::Redaction:
|
|
|
|
return mtx::events::EventType::RoomRedaction;
|
|
|
|
/// m.room.pinned_events
|
|
|
|
case qml_mtx_events::PinnedEvents:
|
|
|
|
return mtx::events::EventType::RoomPinnedEvents;
|
|
|
|
// m.sticker
|
|
|
|
case qml_mtx_events::Sticker:
|
|
|
|
return mtx::events::EventType::Sticker;
|
|
|
|
// m.tag
|
|
|
|
case qml_mtx_events::Tag:
|
|
|
|
return mtx::events::EventType::Tag;
|
|
|
|
/// m.room.message
|
|
|
|
case qml_mtx_events::AudioMessage:
|
|
|
|
case qml_mtx_events::EmoteMessage:
|
|
|
|
case qml_mtx_events::FileMessage:
|
|
|
|
case qml_mtx_events::ImageMessage:
|
|
|
|
case qml_mtx_events::LocationMessage:
|
|
|
|
case qml_mtx_events::NoticeMessage:
|
|
|
|
case qml_mtx_events::TextMessage:
|
|
|
|
case qml_mtx_events::VideoMessage:
|
|
|
|
case qml_mtx_events::Redacted:
|
|
|
|
case qml_mtx_events::UnknownMessage:
|
|
|
|
case qml_mtx_events::KeyVerificationRequest:
|
|
|
|
case qml_mtx_events::KeyVerificationStart:
|
|
|
|
case qml_mtx_events::KeyVerificationMac:
|
|
|
|
case qml_mtx_events::KeyVerificationAccept:
|
|
|
|
case qml_mtx_events::KeyVerificationCancel:
|
|
|
|
case qml_mtx_events::KeyVerificationKey:
|
|
|
|
case qml_mtx_events::KeyVerificationDone:
|
|
|
|
case qml_mtx_events::KeyVerificationReady:
|
|
|
|
return mtx::events::EventType::RoomMessage;
|
|
|
|
default:
|
|
|
|
return mtx::events::EventType::Unsupported;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:07:01 +03:00
|
|
|
TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObject *parent)
|
2019-09-01 00:44:17 +03:00
|
|
|
: QAbstractListModel(parent)
|
2020-07-10 00:15:22 +03:00
|
|
|
, events(room_id.toStdString(), this)
|
2019-09-01 00:44:17 +03:00
|
|
|
, room_id_(room_id)
|
2019-10-03 19:07:01 +03:00
|
|
|
, manager_(manager)
|
2019-09-01 00:44:17 +03:00
|
|
|
{
|
2021-05-22 01:57:14 +03:00
|
|
|
lastMessage_.timestamp = 0;
|
|
|
|
|
2021-03-05 17:26:07 +03:00
|
|
|
connect(
|
|
|
|
this,
|
|
|
|
&TimelineModel::redactionFailed,
|
|
|
|
this,
|
|
|
|
[](const QString &msg) { emit ChatPage::instance()->showNotification(msg); },
|
|
|
|
Qt::QueuedConnection);
|
2020-01-11 20:53:32 +03:00
|
|
|
|
2020-06-24 15:50:11 +03:00
|
|
|
connect(this,
|
|
|
|
&TimelineModel::newMessageToSend,
|
|
|
|
this,
|
|
|
|
&TimelineModel::addPendingMessage,
|
|
|
|
Qt::QueuedConnection);
|
2020-07-18 18:43:49 +03:00
|
|
|
connect(this, &TimelineModel::addPendingMessageToStore, &events, &EventStore::addPending);
|
2020-06-24 15:50:11 +03:00
|
|
|
|
2021-03-05 17:26:07 +03:00
|
|
|
connect(
|
|
|
|
&events,
|
|
|
|
&EventStore::dataChanged,
|
|
|
|
this,
|
|
|
|
[this](int from, int to) {
|
|
|
|
nhlog::ui()->debug(
|
|
|
|
"data changed {} to {}", events.size() - to - 1, events.size() - from - 1);
|
|
|
|
emit dataChanged(index(events.size() - to - 1, 0),
|
|
|
|
index(events.size() - from - 1, 0));
|
|
|
|
},
|
|
|
|
Qt::QueuedConnection);
|
2020-07-10 00:15:22 +03:00
|
|
|
|
|
|
|
connect(&events, &EventStore::beginInsertRows, this, [this](int from, int to) {
|
2020-07-13 01:08:58 +03:00
|
|
|
int first = events.size() - to;
|
|
|
|
int last = events.size() - from;
|
|
|
|
if (from >= events.size()) {
|
|
|
|
int batch_size = to - from;
|
|
|
|
first += batch_size;
|
|
|
|
last += batch_size;
|
|
|
|
} else {
|
|
|
|
first -= 1;
|
|
|
|
last -= 1;
|
|
|
|
}
|
|
|
|
nhlog::ui()->debug("begin insert from {} to {}", first, last);
|
|
|
|
beginInsertRows(QModelIndex(), first, last);
|
2020-07-10 00:15:22 +03:00
|
|
|
});
|
|
|
|
connect(&events, &EventStore::endInsertRows, this, [this]() { endInsertRows(); });
|
2020-07-13 01:08:58 +03:00
|
|
|
connect(&events, &EventStore::beginResetModel, this, [this]() { beginResetModel(); });
|
|
|
|
connect(&events, &EventStore::endResetModel, this, [this]() { endResetModel(); });
|
2020-07-10 00:15:22 +03:00
|
|
|
connect(&events, &EventStore::newEncryptedImage, this, &TimelineModel::newEncryptedImage);
|
2020-07-13 01:08:58 +03:00
|
|
|
connect(
|
|
|
|
&events, &EventStore::fetchedMore, this, [this]() { setPaginationInProgress(false); });
|
2020-08-09 06:05:15 +03:00
|
|
|
connect(&events,
|
|
|
|
&EventStore::startDMVerification,
|
|
|
|
this,
|
|
|
|
[this](mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> msg) {
|
2020-10-05 23:12:10 +03:00
|
|
|
ChatPage::instance()->receivedRoomDeviceVerificationRequest(msg, this);
|
2020-08-09 06:05:15 +03:00
|
|
|
});
|
2020-08-18 08:59:02 +03:00
|
|
|
connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) {
|
|
|
|
this->updateFlowEventId(event_id);
|
|
|
|
});
|
2021-04-29 20:09:16 +03:00
|
|
|
|
|
|
|
showEventTimer.callOnTimeout(this, &TimelineModel::scrollTimerEvent);
|
2019-09-01 00:44:17 +03:00
|
|
|
}
|
|
|
|
|
2019-08-31 00:20:53 +03:00
|
|
|
QHash<int, QByteArray>
|
|
|
|
TimelineModel::roleNames() const
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
{Type, "type"},
|
2020-01-23 22:59:17 +03:00
|
|
|
{TypeString, "typeString"},
|
2020-05-19 22:04:38 +03:00
|
|
|
{IsOnlyEmoji, "isOnlyEmoji"},
|
2019-08-31 00:20:53 +03:00
|
|
|
{Body, "body"},
|
|
|
|
{FormattedBody, "formattedBody"},
|
2021-01-20 01:58:25 +03:00
|
|
|
{PreviousMessageUserId, "previousMessageUserId"},
|
2021-05-02 19:01:18 +03:00
|
|
|
{IsSender, "isSender"},
|
2019-08-31 00:20:53 +03:00
|
|
|
{UserId, "userId"},
|
|
|
|
{UserName, "userName"},
|
2021-01-20 01:58:25 +03:00
|
|
|
{PreviousMessageDay, "previousMessageDay"},
|
|
|
|
{Day, "day"},
|
2019-08-31 00:20:53 +03:00
|
|
|
{Timestamp, "timestamp"},
|
2019-09-08 13:44:46 +03:00
|
|
|
{Url, "url"},
|
2019-10-09 01:36:03 +03:00
|
|
|
{ThumbnailUrl, "thumbnailUrl"},
|
2020-03-01 21:55:43 +03:00
|
|
|
{Blurhash, "blurhash"},
|
2019-09-29 11:45:35 +03:00
|
|
|
{Filename, "filename"},
|
2019-10-04 02:10:46 +03:00
|
|
|
{Filesize, "filesize"},
|
2019-09-29 11:45:35 +03:00
|
|
|
{MimeType, "mimetype"},
|
2019-09-08 13:44:46 +03:00
|
|
|
{Height, "height"},
|
|
|
|
{Width, "width"},
|
|
|
|
{ProportionalHeight, "proportionalHeight"},
|
2019-09-08 16:26:46 +03:00
|
|
|
{Id, "id"},
|
2019-09-18 23:58:25 +03:00
|
|
|
{State, "state"},
|
2021-02-01 00:41:43 +03:00
|
|
|
{IsEdited, "isEdited"},
|
|
|
|
{IsEditable, "isEditable"},
|
2019-09-20 00:02:56 +03:00
|
|
|
{IsEncrypted, "isEncrypted"},
|
2021-05-07 13:19:46 +03:00
|
|
|
{Trustlevel, "trustlevel"},
|
2020-05-15 03:35:29 +03:00
|
|
|
{IsRoomEncrypted, "isRoomEncrypted"},
|
2019-11-05 19:16:04 +03:00
|
|
|
{ReplyTo, "replyTo"},
|
2020-05-04 14:14:54 +03:00
|
|
|
{Reactions, "reactions"},
|
2020-02-29 03:27:51 +03:00
|
|
|
{RoomId, "roomId"},
|
2019-12-10 16:46:52 +03:00
|
|
|
{RoomName, "roomName"},
|
|
|
|
{RoomTopic, "roomTopic"},
|
2020-07-24 20:30:12 +03:00
|
|
|
{CallType, "callType"},
|
2020-01-04 01:21:33 +03:00
|
|
|
{Dump, "dump"},
|
2019-08-31 00:20:53 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
int
|
|
|
|
TimelineModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
2020-07-18 18:43:49 +03:00
|
|
|
return this->events.size();
|
2019-08-31 00:20:53 +03:00
|
|
|
}
|
|
|
|
|
2020-01-11 16:07:51 +03:00
|
|
|
QVariantMap
|
2020-07-10 00:15:22 +03:00
|
|
|
TimelineModel::getDump(QString eventId, QString relatedTo) const
|
2020-01-11 16:07:51 +03:00
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
if (auto event = events.get(eventId.toStdString(), relatedTo.toStdString()))
|
2020-07-10 00:15:22 +03:00
|
|
|
return data(*event, Dump).toMap();
|
2020-01-11 16:07:51 +03:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-08-31 00:20:53 +03:00
|
|
|
QVariant
|
2020-07-10 00:15:22 +03:00
|
|
|
TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int role) const
|
2019-08-31 00:20:53 +03:00
|
|
|
{
|
2019-12-27 23:49:55 +03:00
|
|
|
using namespace mtx::accessors;
|
2020-07-10 00:15:22 +03:00
|
|
|
namespace acc = mtx::accessors;
|
2019-09-08 17:50:32 +03:00
|
|
|
|
2019-08-31 00:20:53 +03:00
|
|
|
switch (role) {
|
2021-05-02 19:01:18 +03:00
|
|
|
case IsSender:
|
|
|
|
return QVariant(acc::sender(event) == http::client()->user_id().to_string());
|
2019-08-31 00:20:53 +03:00
|
|
|
case UserId:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(QString::fromStdString(acc::sender(event)));
|
2019-09-01 15:17:33 +03:00
|
|
|
case UserName:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(displayName(QString::fromStdString(acc::sender(event))));
|
2019-09-01 15:17:33 +03:00
|
|
|
|
2021-01-20 01:58:25 +03:00
|
|
|
case Day: {
|
|
|
|
QDateTime prevDate = origin_server_ts(event);
|
|
|
|
prevDate.setTime(QTime());
|
|
|
|
return QVariant(prevDate.toMSecsSinceEpoch());
|
|
|
|
}
|
2019-09-01 15:17:33 +03:00
|
|
|
case Timestamp:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(origin_server_ts(event));
|
2019-09-03 00:28:05 +03:00
|
|
|
case Type:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(toRoomEventType(event));
|
2020-01-23 22:59:17 +03:00
|
|
|
case TypeString:
|
|
|
|
return QVariant(toRoomEventTypeString(event));
|
2020-05-19 22:04:38 +03:00
|
|
|
case IsOnlyEmoji: {
|
|
|
|
QString qBody = QString::fromStdString(body(event));
|
|
|
|
|
|
|
|
QVector<uint> utf32_string = qBody.toUcs4();
|
|
|
|
int emojiCount = 0;
|
|
|
|
|
|
|
|
for (auto &code : utf32_string) {
|
|
|
|
if (utils::codepointIsEmoji(code)) {
|
|
|
|
emojiCount++;
|
|
|
|
} else {
|
|
|
|
return QVariant(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant(emojiCount);
|
|
|
|
}
|
2019-09-11 01:54:40 +03:00
|
|
|
case Body:
|
2021-01-22 19:03:03 +03:00
|
|
|
return QVariant(
|
|
|
|
utils::replaceEmoji(QString::fromStdString(body(event)).toHtmlEscaped()));
|
2020-01-11 16:07:51 +03:00
|
|
|
case FormattedBody: {
|
|
|
|
const static QRegularExpression replyFallback(
|
|
|
|
"<mx-reply>.*</mx-reply>", QRegularExpression::DotMatchesEverythingOption);
|
2020-01-27 19:05:40 +03:00
|
|
|
|
2021-02-18 00:14:19 +03:00
|
|
|
auto ascent = QFontMetrics(UserSettings::instance()->font()).ascent();
|
|
|
|
|
2021-02-20 21:05:21 +03:00
|
|
|
bool isReply = utils::isReply(event);
|
2020-01-27 19:05:40 +03:00
|
|
|
|
|
|
|
auto formattedBody_ = QString::fromStdString(formatted_body(event));
|
|
|
|
if (formattedBody_.isEmpty()) {
|
|
|
|
auto body_ = QString::fromStdString(body(event));
|
|
|
|
|
|
|
|
if (isReply) {
|
|
|
|
while (body_.startsWith("> "))
|
|
|
|
body_ = body_.right(body_.size() - body_.indexOf('\n') - 1);
|
|
|
|
if (body_.startsWith('\n'))
|
|
|
|
body_ = body_.right(body_.size() - 1);
|
|
|
|
}
|
2020-01-27 20:36:34 +03:00
|
|
|
formattedBody_ = body_.toHtmlEscaped().replace('\n', "<br>");
|
2020-01-27 19:05:40 +03:00
|
|
|
} else {
|
|
|
|
if (isReply)
|
|
|
|
formattedBody_ = formattedBody_.remove(replyFallback);
|
|
|
|
}
|
2020-05-14 01:41:10 +03:00
|
|
|
|
2021-02-18 00:14:19 +03:00
|
|
|
// TODO(Nico): Don't parse html with a regex
|
|
|
|
const static QRegularExpression matchImgUri(
|
|
|
|
"(<img [^>]*)src=\"mxc://([^\"]*)\"([^>]*>)");
|
|
|
|
formattedBody_.replace(matchImgUri, "\\1 src=\"image://mxcImage/\\2\"\\3");
|
|
|
|
const static QRegularExpression matchEmoticonHeight(
|
|
|
|
"(<img data-mx-emoticon [^>]*)height=\"([^\"]*)\"([^>]*>)");
|
|
|
|
formattedBody_.replace(matchEmoticonHeight,
|
|
|
|
QString("\\1 height=\"%1\"\\3").arg(ascent));
|
2020-05-14 01:41:10 +03:00
|
|
|
|
2020-01-27 19:05:40 +03:00
|
|
|
return QVariant(utils::replaceEmoji(
|
|
|
|
utils::linkifyMessage(utils::escapeBlacklistedHtml(formattedBody_))));
|
2020-01-11 16:07:51 +03:00
|
|
|
}
|
2019-09-08 13:44:46 +03:00
|
|
|
case Url:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(QString::fromStdString(url(event)));
|
2019-10-09 01:36:03 +03:00
|
|
|
case ThumbnailUrl:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(QString::fromStdString(thumbnail_url(event)));
|
2020-03-01 21:55:43 +03:00
|
|
|
case Blurhash:
|
|
|
|
return QVariant(QString::fromStdString(blurhash(event)));
|
2019-09-29 11:45:35 +03:00
|
|
|
case Filename:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(QString::fromStdString(filename(event)));
|
2019-10-04 02:10:46 +03:00
|
|
|
case Filesize:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(utils::humanReadableFileSize(filesize(event)));
|
2019-09-29 11:45:35 +03:00
|
|
|
case MimeType:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(QString::fromStdString(mimetype(event)));
|
2019-09-08 13:44:46 +03:00
|
|
|
case Height:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(qulonglong{media_height(event)});
|
2019-09-08 13:44:46 +03:00
|
|
|
case Width:
|
2019-12-27 23:49:55 +03:00
|
|
|
return QVariant(qulonglong{media_width(event)});
|
|
|
|
case ProportionalHeight: {
|
|
|
|
auto w = media_width(event);
|
|
|
|
if (w == 0)
|
|
|
|
w = 1;
|
|
|
|
|
|
|
|
double prop = media_height(event) / (double)w;
|
|
|
|
|
|
|
|
return QVariant(prop > 0 ? prop : 1.);
|
|
|
|
}
|
2021-02-01 00:41:43 +03:00
|
|
|
case Id: {
|
|
|
|
if (auto replaces = relations(event).replaces())
|
|
|
|
return QVariant(QString::fromStdString(replaces.value()));
|
|
|
|
else
|
|
|
|
return QVariant(QString::fromStdString(event_id(event)));
|
|
|
|
}
|
2020-05-06 20:21:31 +03:00
|
|
|
case State: {
|
2020-07-10 00:15:22 +03:00
|
|
|
auto id = QString::fromStdString(event_id(event));
|
2020-05-06 20:21:31 +03:00
|
|
|
auto containsOthers = [](const auto &vec) {
|
|
|
|
for (const auto &e : vec)
|
|
|
|
if (e.second != http::client()->user_id().to_string())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2019-09-19 22:47:16 +03:00
|
|
|
// only show read receipts for messages not from us
|
2019-12-27 23:49:55 +03:00
|
|
|
if (acc::sender(event) != http::client()->user_id().to_string())
|
2019-09-19 22:47:16 +03:00
|
|
|
return qml_mtx_events::Empty;
|
2020-07-18 18:43:49 +03:00
|
|
|
else if (!id.isEmpty() && id[0] == "m")
|
2019-09-18 23:58:25 +03:00
|
|
|
return qml_mtx_events::Sent;
|
2020-05-06 20:21:31 +03:00
|
|
|
else if (read.contains(id) || containsOthers(cache::readReceipts(id, room_id_)))
|
2019-09-19 00:37:30 +03:00
|
|
|
return qml_mtx_events::Read;
|
2019-09-18 23:58:25 +03:00
|
|
|
else
|
|
|
|
return qml_mtx_events::Received;
|
2020-05-06 20:21:31 +03:00
|
|
|
}
|
2021-02-01 00:41:43 +03:00
|
|
|
case IsEdited:
|
|
|
|
return QVariant(relations(event).replaces().has_value());
|
|
|
|
case IsEditable:
|
2021-05-09 14:02:41 +03:00
|
|
|
return QVariant(!is_state_event(event) &&
|
|
|
|
mtx::accessors::sender(event) ==
|
|
|
|
http::client()->user_id().to_string() &&
|
|
|
|
!event_id(event).empty() && event_id(event).front() == '$');
|
2019-09-20 00:02:56 +03:00
|
|
|
case IsEncrypted: {
|
2020-07-18 18:59:59 +03:00
|
|
|
auto id = event_id(event);
|
2021-05-30 02:09:16 +03:00
|
|
|
auto encrypted_event = events.get(id, "", false);
|
2020-07-18 18:59:59 +03:00
|
|
|
return encrypted_event &&
|
|
|
|
std::holds_alternative<
|
|
|
|
mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
|
|
|
|
*encrypted_event);
|
2019-11-05 19:16:04 +03:00
|
|
|
}
|
2021-05-07 13:19:46 +03:00
|
|
|
|
|
|
|
case Trustlevel: {
|
|
|
|
auto id = event_id(event);
|
2021-05-30 02:09:16 +03:00
|
|
|
auto encrypted_event = events.get(id, "", false);
|
2021-05-07 13:19:46 +03:00
|
|
|
if (encrypted_event) {
|
|
|
|
if (auto encrypted =
|
|
|
|
std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
|
|
|
|
&*encrypted_event)) {
|
|
|
|
return olm::calculate_trust(encrypted->sender,
|
|
|
|
encrypted->content.sender_key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return crypto::Trust::Unverified;
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:35:29 +03:00
|
|
|
case IsRoomEncrypted: {
|
|
|
|
return cache::isRoomEncrypted(room_id_.toStdString());
|
|
|
|
}
|
2019-12-27 23:49:55 +03:00
|
|
|
case ReplyTo:
|
2021-01-27 00:36:35 +03:00
|
|
|
return QVariant(QString::fromStdString(relations(event).reply_to().value_or("")));
|
2020-07-10 00:15:22 +03:00
|
|
|
case Reactions: {
|
2021-02-01 00:41:43 +03:00
|
|
|
auto id = relations(event).replaces().value_or(event_id(event));
|
2020-07-19 13:22:54 +03:00
|
|
|
return QVariant::fromValue(events.reactions(id));
|
2020-07-10 00:15:22 +03:00
|
|
|
}
|
2020-02-29 03:27:51 +03:00
|
|
|
case RoomId:
|
2020-05-17 03:36:04 +03:00
|
|
|
return QVariant(room_id_);
|
2019-12-10 16:46:52 +03:00
|
|
|
case RoomName:
|
2021-04-19 12:20:34 +03:00
|
|
|
return QVariant(
|
|
|
|
utils::replaceEmoji(QString::fromStdString(room_name(event)).toHtmlEscaped()));
|
2019-12-10 16:46:52 +03:00
|
|
|
case RoomTopic:
|
2021-04-19 12:20:34 +03:00
|
|
|
return QVariant(utils::replaceEmoji(
|
|
|
|
utils::linkifyMessage(QString::fromStdString(room_topic(event))
|
|
|
|
.toHtmlEscaped()
|
|
|
|
.replace("\n", "<br>"))));
|
2020-07-24 20:30:12 +03:00
|
|
|
case CallType:
|
|
|
|
return QVariant(QString::fromStdString(call_type(event)));
|
2020-01-04 01:21:33 +03:00
|
|
|
case Dump: {
|
|
|
|
QVariantMap m;
|
|
|
|
auto names = roleNames();
|
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
m.insert(names[Type], data(event, static_cast<int>(Type)));
|
|
|
|
m.insert(names[TypeString], data(event, static_cast<int>(TypeString)));
|
|
|
|
m.insert(names[IsOnlyEmoji], data(event, static_cast<int>(IsOnlyEmoji)));
|
|
|
|
m.insert(names[Body], data(event, static_cast<int>(Body)));
|
|
|
|
m.insert(names[FormattedBody], data(event, static_cast<int>(FormattedBody)));
|
2021-05-02 19:01:18 +03:00
|
|
|
m.insert(names[IsSender], data(event, static_cast<int>(IsSender)));
|
2020-07-10 00:15:22 +03:00
|
|
|
m.insert(names[UserId], data(event, static_cast<int>(UserId)));
|
|
|
|
m.insert(names[UserName], data(event, static_cast<int>(UserName)));
|
2021-01-20 01:58:25 +03:00
|
|
|
m.insert(names[Day], data(event, static_cast<int>(Day)));
|
2020-07-10 00:15:22 +03:00
|
|
|
m.insert(names[Timestamp], data(event, static_cast<int>(Timestamp)));
|
|
|
|
m.insert(names[Url], data(event, static_cast<int>(Url)));
|
|
|
|
m.insert(names[ThumbnailUrl], data(event, static_cast<int>(ThumbnailUrl)));
|
|
|
|
m.insert(names[Blurhash], data(event, static_cast<int>(Blurhash)));
|
|
|
|
m.insert(names[Filename], data(event, static_cast<int>(Filename)));
|
|
|
|
m.insert(names[Filesize], data(event, static_cast<int>(Filesize)));
|
|
|
|
m.insert(names[MimeType], data(event, static_cast<int>(MimeType)));
|
|
|
|
m.insert(names[Height], data(event, static_cast<int>(Height)));
|
|
|
|
m.insert(names[Width], data(event, static_cast<int>(Width)));
|
|
|
|
m.insert(names[ProportionalHeight],
|
|
|
|
data(event, static_cast<int>(ProportionalHeight)));
|
|
|
|
m.insert(names[Id], data(event, static_cast<int>(Id)));
|
|
|
|
m.insert(names[State], data(event, static_cast<int>(State)));
|
2021-02-25 01:51:05 +03:00
|
|
|
m.insert(names[IsEdited], data(event, static_cast<int>(IsEdited)));
|
|
|
|
m.insert(names[IsEditable], data(event, static_cast<int>(IsEditable)));
|
2020-07-10 00:15:22 +03:00
|
|
|
m.insert(names[IsEncrypted], data(event, static_cast<int>(IsEncrypted)));
|
|
|
|
m.insert(names[IsRoomEncrypted], data(event, static_cast<int>(IsRoomEncrypted)));
|
|
|
|
m.insert(names[ReplyTo], data(event, static_cast<int>(ReplyTo)));
|
|
|
|
m.insert(names[RoomName], data(event, static_cast<int>(RoomName)));
|
|
|
|
m.insert(names[RoomTopic], data(event, static_cast<int>(RoomTopic)));
|
2020-08-17 21:40:33 +03:00
|
|
|
m.insert(names[CallType], data(event, static_cast<int>(CallType)));
|
2020-01-04 01:21:33 +03:00
|
|
|
|
|
|
|
return QVariant(m);
|
|
|
|
}
|
2019-08-31 00:20:53 +03:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-11 20:53:32 +03:00
|
|
|
QVariant
|
|
|
|
TimelineModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
using namespace mtx::accessors;
|
|
|
|
namespace acc = mtx::accessors;
|
2020-07-10 00:15:22 +03:00
|
|
|
if (index.row() < 0 && index.row() >= rowCount())
|
2020-01-11 20:53:32 +03:00
|
|
|
return QVariant();
|
|
|
|
|
2020-07-26 13:33:30 +03:00
|
|
|
auto event = events.get(rowCount() - index.row() - 1);
|
2020-01-11 20:53:32 +03:00
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!event)
|
|
|
|
return "";
|
2020-01-11 20:53:32 +03:00
|
|
|
|
2021-01-20 01:58:25 +03:00
|
|
|
if (role == PreviousMessageDay || role == PreviousMessageUserId) {
|
|
|
|
int prevIdx = rowCount() - index.row() - 2;
|
|
|
|
if (prevIdx < 0)
|
|
|
|
return QVariant();
|
|
|
|
auto tempEv = events.get(prevIdx);
|
|
|
|
if (!tempEv)
|
|
|
|
return QVariant();
|
|
|
|
if (role == PreviousMessageUserId)
|
|
|
|
return data(*tempEv, UserId);
|
|
|
|
else
|
|
|
|
return data(*tempEv, Day);
|
2020-01-11 20:53:32 +03:00
|
|
|
}
|
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
return data(*event, role);
|
2020-01-11 20:53:32 +03:00
|
|
|
}
|
|
|
|
|
2020-01-06 18:42:56 +03:00
|
|
|
bool
|
|
|
|
TimelineModel::canFetchMore(const QModelIndex &) const
|
|
|
|
{
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!events.size())
|
2020-01-06 18:42:56 +03:00
|
|
|
return true;
|
2020-07-26 13:33:30 +03:00
|
|
|
if (auto first = events.get(0);
|
2020-07-13 01:08:58 +03:00
|
|
|
first &&
|
|
|
|
!std::holds_alternative<mtx::events::StateEvent<mtx::events::state::Create>>(*first))
|
2020-01-06 18:42:56 +03:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-28 12:07:24 +03:00
|
|
|
void
|
|
|
|
TimelineModel::setPaginationInProgress(const bool paginationInProgress)
|
|
|
|
{
|
|
|
|
if (m_paginationInProgress == paginationInProgress) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_paginationInProgress = paginationInProgress;
|
|
|
|
emit paginationInProgressChanged(m_paginationInProgress);
|
|
|
|
}
|
|
|
|
|
2020-01-06 18:42:56 +03:00
|
|
|
void
|
|
|
|
TimelineModel::fetchMore(const QModelIndex &)
|
|
|
|
{
|
2020-04-28 12:07:24 +03:00
|
|
|
if (m_paginationInProgress) {
|
2020-01-06 18:42:56 +03:00
|
|
|
nhlog::ui()->warn("Already loading older messages");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-28 12:07:24 +03:00
|
|
|
setPaginationInProgress(true);
|
2020-07-13 01:08:58 +03:00
|
|
|
|
|
|
|
events.fetchMore();
|
2020-01-06 18:42:56 +03:00
|
|
|
}
|
|
|
|
|
2021-05-21 22:19:03 +03:00
|
|
|
void
|
|
|
|
TimelineModel::sync(const mtx::responses::JoinedRoom &room)
|
|
|
|
{
|
|
|
|
this->syncState(room.state);
|
|
|
|
this->addEvents(room.timeline);
|
|
|
|
|
|
|
|
if (room.unread_notifications.highlight_count != highlight_count ||
|
|
|
|
room.unread_notifications.notification_count != notification_count) {
|
|
|
|
notification_count = room.unread_notifications.notification_count;
|
|
|
|
highlight_count = room.unread_notifications.highlight_count;
|
|
|
|
emit notificationsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 18:01:58 +03:00
|
|
|
void
|
|
|
|
TimelineModel::syncState(const mtx::responses::State &s)
|
|
|
|
{
|
|
|
|
using namespace mtx::events;
|
|
|
|
|
|
|
|
for (const auto &e : s.events) {
|
|
|
|
if (std::holds_alternative<StateEvent<state::Avatar>>(e))
|
|
|
|
emit roomAvatarUrlChanged();
|
|
|
|
else if (std::holds_alternative<StateEvent<state::Name>>(e))
|
|
|
|
emit roomNameChanged();
|
|
|
|
else if (std::holds_alternative<StateEvent<state::Topic>>(e))
|
|
|
|
emit roomTopicChanged();
|
2021-05-02 19:01:18 +03:00
|
|
|
else if (std::holds_alternative<StateEvent<state::Topic>>(e)) {
|
|
|
|
permissions_.invalidate();
|
|
|
|
emit permissionsChanged();
|
|
|
|
} else if (std::holds_alternative<StateEvent<state::Member>>(e)) {
|
2020-09-03 18:01:58 +03:00
|
|
|
emit roomAvatarUrlChanged();
|
|
|
|
emit roomNameChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-31 23:43:31 +03:00
|
|
|
void
|
2019-09-03 03:14:49 +03:00
|
|
|
TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
|
2019-08-31 23:43:31 +03:00
|
|
|
{
|
2019-09-07 15:37:54 +03:00
|
|
|
if (timeline.events.empty())
|
|
|
|
return;
|
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
events.handleSync(timeline);
|
2019-10-03 19:07:01 +03:00
|
|
|
|
2020-08-17 21:40:33 +03:00
|
|
|
using namespace mtx::events;
|
2020-09-03 18:01:58 +03:00
|
|
|
|
2020-08-17 21:40:33 +03:00
|
|
|
for (auto e : timeline.events) {
|
|
|
|
if (auto encryptedEvent = std::get_if<EncryptedEvent<msg::Encrypted>>(&e)) {
|
|
|
|
MegolmSessionIndex index;
|
|
|
|
index.room_id = room_id_.toStdString();
|
|
|
|
index.session_id = encryptedEvent->content.session_id;
|
|
|
|
index.sender_key = encryptedEvent->content.sender_key;
|
|
|
|
|
|
|
|
auto result = olm::decryptEvent(index, *encryptedEvent);
|
|
|
|
if (result.event)
|
|
|
|
e = result.event.value();
|
|
|
|
}
|
2019-10-03 19:07:01 +03:00
|
|
|
|
2020-08-17 21:40:33 +03:00
|
|
|
if (std::holds_alternative<RoomEvent<msg::CallCandidates>>(e) ||
|
|
|
|
std::holds_alternative<RoomEvent<msg::CallInvite>>(e) ||
|
|
|
|
std::holds_alternative<RoomEvent<msg::CallAnswer>>(e) ||
|
|
|
|
std::holds_alternative<RoomEvent<msg::CallHangUp>>(e))
|
|
|
|
std::visit(
|
|
|
|
[this](auto &event) {
|
|
|
|
event.room_id = room_id_.toStdString();
|
2021-01-01 16:46:08 +03:00
|
|
|
if constexpr (std::is_same_v<std::decay_t<decltype(event)>,
|
2021-01-10 20:23:58 +03:00
|
|
|
RoomEvent<msg::CallAnswer>> ||
|
|
|
|
std::is_same_v<std::decay_t<decltype(event)>,
|
|
|
|
RoomEvent<msg::CallHangUp>>)
|
2020-08-17 21:40:33 +03:00
|
|
|
emit newCallEvent(event);
|
2021-01-01 16:46:08 +03:00
|
|
|
else {
|
|
|
|
if (event.sender != http::client()->user_id().to_string())
|
|
|
|
emit newCallEvent(event);
|
|
|
|
}
|
2020-08-17 21:40:33 +03:00
|
|
|
},
|
|
|
|
e);
|
2020-09-03 18:01:58 +03:00
|
|
|
else if (std::holds_alternative<StateEvent<state::Avatar>>(e))
|
|
|
|
emit roomAvatarUrlChanged();
|
|
|
|
else if (std::holds_alternative<StateEvent<state::Name>>(e))
|
|
|
|
emit roomNameChanged();
|
|
|
|
else if (std::holds_alternative<StateEvent<state::Topic>>(e))
|
|
|
|
emit roomTopicChanged();
|
2021-05-02 19:01:18 +03:00
|
|
|
else if (std::holds_alternative<StateEvent<state::PowerLevels>>(e)) {
|
|
|
|
permissions_.invalidate();
|
|
|
|
emit permissionsChanged();
|
|
|
|
} else if (std::holds_alternative<StateEvent<state::Member>>(e)) {
|
2020-09-03 18:01:58 +03:00
|
|
|
emit roomAvatarUrlChanged();
|
|
|
|
emit roomNameChanged();
|
|
|
|
}
|
2020-08-17 21:40:33 +03:00
|
|
|
}
|
|
|
|
updateLastMessage();
|
2019-10-31 16:09:51 +03:00
|
|
|
}
|
2019-10-03 19:07:01 +03:00
|
|
|
|
2019-11-09 05:30:17 +03:00
|
|
|
template<typename T>
|
|
|
|
auto
|
|
|
|
isMessage(const mtx::events::RoomEvent<T> &e)
|
|
|
|
-> std::enable_if_t<std::is_same<decltype(e.content.msgtype), std::string>::value, bool>
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
auto
|
|
|
|
isMessage(const mtx::events::Event<T> &)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-23 02:52:30 +03:00
|
|
|
template<typename T>
|
|
|
|
auto
|
|
|
|
isMessage(const mtx::events::EncryptedEvent<T> &)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-11 02:19:48 +03:00
|
|
|
auto
|
|
|
|
isMessage(const mtx::events::RoomEvent<mtx::events::msg::CallInvite> &)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto
|
|
|
|
isMessage(const mtx::events::RoomEvent<mtx::events::msg::CallAnswer> &)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
auto
|
|
|
|
isMessage(const mtx::events::RoomEvent<mtx::events::msg::CallHangUp> &)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-04 21:17:57 +03:00
|
|
|
// Workaround. We also want to see a room at the top, if we just joined it
|
|
|
|
auto
|
|
|
|
isYourJoin(const mtx::events::StateEvent<mtx::events::state::Member> &e)
|
|
|
|
{
|
|
|
|
return e.content.membership == mtx::events::state::Membership::Join &&
|
|
|
|
e.state_key == http::client()->user_id().to_string();
|
|
|
|
}
|
|
|
|
template<typename T>
|
|
|
|
auto
|
|
|
|
isYourJoin(const mtx::events::Event<T> &)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-31 16:09:51 +03:00
|
|
|
void
|
|
|
|
TimelineModel::updateLastMessage()
|
2020-04-24 02:05:44 +03:00
|
|
|
{
|
2020-07-10 00:15:22 +03:00
|
|
|
for (auto it = events.size() - 1; it >= 0; --it) {
|
2020-07-26 13:33:30 +03:00
|
|
|
auto event = events.get(it, decryptDescription);
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!event)
|
|
|
|
continue;
|
2019-10-31 16:09:51 +03:00
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
if (std::visit([](const auto &e) -> bool { return isYourJoin(e); }, *event)) {
|
|
|
|
auto time = mtx::accessors::origin_server_ts(*event);
|
2020-05-04 21:17:57 +03:00
|
|
|
uint64_t ts = time.toMSecsSinceEpoch();
|
2021-05-21 22:19:03 +03:00
|
|
|
auto description =
|
2020-07-10 00:15:22 +03:00
|
|
|
DescInfo{QString::fromStdString(mtx::accessors::event_id(*event)),
|
2020-05-04 21:17:57 +03:00
|
|
|
QString::fromStdString(http::client()->user_id().to_string()),
|
2020-05-10 02:38:40 +03:00
|
|
|
tr("You joined this room."),
|
2020-05-04 21:17:57 +03:00
|
|
|
utils::descriptiveTime(time),
|
|
|
|
ts,
|
2021-05-21 22:19:03 +03:00
|
|
|
time};
|
|
|
|
if (description != lastMessage_) {
|
|
|
|
lastMessage_ = description;
|
|
|
|
emit manager_->updateRoomsLastMessage(room_id_, lastMessage_);
|
|
|
|
emit lastMessageChanged();
|
|
|
|
}
|
2020-05-04 21:17:57 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!std::visit([](const auto &e) -> bool { return isMessage(e); }, *event))
|
2019-11-09 05:30:17 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
auto description = utils::getMessageDescription(
|
2020-11-26 01:43:31 +03:00
|
|
|
*event,
|
|
|
|
QString::fromStdString(http::client()->user_id().to_string()),
|
|
|
|
cache::displayName(room_id_,
|
|
|
|
QString::fromStdString(mtx::accessors::sender(*event))));
|
2021-05-21 22:19:03 +03:00
|
|
|
if (description != lastMessage_) {
|
|
|
|
lastMessage_ = description;
|
|
|
|
emit manager_->updateRoomsLastMessage(room_id_, description);
|
|
|
|
emit lastMessageChanged();
|
|
|
|
}
|
2019-11-09 05:30:17 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-09-09 22:42:33 +03:00
|
|
|
}
|
|
|
|
|
2019-10-03 23:39:56 +03:00
|
|
|
void
|
|
|
|
TimelineModel::setCurrentIndex(int index)
|
|
|
|
{
|
|
|
|
auto oldIndex = idToIndex(currentId);
|
2019-10-06 15:00:49 +03:00
|
|
|
currentId = indexToId(index);
|
2021-02-10 03:03:20 +03:00
|
|
|
if (index != oldIndex)
|
|
|
|
emit currentIndexChanged(index);
|
|
|
|
|
2021-02-13 03:41:09 +03:00
|
|
|
if (!ChatPage::instance()->isActiveWindow())
|
|
|
|
return;
|
|
|
|
|
2021-02-10 03:03:20 +03:00
|
|
|
if (!currentId.startsWith("m")) {
|
|
|
|
auto oldReadIndex =
|
|
|
|
cache::getEventIndex(roomId().toStdString(), currentReadId.toStdString());
|
|
|
|
auto nextEventIndexAndId =
|
|
|
|
cache::lastInvisibleEventAfter(roomId().toStdString(), currentId.toStdString());
|
|
|
|
|
|
|
|
if (nextEventIndexAndId &&
|
|
|
|
(!oldReadIndex || *oldReadIndex < nextEventIndexAndId->first)) {
|
|
|
|
readEvent(nextEventIndexAndId->second);
|
|
|
|
currentReadId = QString::fromStdString(nextEventIndexAndId->second);
|
|
|
|
}
|
2019-10-03 23:39:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 16:09:51 +03:00
|
|
|
void
|
|
|
|
TimelineModel::readEvent(const std::string &id)
|
|
|
|
{
|
|
|
|
http::client()->read_event(room_id_.toStdString(), id, [this](mtx::http::RequestErr err) {
|
|
|
|
if (err) {
|
|
|
|
nhlog::net()->warn("failed to read_event ({}, {})",
|
|
|
|
room_id_.toStdString(),
|
|
|
|
currentId.toStdString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-01 23:34:36 +03:00
|
|
|
QString
|
|
|
|
TimelineModel::displayName(QString id) const
|
|
|
|
{
|
2020-02-02 17:15:00 +03:00
|
|
|
return cache::displayName(room_id_, id).toHtmlEscaped();
|
2019-09-01 23:34:36 +03:00
|
|
|
}
|
2019-09-01 23:58:26 +03:00
|
|
|
|
2019-09-07 23:22:07 +03:00
|
|
|
QString
|
|
|
|
TimelineModel::avatarUrl(QString id) const
|
|
|
|
{
|
2019-12-15 04:56:04 +03:00
|
|
|
return cache::avatarUrl(room_id_, id);
|
2019-09-07 23:22:07 +03:00
|
|
|
}
|
|
|
|
|
2019-09-01 23:58:26 +03:00
|
|
|
QString
|
|
|
|
TimelineModel::formatDateSeparator(QDate date) const
|
|
|
|
{
|
|
|
|
auto now = QDateTime::currentDateTime();
|
|
|
|
|
|
|
|
QString fmt = QLocale::system().dateFormat(QLocale::LongFormat);
|
|
|
|
|
|
|
|
if (now.date().year() == date.year()) {
|
|
|
|
QRegularExpression rx("[^a-zA-Z]*y+[^a-zA-Z]*");
|
|
|
|
fmt = fmt.remove(rx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return date.toString(fmt);
|
|
|
|
}
|
2019-09-07 03:01:44 +03:00
|
|
|
|
2019-09-08 16:26:46 +03:00
|
|
|
void
|
|
|
|
TimelineModel::viewRawMessage(QString id) const
|
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
auto e = events.get(id.toStdString(), "", false);
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!e)
|
|
|
|
return;
|
|
|
|
std::string ev = mtx::accessors::serialize_event(*e).dump(4);
|
2019-09-08 16:26:46 +03:00
|
|
|
auto dialog = new dialogs::RawMessage(QString::fromStdString(ev));
|
|
|
|
Q_UNUSED(dialog);
|
|
|
|
}
|
2019-09-08 17:50:32 +03:00
|
|
|
|
2021-04-11 17:31:49 +03:00
|
|
|
void
|
|
|
|
TimelineModel::forwardMessage(QString eventId, QString roomId)
|
|
|
|
{
|
|
|
|
auto e = events.get(eventId.toStdString(), "");
|
|
|
|
if (!e)
|
|
|
|
return;
|
|
|
|
|
2021-04-17 20:28:04 +03:00
|
|
|
emit forwardToRoom(e, roomId);
|
2021-04-11 17:31:49 +03:00
|
|
|
}
|
|
|
|
|
2019-11-03 04:09:36 +03:00
|
|
|
void
|
2020-04-21 23:32:45 +03:00
|
|
|
TimelineModel::viewDecryptedRawMessage(QString id) const
|
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
auto e = events.get(id.toStdString(), "");
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!e)
|
|
|
|
return;
|
2019-11-03 04:09:36 +03:00
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
std::string ev = mtx::accessors::serialize_event(*e).dump(4);
|
2020-04-21 23:32:45 +03:00
|
|
|
auto dialog = new dialogs::RawMessage(QString::fromStdString(ev));
|
|
|
|
Q_UNUSED(dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-04-30 16:33:17 +03:00
|
|
|
TimelineModel::openUserProfile(QString userid)
|
2019-11-03 04:09:36 +03:00
|
|
|
{
|
2021-04-30 16:33:17 +03:00
|
|
|
UserProfile *userProfile = new UserProfile(room_id_, userid, manager_, this);
|
2021-02-02 11:00:47 +03:00
|
|
|
connect(
|
2021-02-02 14:54:08 +03:00
|
|
|
this, &TimelineModel::roomAvatarUrlChanged, userProfile, &UserProfile::updateAvatarUrl);
|
2021-04-30 16:33:17 +03:00
|
|
|
emit manager_->openProfile(userProfile);
|
2019-11-03 04:09:36 +03:00
|
|
|
}
|
|
|
|
|
2021-02-11 21:20:45 +03:00
|
|
|
void
|
2021-02-12 10:18:12 +03:00
|
|
|
TimelineModel::openRoomSettings()
|
2021-02-11 21:20:45 +03:00
|
|
|
{
|
2021-02-12 10:18:12 +03:00
|
|
|
RoomSettings *settings = new RoomSettings(roomId(), this);
|
2021-02-11 21:20:45 +03:00
|
|
|
connect(this, &TimelineModel::roomAvatarUrlChanged, settings, &RoomSettings::avatarChanged);
|
|
|
|
openRoomSettingsDialog(settings);
|
|
|
|
}
|
|
|
|
|
2019-09-11 01:54:40 +03:00
|
|
|
void
|
|
|
|
TimelineModel::replyAction(QString id)
|
|
|
|
{
|
2020-04-13 17:22:30 +03:00
|
|
|
setReply(id);
|
|
|
|
}
|
|
|
|
|
2021-02-01 00:41:43 +03:00
|
|
|
void
|
|
|
|
TimelineModel::editAction(QString id)
|
|
|
|
{
|
|
|
|
setEdit(id);
|
|
|
|
}
|
|
|
|
|
2020-04-13 17:22:30 +03:00
|
|
|
RelatedInfo
|
|
|
|
TimelineModel::relatedInfo(QString id)
|
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
auto event = events.get(id.toStdString(), "");
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!event)
|
2020-04-13 17:22:30 +03:00
|
|
|
return {};
|
|
|
|
|
2021-03-17 21:08:17 +03:00
|
|
|
return utils::stripReplyFallbacks(*event, id.toStdString(), room_id_);
|
2019-09-19 00:37:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineModel::readReceiptsAction(QString id) const
|
|
|
|
{
|
|
|
|
MainWindow::instance()->openReadReceiptsDialog(id);
|
2019-09-11 01:54:40 +03:00
|
|
|
}
|
2019-09-18 21:34:30 +03:00
|
|
|
|
2019-09-29 13:29:17 +03:00
|
|
|
void
|
|
|
|
TimelineModel::redactEvent(QString id)
|
|
|
|
{
|
|
|
|
if (!id.isEmpty())
|
|
|
|
http::client()->redact_event(
|
|
|
|
room_id_.toStdString(),
|
|
|
|
id.toStdString(),
|
|
|
|
[this, id](const mtx::responses::EventId &, mtx::http::RequestErr err) {
|
|
|
|
if (err) {
|
|
|
|
emit redactionFailed(
|
|
|
|
tr("Message redaction failed: %1")
|
|
|
|
.arg(QString::fromStdString(err->matrix_error.error)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit eventRedacted(id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-18 21:34:30 +03:00
|
|
|
int
|
|
|
|
TimelineModel::idToIndex(QString id) const
|
|
|
|
{
|
|
|
|
if (id.isEmpty())
|
|
|
|
return -1;
|
2020-07-10 00:15:22 +03:00
|
|
|
|
|
|
|
auto idx = events.idToIndex(id.toStdString());
|
|
|
|
if (idx)
|
2020-07-18 22:14:45 +03:00
|
|
|
return events.size() - *idx - 1;
|
2020-07-10 00:15:22 +03:00
|
|
|
else
|
|
|
|
return -1;
|
2019-09-18 21:34:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TimelineModel::indexToId(int index) const
|
|
|
|
{
|
2020-07-18 22:14:45 +03:00
|
|
|
auto id = events.indexToId(events.size() - index - 1);
|
2020-07-10 00:15:22 +03:00
|
|
|
return id ? QString::fromStdString(*id) : "";
|
2019-09-18 21:34:30 +03:00
|
|
|
}
|
2019-09-19 00:37:30 +03:00
|
|
|
|
2019-09-19 22:47:16 +03:00
|
|
|
// Note: this will only be called for our messages
|
2019-09-19 00:37:30 +03:00
|
|
|
void
|
|
|
|
TimelineModel::markEventsAsRead(const std::vector<QString> &event_ids)
|
|
|
|
{
|
|
|
|
for (const auto &id : event_ids) {
|
|
|
|
read.insert(id);
|
|
|
|
int idx = idToIndex(id);
|
|
|
|
if (idx < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emit dataChanged(index(idx, 0), index(idx, 0));
|
|
|
|
}
|
|
|
|
}
|
2019-09-19 23:44:25 +03:00
|
|
|
|
2020-08-09 06:05:15 +03:00
|
|
|
template<typename T>
|
2019-09-19 23:44:25 +03:00
|
|
|
void
|
2020-08-30 19:57:14 +03:00
|
|
|
TimelineModel::sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::EventType eventType)
|
2019-09-19 23:44:25 +03:00
|
|
|
{
|
|
|
|
const auto room_id = room_id_.toStdString();
|
|
|
|
|
|
|
|
using namespace mtx::events;
|
|
|
|
using namespace mtx::identifiers;
|
|
|
|
|
2020-08-30 19:57:14 +03:00
|
|
|
json doc = {{"type", mtx::events::to_string(eventType)},
|
2020-09-03 06:59:32 +03:00
|
|
|
{"content", json(msg.content)},
|
2020-08-30 19:57:14 +03:00
|
|
|
{"room_id", room_id}};
|
2019-09-19 23:44:25 +03:00
|
|
|
|
|
|
|
try {
|
2020-11-30 02:26:27 +03:00
|
|
|
mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> event;
|
|
|
|
event.content =
|
|
|
|
olm::encrypt_group_message(room_id, http::client()->device_id(), doc);
|
|
|
|
event.event_id = msg.event_id;
|
|
|
|
event.room_id = room_id;
|
|
|
|
event.sender = http::client()->user_id().to_string();
|
|
|
|
event.type = mtx::events::EventType::RoomEncrypted;
|
|
|
|
event.origin_server_ts = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
|
|
|
|
emit this->addPendingMessageToStore(event);
|
2019-09-19 23:44:25 +03:00
|
|
|
|
|
|
|
// TODO: Let the user know about the errors.
|
|
|
|
} catch (const lmdb::error &e) {
|
|
|
|
nhlog::db()->critical(
|
|
|
|
"failed to open outbound megolm session ({}): {}", room_id, e.what());
|
2020-07-18 18:43:49 +03:00
|
|
|
emit ChatPage::instance()->showNotification(
|
|
|
|
tr("Failed to encrypt event, sending aborted!"));
|
2019-09-19 23:44:25 +03:00
|
|
|
} catch (const mtx::crypto::olm_exception &e) {
|
|
|
|
nhlog::crypto()->critical(
|
|
|
|
"failed to open outbound megolm session ({}): {}", room_id, e.what());
|
2020-07-18 18:43:49 +03:00
|
|
|
emit ChatPage::instance()->showNotification(
|
|
|
|
tr("Failed to encrypt event, sending aborted!"));
|
2019-09-19 23:44:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 02:30:02 +03:00
|
|
|
struct SendMessageVisitor
|
|
|
|
{
|
2020-07-18 18:43:49 +03:00
|
|
|
explicit SendMessageVisitor(TimelineModel *model)
|
|
|
|
: model_(model)
|
2019-11-10 02:30:02 +03:00
|
|
|
{}
|
|
|
|
|
2020-07-11 02:19:48 +03:00
|
|
|
template<typename T, mtx::events::EventType Event>
|
2020-08-17 21:40:33 +03:00
|
|
|
void sendRoomEvent(mtx::events::RoomEvent<T> msg)
|
2020-08-09 06:05:15 +03:00
|
|
|
{
|
2019-12-15 04:56:04 +03:00
|
|
|
if (cache::isRoomEncrypted(model_->room_id_.toStdString())) {
|
2020-04-21 10:03:36 +03:00
|
|
|
auto encInfo = mtx::accessors::file(msg);
|
|
|
|
if (encInfo)
|
|
|
|
emit model_->newEncryptedImage(encInfo.value());
|
|
|
|
|
2020-08-30 19:57:14 +03:00
|
|
|
model_->sendEncryptedMessage(msg, Event);
|
2019-11-10 02:30:02 +03:00
|
|
|
} else {
|
2020-08-17 21:40:33 +03:00
|
|
|
msg.type = Event;
|
2020-07-18 18:43:49 +03:00
|
|
|
emit model_->addPendingMessageToStore(msg);
|
2019-11-10 02:30:02 +03:00
|
|
|
}
|
2020-08-09 06:05:15 +03:00
|
|
|
}
|
2019-11-10 02:30:02 +03:00
|
|
|
|
2020-05-10 05:39:25 +03:00
|
|
|
// Do-nothing operator for all unhandled events
|
2019-11-10 02:30:02 +03:00
|
|
|
template<typename T>
|
|
|
|
void operator()(const mtx::events::Event<T> &)
|
|
|
|
{}
|
2020-07-11 02:19:48 +03:00
|
|
|
|
2020-05-10 05:39:25 +03:00
|
|
|
// Operator for m.room.message events that contain a msgtype in their content
|
2019-11-10 02:30:02 +03:00
|
|
|
template<typename T,
|
|
|
|
std::enable_if_t<std::is_same<decltype(T::msgtype), std::string>::value, int> = 0>
|
2020-08-17 21:40:33 +03:00
|
|
|
void operator()(mtx::events::RoomEvent<T> msg)
|
2020-08-09 06:05:15 +03:00
|
|
|
{
|
2020-07-11 02:19:48 +03:00
|
|
|
sendRoomEvent<T, mtx::events::EventType::RoomMessage>(msg);
|
2020-08-09 06:05:15 +03:00
|
|
|
}
|
2019-11-10 02:30:02 +03:00
|
|
|
|
2020-05-10 05:39:25 +03:00
|
|
|
// Special operator for reactions, which are a type of m.room.message, but need to be
|
|
|
|
// handled distinctly for their differences from normal room messages. Specifically,
|
|
|
|
// reactions need to have the relation outside of ciphertext, or synapse / the homeserver
|
|
|
|
// cannot handle it correctly. See the MSC for more details:
|
|
|
|
// https://github.com/matrix-org/matrix-doc/blob/matthew/msc1849/proposals/1849-aggregations.md#end-to-end-encryption
|
2020-07-20 01:42:48 +03:00
|
|
|
void operator()(mtx::events::RoomEvent<mtx::events::msg::Reaction> msg)
|
2020-08-09 06:05:15 +03:00
|
|
|
{
|
2020-07-20 01:42:48 +03:00
|
|
|
msg.type = mtx::events::EventType::Reaction;
|
2020-07-18 18:43:49 +03:00
|
|
|
emit model_->addPendingMessageToStore(msg);
|
2020-08-09 06:05:15 +03:00
|
|
|
}
|
2020-05-10 05:39:25 +03:00
|
|
|
|
2020-07-11 02:19:48 +03:00
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::CallInvite> &event)
|
2020-08-09 06:05:15 +03:00
|
|
|
{
|
2020-07-11 02:19:48 +03:00
|
|
|
sendRoomEvent<mtx::events::msg::CallInvite, mtx::events::EventType::CallInvite>(
|
|
|
|
event);
|
2020-08-09 06:05:15 +03:00
|
|
|
}
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::CallCandidates> &event)
|
2020-08-09 06:05:15 +03:00
|
|
|
{
|
2020-07-11 02:19:48 +03:00
|
|
|
sendRoomEvent<mtx::events::msg::CallCandidates,
|
|
|
|
mtx::events::EventType::CallCandidates>(event);
|
2020-08-09 06:05:15 +03:00
|
|
|
}
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::CallAnswer> &event)
|
2020-08-09 06:05:15 +03:00
|
|
|
{
|
2020-07-11 02:19:48 +03:00
|
|
|
sendRoomEvent<mtx::events::msg::CallAnswer, mtx::events::EventType::CallAnswer>(
|
|
|
|
event);
|
2020-08-09 06:05:15 +03:00
|
|
|
}
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::CallHangUp> &event)
|
2020-08-09 06:05:15 +03:00
|
|
|
{
|
2020-07-11 02:19:48 +03:00
|
|
|
sendRoomEvent<mtx::events::msg::CallHangUp, mtx::events::EventType::CallHangUp>(
|
|
|
|
event);
|
2020-08-09 06:05:15 +03:00
|
|
|
}
|
2020-05-10 05:39:25 +03:00
|
|
|
|
2020-08-30 19:57:14 +03:00
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &msg)
|
2020-08-09 06:05:15 +03:00
|
|
|
{
|
2020-08-30 19:57:14 +03:00
|
|
|
sendRoomEvent<mtx::events::msg::KeyVerificationRequest,
|
|
|
|
mtx::events::EventType::RoomMessage>(msg);
|
2020-08-09 06:05:15 +03:00
|
|
|
}
|
|
|
|
|
2020-08-30 19:57:14 +03:00
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationReady> &msg)
|
|
|
|
{
|
|
|
|
sendRoomEvent<mtx::events::msg::KeyVerificationReady,
|
|
|
|
mtx::events::EventType::KeyVerificationReady>(msg);
|
|
|
|
}
|
2019-11-10 02:30:02 +03:00
|
|
|
|
2020-08-30 19:57:14 +03:00
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationStart> &msg)
|
2019-11-10 02:30:02 +03:00
|
|
|
{
|
2020-08-30 19:57:14 +03:00
|
|
|
sendRoomEvent<mtx::events::msg::KeyVerificationStart,
|
|
|
|
mtx::events::EventType::KeyVerificationStart>(msg);
|
|
|
|
}
|
2020-04-21 10:03:36 +03:00
|
|
|
|
2020-08-30 19:57:14 +03:00
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationAccept> &msg)
|
|
|
|
{
|
|
|
|
sendRoomEvent<mtx::events::msg::KeyVerificationAccept,
|
|
|
|
mtx::events::EventType::KeyVerificationAccept>(msg);
|
2019-11-10 02:30:02 +03:00
|
|
|
}
|
|
|
|
|
2020-08-30 19:57:14 +03:00
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationMac> &msg)
|
2020-05-10 05:39:25 +03:00
|
|
|
{
|
2020-08-30 19:57:14 +03:00
|
|
|
sendRoomEvent<mtx::events::msg::KeyVerificationMac,
|
|
|
|
mtx::events::EventType::KeyVerificationMac>(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationKey> &msg)
|
|
|
|
{
|
|
|
|
sendRoomEvent<mtx::events::msg::KeyVerificationKey,
|
|
|
|
mtx::events::EventType::KeyVerificationKey>(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationDone> &msg)
|
|
|
|
{
|
|
|
|
sendRoomEvent<mtx::events::msg::KeyVerificationDone,
|
|
|
|
mtx::events::EventType::KeyVerificationDone>(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator()(const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationCancel> &msg)
|
|
|
|
{
|
|
|
|
sendRoomEvent<mtx::events::msg::KeyVerificationCancel,
|
|
|
|
mtx::events::EventType::KeyVerificationCancel>(msg);
|
2020-05-10 05:39:25 +03:00
|
|
|
}
|
|
|
|
|
2019-11-10 02:30:02 +03:00
|
|
|
TimelineModel *model_;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineModel::addPendingMessage(mtx::events::collections::TimelineEvents event)
|
|
|
|
{
|
2020-07-18 18:43:49 +03:00
|
|
|
std::visit(
|
|
|
|
[](auto &msg) {
|
|
|
|
msg.type = mtx::events::EventType::RoomMessage;
|
|
|
|
msg.event_id = "m" + http::client()->generate_txn_id();
|
|
|
|
msg.sender = http::client()->user_id().to_string();
|
|
|
|
msg.origin_server_ts = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
},
|
|
|
|
event);
|
|
|
|
|
2020-08-09 06:05:15 +03:00
|
|
|
std::visit(SendMessageVisitor{this}, event);
|
2019-11-10 02:30:02 +03:00
|
|
|
}
|
2019-12-03 04:26:41 +03:00
|
|
|
|
2021-01-24 03:29:30 +03:00
|
|
|
void
|
|
|
|
TimelineModel::openMedia(QString eventId)
|
|
|
|
{
|
|
|
|
cacheMedia(eventId, [](QString filename) {
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-20 16:05:12 +03:00
|
|
|
bool
|
2019-12-03 04:26:41 +03:00
|
|
|
TimelineModel::saveMedia(QString eventId) const
|
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), "");
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!event)
|
|
|
|
return false;
|
2019-12-03 04:26:41 +03:00
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
QString mxcUrl = QString::fromStdString(mtx::accessors::url(*event));
|
|
|
|
QString originalFilename = QString::fromStdString(mtx::accessors::filename(*event));
|
|
|
|
QString mimeType = QString::fromStdString(mtx::accessors::mimetype(*event));
|
2019-12-03 04:26:41 +03:00
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
auto encryptionInfo = mtx::accessors::file(*event);
|
2019-12-03 04:26:41 +03:00
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
qml_mtx_events::EventType eventType = toRoomEventType(*event);
|
2019-12-03 04:26:41 +03:00
|
|
|
|
|
|
|
QString dialogTitle;
|
|
|
|
if (eventType == qml_mtx_events::EventType::ImageMessage) {
|
|
|
|
dialogTitle = tr("Save image");
|
|
|
|
} else if (eventType == qml_mtx_events::EventType::VideoMessage) {
|
|
|
|
dialogTitle = tr("Save video");
|
|
|
|
} else if (eventType == qml_mtx_events::EventType::AudioMessage) {
|
|
|
|
dialogTitle = tr("Save audio");
|
|
|
|
} else {
|
|
|
|
dialogTitle = tr("Save file");
|
|
|
|
}
|
|
|
|
|
2020-02-14 23:24:53 +03:00
|
|
|
const QString filterString = QMimeDatabase().mimeTypeForName(mimeType).filterString();
|
2020-02-15 04:35:26 +03:00
|
|
|
const QString downloadsFolder =
|
|
|
|
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
2020-02-14 23:24:53 +03:00
|
|
|
const QString openLocation = downloadsFolder + "/" + originalFilename;
|
2019-12-03 04:26:41 +03:00
|
|
|
|
2020-02-14 23:24:53 +03:00
|
|
|
const QString filename = QFileDialog::getSaveFileName(
|
|
|
|
manager_->getWidget(), dialogTitle, openLocation, filterString);
|
2019-12-03 04:26:41 +03:00
|
|
|
|
|
|
|
if (filename.isEmpty())
|
2020-03-20 16:05:12 +03:00
|
|
|
return false;
|
2019-12-03 04:26:41 +03:00
|
|
|
|
|
|
|
const auto url = mxcUrl.toStdString();
|
|
|
|
|
|
|
|
http::client()->download(
|
|
|
|
url,
|
|
|
|
[filename, url, encryptionInfo](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 {
|
|
|
|
auto temp = data;
|
|
|
|
if (encryptionInfo)
|
|
|
|
temp = mtx::crypto::to_string(
|
|
|
|
mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
|
|
|
|
|
|
|
|
QFile file(filename);
|
|
|
|
|
|
|
|
if (!file.open(QIODevice::WriteOnly))
|
|
|
|
return;
|
|
|
|
|
|
|
|
file.write(QByteArray(temp.data(), (int)temp.size()));
|
|
|
|
file.close();
|
2020-03-20 16:05:12 +03:00
|
|
|
|
|
|
|
return;
|
2019-12-03 04:26:41 +03:00
|
|
|
} catch (const std::exception &e) {
|
|
|
|
nhlog::ui()->warn("Error while saving file to: {}", e.what());
|
|
|
|
}
|
|
|
|
});
|
2020-03-20 16:05:12 +03:00
|
|
|
return true;
|
2019-12-03 04:26:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-01-24 03:29:30 +03:00
|
|
|
TimelineModel::cacheMedia(QString eventId, std::function<void(const QString)> callback)
|
2019-12-03 04:26:41 +03:00
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
mtx::events::collections::TimelineEvents *event = events.get(eventId.toStdString(), "");
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!event)
|
|
|
|
return;
|
2019-12-03 04:26:41 +03:00
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
QString mxcUrl = QString::fromStdString(mtx::accessors::url(*event));
|
|
|
|
QString originalFilename = QString::fromStdString(mtx::accessors::filename(*event));
|
|
|
|
QString mimeType = QString::fromStdString(mtx::accessors::mimetype(*event));
|
2019-12-03 04:26:41 +03:00
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
auto encryptionInfo = mtx::accessors::file(*event);
|
2019-12-03 04:26:41 +03:00
|
|
|
|
|
|
|
// If the message is a link to a non mxcUrl, don't download it
|
|
|
|
if (!mxcUrl.startsWith("mxc://")) {
|
|
|
|
emit mediaCached(mxcUrl, mxcUrl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString suffix = QMimeDatabase().mimeTypeForName(mimeType).preferredSuffix();
|
|
|
|
|
2021-01-24 03:29:30 +03:00
|
|
|
const auto url = mxcUrl.toStdString();
|
|
|
|
const auto name = QString(mxcUrl).remove("mxc://");
|
2019-12-03 04:26:41 +03:00
|
|
|
QFileInfo filename(QString("%1/media_cache/%2.%3")
|
|
|
|
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))
|
2021-01-24 03:29:30 +03:00
|
|
|
.arg(name)
|
2019-12-03 04:26:41 +03:00
|
|
|
.arg(suffix));
|
2021-01-24 03:29:30 +03:00
|
|
|
if (QDir::cleanPath(name) != name) {
|
2019-12-03 04:26:41 +03:00
|
|
|
nhlog::net()->warn("mxcUrl '{}' is not safe, not downloading file", url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDir().mkpath(filename.path());
|
|
|
|
|
|
|
|
if (filename.isReadable()) {
|
2021-03-15 06:33:06 +03:00
|
|
|
#if defined(Q_OS_WIN)
|
2019-12-03 04:26:41 +03:00
|
|
|
emit mediaCached(mxcUrl, filename.filePath());
|
2021-03-15 06:33:06 +03:00
|
|
|
#else
|
|
|
|
emit mediaCached(mxcUrl, "file://" + filename.filePath());
|
|
|
|
#endif
|
2021-01-24 03:29:30 +03:00
|
|
|
if (callback) {
|
|
|
|
callback(filename.filePath());
|
|
|
|
}
|
2019-12-03 04:26:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
http::client()->download(
|
|
|
|
url,
|
2021-01-24 03:29:30 +03:00
|
|
|
[this, callback, mxcUrl, filename, url, encryptionInfo](const std::string &data,
|
|
|
|
const std::string &,
|
|
|
|
const std::string &,
|
|
|
|
mtx::http::RequestErr err) {
|
2019-12-03 04:26:41 +03:00
|
|
|
if (err) {
|
|
|
|
nhlog::net()->warn("failed to retrieve image {}: {} {}",
|
|
|
|
url,
|
|
|
|
err->matrix_error.error,
|
|
|
|
static_cast<int>(err->status_code));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
auto temp = data;
|
|
|
|
if (encryptionInfo)
|
|
|
|
temp = mtx::crypto::to_string(
|
|
|
|
mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
|
|
|
|
|
|
|
|
QFile file(filename.filePath());
|
|
|
|
|
|
|
|
if (!file.open(QIODevice::WriteOnly))
|
|
|
|
return;
|
|
|
|
|
2020-12-25 03:08:06 +03:00
|
|
|
file.write(QByteArray(temp.data(), (int)temp.size()));
|
2019-12-03 04:26:41 +03:00
|
|
|
file.close();
|
2021-01-24 03:29:30 +03:00
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
callback(filename.filePath());
|
|
|
|
}
|
2019-12-03 04:26:41 +03:00
|
|
|
} catch (const std::exception &e) {
|
|
|
|
nhlog::ui()->warn("Error while saving file to: {}", e.what());
|
|
|
|
}
|
|
|
|
|
2021-03-15 06:33:06 +03:00
|
|
|
#if defined(Q_OS_WIN)
|
2019-12-03 04:26:41 +03:00
|
|
|
emit mediaCached(mxcUrl, filename.filePath());
|
2021-03-15 06:33:06 +03:00
|
|
|
#else
|
|
|
|
emit mediaCached(mxcUrl, "file://" + filename.filePath());
|
|
|
|
#endif
|
2019-12-03 04:26:41 +03:00
|
|
|
});
|
|
|
|
}
|
2020-01-17 03:25:14 +03:00
|
|
|
|
2021-01-24 03:29:30 +03:00
|
|
|
void
|
|
|
|
TimelineModel::cacheMedia(QString eventId)
|
|
|
|
{
|
|
|
|
cacheMedia(eventId, NULL);
|
|
|
|
}
|
|
|
|
|
2021-04-29 20:09:16 +03:00
|
|
|
void
|
|
|
|
TimelineModel::showEvent(QString eventId)
|
|
|
|
{
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
if (idToIndex(eventId) != -1) {
|
|
|
|
eventIdToShow = eventId;
|
|
|
|
emit scrollTargetChanged();
|
|
|
|
showEventTimer.start(50ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineModel::eventShown()
|
|
|
|
{
|
|
|
|
eventIdToShow.clear();
|
|
|
|
emit scrollTargetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TimelineModel::scrollTarget() const
|
|
|
|
{
|
|
|
|
return eventIdToShow;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineModel::scrollTimerEvent()
|
|
|
|
{
|
|
|
|
if (eventIdToShow.isEmpty() || showEventTimerCounter > 3) {
|
|
|
|
showEventTimer.stop();
|
|
|
|
showEventTimerCounter = 0;
|
|
|
|
} else {
|
|
|
|
emit scrollToIndex(idToIndex(eventIdToShow));
|
|
|
|
showEventTimerCounter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 22:46:49 +03:00
|
|
|
void
|
|
|
|
TimelineModel::copyLinkToEvent(QString eventId) const
|
|
|
|
{
|
|
|
|
QStringList vias;
|
|
|
|
|
|
|
|
auto alias = cache::client()->getRoomAliases(room_id_.toStdString());
|
|
|
|
QString room;
|
|
|
|
if (alias) {
|
|
|
|
room = QString::fromStdString(alias->alias);
|
|
|
|
if (room.isEmpty() && !alias->alt_aliases.empty()) {
|
|
|
|
room = QString::fromStdString(alias->alt_aliases.front());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (room.isEmpty())
|
|
|
|
room = room_id_;
|
|
|
|
|
|
|
|
vias.push_back(QString("via=%1").arg(QString(
|
|
|
|
QUrl::toPercentEncoding(QString::fromStdString(http::client()->user_id().hostname())))));
|
|
|
|
auto members = cache::getMembers(room_id_.toStdString(), 0, 100);
|
|
|
|
for (const auto &m : members) {
|
|
|
|
if (vias.size() >= 4)
|
|
|
|
break;
|
|
|
|
|
|
|
|
auto user_id =
|
|
|
|
mtx::identifiers::parse<mtx::identifiers::User>(m.user_id.toStdString());
|
|
|
|
QString server = QString("via=%1").arg(
|
|
|
|
QString(QUrl::toPercentEncoding(QString::fromStdString(user_id.hostname()))));
|
|
|
|
|
|
|
|
if (!vias.contains(server))
|
|
|
|
vias.push_back(server);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto link = QString("https://matrix.to/#/%1/%2?%3")
|
|
|
|
.arg(QString(QUrl::toPercentEncoding(room)),
|
|
|
|
QString(QUrl::toPercentEncoding(eventId)),
|
|
|
|
vias.join('&'));
|
|
|
|
|
|
|
|
QGuiApplication::clipboard()->setText(link);
|
|
|
|
}
|
|
|
|
|
2020-01-17 03:25:14 +03:00
|
|
|
QString
|
|
|
|
TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg)
|
|
|
|
{
|
|
|
|
QString temp =
|
2020-03-12 20:11:52 +03:00
|
|
|
tr("%1 and %2 are typing.",
|
2020-01-17 03:25:14 +03:00
|
|
|
"Multiple users are typing. First argument is a comma separated list of potentially "
|
|
|
|
"multiple users. Second argument is the last user of that list. (If only one user is "
|
|
|
|
"typing, %1 is empty. You should still use it in your string though to silence Qt "
|
|
|
|
"warnings.)",
|
2020-12-25 03:08:06 +03:00
|
|
|
(int)users.size());
|
2020-01-17 03:25:14 +03:00
|
|
|
|
|
|
|
if (users.empty()) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList uidWithoutLast;
|
|
|
|
|
|
|
|
auto formatUser = [this, bg](const QString &user_id) -> QString {
|
2020-09-03 20:51:50 +03:00
|
|
|
auto uncoloredUsername = utils::replaceEmoji(displayName(user_id));
|
2020-02-20 22:51:07 +03:00
|
|
|
QString prefix =
|
|
|
|
QString("<font color=\"%1\">").arg(manager_->userColor(user_id, bg).name());
|
2020-01-21 22:41:09 +03:00
|
|
|
|
|
|
|
// color only parts that don't have a font already specified
|
|
|
|
QString coloredUsername;
|
|
|
|
int index = 0;
|
|
|
|
do {
|
|
|
|
auto startIndex = uncoloredUsername.indexOf("<font", index);
|
|
|
|
|
|
|
|
if (startIndex - index != 0)
|
|
|
|
coloredUsername +=
|
|
|
|
prefix +
|
|
|
|
uncoloredUsername.midRef(
|
|
|
|
index, startIndex > 0 ? startIndex - index : -1) +
|
|
|
|
"</font>";
|
|
|
|
|
|
|
|
auto endIndex = uncoloredUsername.indexOf("</font>", startIndex);
|
|
|
|
if (endIndex > 0)
|
|
|
|
endIndex += sizeof("</font>") - 1;
|
|
|
|
|
|
|
|
if (endIndex - startIndex != 0)
|
|
|
|
coloredUsername +=
|
|
|
|
uncoloredUsername.midRef(startIndex, endIndex - startIndex);
|
|
|
|
|
|
|
|
index = endIndex;
|
|
|
|
} while (index > 0 && index < uncoloredUsername.size());
|
|
|
|
|
|
|
|
return coloredUsername;
|
2020-01-17 03:25:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i + 1 < users.size(); i++) {
|
|
|
|
uidWithoutLast.append(formatUser(users[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return temp.arg(uidWithoutLast.join(", ")).arg(formatUser(users.back()));
|
|
|
|
}
|
2020-01-23 22:34:04 +03:00
|
|
|
|
2020-02-29 03:27:51 +03:00
|
|
|
QString
|
|
|
|
TimelineModel::formatJoinRuleEvent(QString id)
|
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!e)
|
2020-02-29 03:27:51 +03:00
|
|
|
return "";
|
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::JoinRules>>(e);
|
2020-02-29 03:27:51 +03:00
|
|
|
if (!event)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
QString user = QString::fromStdString(event->sender);
|
2020-09-03 20:51:50 +03:00
|
|
|
QString name = utils::replaceEmoji(displayName(user));
|
2020-02-29 03:27:51 +03:00
|
|
|
|
|
|
|
switch (event->content.join_rule) {
|
|
|
|
case mtx::events::state::JoinRule::Public:
|
2020-03-12 20:11:52 +03:00
|
|
|
return tr("%1 opened the room to the public.").arg(name);
|
2020-02-29 03:27:51 +03:00
|
|
|
case mtx::events::state::JoinRule::Invite:
|
2020-03-12 20:11:52 +03:00
|
|
|
return tr("%1 made this room require and invitation to join.").arg(name);
|
2020-02-29 03:27:51 +03:00
|
|
|
default:
|
|
|
|
// Currently, knock and private are reserved keywords and not implemented in Matrix.
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TimelineModel::formatGuestAccessEvent(QString id)
|
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!e)
|
2020-02-29 03:27:51 +03:00
|
|
|
return "";
|
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::GuestAccess>>(e);
|
2020-02-29 03:27:51 +03:00
|
|
|
if (!event)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
QString user = QString::fromStdString(event->sender);
|
2020-09-03 20:51:50 +03:00
|
|
|
QString name = utils::replaceEmoji(displayName(user));
|
2020-02-29 03:27:51 +03:00
|
|
|
|
|
|
|
switch (event->content.guest_access) {
|
|
|
|
case mtx::events::state::AccessState::CanJoin:
|
2020-03-12 20:11:52 +03:00
|
|
|
return tr("%1 made the room open to guests.").arg(name);
|
2020-02-29 03:27:51 +03:00
|
|
|
case mtx::events::state::AccessState::Forbidden:
|
2020-03-12 20:11:52 +03:00
|
|
|
return tr("%1 has closed the room to guest access.").arg(name);
|
2020-02-29 03:27:51 +03:00
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TimelineModel::formatHistoryVisibilityEvent(QString id)
|
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!e)
|
2020-02-29 03:27:51 +03:00
|
|
|
return "";
|
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::HistoryVisibility>>(e);
|
2020-02-29 03:27:51 +03:00
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
QString user = QString::fromStdString(event->sender);
|
2020-09-03 20:51:50 +03:00
|
|
|
QString name = utils::replaceEmoji(displayName(user));
|
2020-02-29 03:27:51 +03:00
|
|
|
|
|
|
|
switch (event->content.history_visibility) {
|
|
|
|
case mtx::events::state::Visibility::WorldReadable:
|
|
|
|
return tr("%1 made the room history world readable. Events may be now read by "
|
2020-03-12 20:11:52 +03:00
|
|
|
"non-joined people.")
|
2020-02-29 03:27:51 +03:00
|
|
|
.arg(name);
|
|
|
|
case mtx::events::state::Visibility::Shared:
|
2020-03-12 20:11:52 +03:00
|
|
|
return tr("%1 set the room history visible to members from this point on.")
|
2020-02-29 03:27:51 +03:00
|
|
|
.arg(name);
|
|
|
|
case mtx::events::state::Visibility::Invited:
|
2020-03-12 20:11:52 +03:00
|
|
|
return tr("%1 set the room history visible to members since they were invited.")
|
2020-02-29 03:27:51 +03:00
|
|
|
.arg(name);
|
|
|
|
case mtx::events::state::Visibility::Joined:
|
2020-03-12 20:11:52 +03:00
|
|
|
return tr("%1 set the room history visible to members since they joined the room.")
|
2020-02-29 03:27:51 +03:00
|
|
|
.arg(name);
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TimelineModel::formatPowerLevelEvent(QString id)
|
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!e)
|
2020-02-29 03:27:51 +03:00
|
|
|
return "";
|
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::PowerLevels>>(e);
|
2020-02-29 03:27:51 +03:00
|
|
|
if (!event)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
QString user = QString::fromStdString(event->sender);
|
2020-09-03 20:51:50 +03:00
|
|
|
QString name = utils::replaceEmoji(displayName(user));
|
2020-02-29 03:27:51 +03:00
|
|
|
|
|
|
|
// TODO: power levels rendering is actually a bit complex. work on this later.
|
|
|
|
return tr("%1 has changed the room's permissions.").arg(name);
|
|
|
|
}
|
|
|
|
|
2020-01-23 22:34:04 +03:00
|
|
|
QString
|
|
|
|
TimelineModel::formatMemberEvent(QString id)
|
|
|
|
{
|
2020-07-26 13:33:30 +03:00
|
|
|
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!e)
|
2020-01-23 22:34:04 +03:00
|
|
|
return "";
|
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::Member>>(e);
|
2020-01-23 22:34:04 +03:00
|
|
|
if (!event)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
mtx::events::StateEvent<mtx::events::state::Member> *prevEvent = nullptr;
|
2020-07-10 00:15:22 +03:00
|
|
|
if (!event->unsigned_data.replaces_state.empty()) {
|
|
|
|
auto tempPrevEvent =
|
2020-07-26 13:33:30 +03:00
|
|
|
events.get(event->unsigned_data.replaces_state, event->event_id);
|
2020-07-18 18:43:49 +03:00
|
|
|
if (tempPrevEvent) {
|
2020-01-23 22:34:04 +03:00
|
|
|
prevEvent =
|
|
|
|
std::get_if<mtx::events::StateEvent<mtx::events::state::Member>>(
|
2020-07-10 00:15:22 +03:00
|
|
|
tempPrevEvent);
|
2020-01-23 22:34:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 22:32:28 +03:00
|
|
|
QString user = QString::fromStdString(event->state_key);
|
|
|
|
QString name = utils::replaceEmoji(displayName(user));
|
2020-02-29 03:27:51 +03:00
|
|
|
QString rendered;
|
2020-01-23 22:34:04 +03:00
|
|
|
|
|
|
|
// see table https://matrix.org/docs/spec/client_server/latest#m-room-member
|
|
|
|
using namespace mtx::events::state;
|
|
|
|
switch (event->content.membership) {
|
|
|
|
case Membership::Invite:
|
2020-02-29 03:27:51 +03:00
|
|
|
rendered = tr("%1 was invited.").arg(name);
|
|
|
|
break;
|
2020-01-23 22:34:04 +03:00
|
|
|
case Membership::Join:
|
|
|
|
if (prevEvent && prevEvent->content.membership == Membership::Join) {
|
2021-04-18 22:32:28 +03:00
|
|
|
QString oldName = QString::fromStdString(prevEvent->content.display_name);
|
|
|
|
|
2020-01-23 22:34:04 +03:00
|
|
|
bool displayNameChanged =
|
|
|
|
prevEvent->content.display_name != event->content.display_name;
|
|
|
|
bool avatarChanged =
|
|
|
|
prevEvent->content.avatar_url != event->content.avatar_url;
|
|
|
|
|
|
|
|
if (displayNameChanged && avatarChanged)
|
2021-04-18 09:13:02 +03:00
|
|
|
rendered = tr("%1 has changed their avatar and changed their "
|
|
|
|
"display name to %2.")
|
|
|
|
.arg(oldName, name);
|
2020-01-23 22:34:04 +03:00
|
|
|
else if (displayNameChanged)
|
2021-04-18 09:13:02 +03:00
|
|
|
rendered =
|
|
|
|
tr("%1 has changed their display name to %2.").arg(oldName, name);
|
2020-01-23 22:34:04 +03:00
|
|
|
else if (avatarChanged)
|
2020-02-29 03:27:51 +03:00
|
|
|
rendered = tr("%1 changed their avatar.").arg(name);
|
2020-05-23 01:24:58 +03:00
|
|
|
else
|
|
|
|
rendered = tr("%1 changed some profile info.").arg(name);
|
2020-01-23 22:34:04 +03:00
|
|
|
// the case of nothing changed but join follows join shouldn't happen, so
|
|
|
|
// just show it as join
|
2020-02-29 03:27:51 +03:00
|
|
|
} else {
|
|
|
|
rendered = tr("%1 joined.").arg(name);
|
2020-01-23 22:34:04 +03:00
|
|
|
}
|
2020-02-29 03:27:51 +03:00
|
|
|
break;
|
2020-01-23 22:34:04 +03:00
|
|
|
case Membership::Leave:
|
|
|
|
if (!prevEvent) // Should only ever happen temporarily
|
|
|
|
return "";
|
|
|
|
|
|
|
|
if (prevEvent->content.membership == Membership::Invite) {
|
|
|
|
if (event->state_key == event->sender)
|
2020-02-29 03:27:51 +03:00
|
|
|
rendered = tr("%1 rejected their invite.").arg(name);
|
2020-01-23 22:34:04 +03:00
|
|
|
else
|
2020-02-29 03:27:51 +03:00
|
|
|
rendered = tr("Revoked the invite to %1.").arg(name);
|
2020-01-23 22:34:04 +03:00
|
|
|
} else if (prevEvent->content.membership == Membership::Join) {
|
|
|
|
if (event->state_key == event->sender)
|
2020-02-29 03:27:51 +03:00
|
|
|
rendered = tr("%1 left the room.").arg(name);
|
2020-01-23 22:34:04 +03:00
|
|
|
else
|
2020-02-29 03:27:51 +03:00
|
|
|
rendered = tr("Kicked %1.").arg(name);
|
2020-01-23 22:34:04 +03:00
|
|
|
} else if (prevEvent->content.membership == Membership::Ban) {
|
2020-03-12 20:11:52 +03:00
|
|
|
rendered = tr("Unbanned %1.").arg(name);
|
2020-01-23 22:34:04 +03:00
|
|
|
} else if (prevEvent->content.membership == Membership::Knock) {
|
|
|
|
if (event->state_key == event->sender)
|
2020-02-29 03:27:51 +03:00
|
|
|
rendered = tr("%1 redacted their knock.").arg(name);
|
2020-01-23 22:34:04 +03:00
|
|
|
else
|
2020-02-29 03:27:51 +03:00
|
|
|
rendered = tr("Rejected the knock from %1.").arg(name);
|
2020-01-23 22:34:04 +03:00
|
|
|
} else
|
|
|
|
return tr("%1 left after having already left!",
|
2020-02-29 03:27:51 +03:00
|
|
|
"This is a leave event after the user already left and shouldn't "
|
2020-01-23 22:34:04 +03:00
|
|
|
"happen apart from state resets")
|
|
|
|
.arg(name);
|
2020-02-29 03:27:51 +03:00
|
|
|
break;
|
2020-01-23 22:34:04 +03:00
|
|
|
|
|
|
|
case Membership::Ban:
|
2020-03-12 20:11:52 +03:00
|
|
|
rendered = tr("%1 was banned.").arg(name);
|
2020-02-29 03:27:51 +03:00
|
|
|
break;
|
2020-01-23 22:34:04 +03:00
|
|
|
case Membership::Knock:
|
2020-02-29 03:27:51 +03:00
|
|
|
rendered = tr("%1 knocked.").arg(name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->content.reason != "") {
|
|
|
|
rendered += tr(" Reason: %1").arg(QString::fromStdString(event->content.reason));
|
2020-01-23 22:34:04 +03:00
|
|
|
}
|
2020-02-29 03:27:51 +03:00
|
|
|
|
|
|
|
return rendered;
|
2020-01-23 22:34:04 +03:00
|
|
|
}
|
2020-09-03 18:01:58 +03:00
|
|
|
|
2021-02-01 00:41:43 +03:00
|
|
|
void
|
|
|
|
TimelineModel::setEdit(QString newEdit)
|
|
|
|
{
|
2021-02-10 20:07:55 +03:00
|
|
|
if (edit_.startsWith('m'))
|
|
|
|
return;
|
|
|
|
|
2021-02-25 01:51:05 +03:00
|
|
|
if (newEdit.isEmpty()) {
|
|
|
|
resetEdit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edit_.isEmpty()) {
|
|
|
|
this->textBeforeEdit = input()->text();
|
|
|
|
this->replyBeforeEdit = reply_;
|
|
|
|
nhlog::ui()->debug("Stored: {}", textBeforeEdit.toStdString());
|
|
|
|
}
|
|
|
|
|
2021-02-01 00:41:43 +03:00
|
|
|
if (edit_ != newEdit) {
|
|
|
|
auto ev = events.get(newEdit.toStdString(), "");
|
2021-02-10 16:32:16 +03:00
|
|
|
if (ev && mtx::accessors::sender(*ev) == http::client()->user_id().to_string()) {
|
2021-02-12 18:10:48 +03:00
|
|
|
auto e = *ev;
|
2021-02-01 00:41:43 +03:00
|
|
|
setReply(QString::fromStdString(
|
2021-02-12 18:10:48 +03:00
|
|
|
mtx::accessors::relations(e).reply_to().value_or("")));
|
2021-02-01 04:22:53 +03:00
|
|
|
|
2021-02-12 18:10:48 +03:00
|
|
|
auto msgType = mtx::accessors::msg_type(e);
|
2021-02-01 04:22:53 +03:00
|
|
|
if (msgType == mtx::events::MessageType::Text ||
|
2021-03-15 22:59:18 +03:00
|
|
|
msgType == mtx::events::MessageType::Notice ||
|
|
|
|
msgType == mtx::events::MessageType::Emote) {
|
|
|
|
auto relInfo = relatedInfo(newEdit);
|
|
|
|
auto editText = relInfo.quoted_body;
|
|
|
|
|
|
|
|
if (!relInfo.quoted_formatted_body.isEmpty()) {
|
|
|
|
auto matches = conf::strings::matrixToLink.globalMatch(
|
|
|
|
relInfo.quoted_formatted_body);
|
|
|
|
std::map<QString, QString> reverseNameMapping;
|
|
|
|
while (matches.hasNext()) {
|
|
|
|
auto m = matches.next();
|
|
|
|
reverseNameMapping[m.captured(2)] = m.captured(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &[user, link] : reverseNameMapping) {
|
|
|
|
// TODO(Nico): html unescape the user name
|
|
|
|
editText.replace(
|
|
|
|
user, QStringLiteral("[%1](%2)").arg(user, link));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msgType == mtx::events::MessageType::Emote)
|
|
|
|
input()->setText("/me " + editText);
|
|
|
|
else
|
|
|
|
input()->setText(editText);
|
2021-02-01 04:22:53 +03:00
|
|
|
} else {
|
|
|
|
input()->setText("");
|
|
|
|
}
|
2021-02-12 18:10:48 +03:00
|
|
|
|
|
|
|
edit_ = newEdit;
|
2021-02-01 04:22:53 +03:00
|
|
|
} else {
|
2021-02-12 18:10:48 +03:00
|
|
|
resetReply();
|
|
|
|
|
2021-02-01 04:22:53 +03:00
|
|
|
input()->setText("");
|
2021-02-12 18:10:48 +03:00
|
|
|
edit_ = "";
|
2021-02-01 00:41:43 +03:00
|
|
|
}
|
2021-02-12 18:10:48 +03:00
|
|
|
emit editChanged(edit_);
|
2021-02-01 00:41:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-01 04:22:53 +03:00
|
|
|
void
|
|
|
|
TimelineModel::resetEdit()
|
|
|
|
{
|
|
|
|
if (!edit_.isEmpty()) {
|
|
|
|
edit_ = "";
|
|
|
|
emit editChanged(edit_);
|
2021-02-25 01:51:05 +03:00
|
|
|
nhlog::ui()->debug("Restoring: {}", textBeforeEdit.toStdString());
|
|
|
|
input()->setText(textBeforeEdit);
|
|
|
|
textBeforeEdit.clear();
|
|
|
|
if (replyBeforeEdit.isEmpty())
|
|
|
|
resetReply();
|
|
|
|
else
|
|
|
|
setReply(replyBeforeEdit);
|
|
|
|
replyBeforeEdit.clear();
|
2021-02-01 04:22:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 18:01:58 +03:00
|
|
|
QString
|
|
|
|
TimelineModel::roomName() const
|
|
|
|
{
|
|
|
|
auto info = cache::getRoomInfo({room_id_.toStdString()});
|
|
|
|
|
|
|
|
if (!info.count(room_id_))
|
|
|
|
return "";
|
|
|
|
else
|
2021-04-19 12:20:34 +03:00
|
|
|
return utils::replaceEmoji(
|
|
|
|
QString::fromStdString(info[room_id_].name).toHtmlEscaped());
|
2020-09-03 18:01:58 +03:00
|
|
|
}
|
|
|
|
|
2021-05-22 11:16:42 +03:00
|
|
|
QString
|
|
|
|
TimelineModel::plainRoomName() const
|
|
|
|
{
|
|
|
|
auto info = cache::getRoomInfo({room_id_.toStdString()});
|
|
|
|
|
|
|
|
if (!info.count(room_id_))
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return QString::fromStdString(info[room_id_].name);
|
|
|
|
}
|
|
|
|
|
2020-09-03 18:01:58 +03:00
|
|
|
QString
|
|
|
|
TimelineModel::roomAvatarUrl() const
|
|
|
|
{
|
|
|
|
auto info = cache::getRoomInfo({room_id_.toStdString()});
|
|
|
|
|
|
|
|
if (!info.count(room_id_))
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return QString::fromStdString(info[room_id_].avatar_url);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
TimelineModel::roomTopic() const
|
|
|
|
{
|
|
|
|
auto info = cache::getRoomInfo({room_id_.toStdString()});
|
|
|
|
|
|
|
|
if (!info.count(room_id_))
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return utils::replaceEmoji(utils::linkifyMessage(
|
2021-04-19 12:20:34 +03:00
|
|
|
QString::fromStdString(info[room_id_].topic).toHtmlEscaped()));
|
2020-09-03 18:01:58 +03:00
|
|
|
}
|