2023-02-22 01:48:49 +03:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2021-03-05 02:35:15 +03:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2019-08-31 00:20:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QColor>
|
2019-09-01 23:58:26 +03:00
|
|
|
#include <QDate>
|
2019-09-18 23:58:25 +03:00
|
|
|
#include <QSet>
|
2021-04-29 20:09:16 +03:00
|
|
|
#include <QTimer>
|
2021-11-29 03:59:57 +03:00
|
|
|
#include <QVariant>
|
2019-08-31 00:20:53 +03:00
|
|
|
|
2019-12-15 05:19:33 +03:00
|
|
|
#include <mtxclient/http/errors.hpp>
|
2019-10-06 13:59:51 +03:00
|
|
|
|
2019-12-15 01:39:02 +03:00
|
|
|
#include "CacheCryptoStructs.h"
|
2021-05-21 22:19:03 +03:00
|
|
|
#include "CacheStructs.h"
|
2020-07-10 00:15:22 +03:00
|
|
|
#include "EventStore.h"
|
2020-11-01 01:24:07 +03:00
|
|
|
#include "InputBar.h"
|
2021-06-11 03:13:12 +03:00
|
|
|
#include "InviteesModel.h"
|
2021-05-30 04:09:21 +03:00
|
|
|
#include "MemberList.h"
|
2021-05-02 19:01:18 +03:00
|
|
|
#include "Permissions.h"
|
2021-07-24 01:11:33 +03:00
|
|
|
#include "ReadReceiptsModel.h"
|
2022-09-20 22:26:28 +03:00
|
|
|
#include "ui/RoomSummary.h"
|
2019-12-15 05:19:33 +03:00
|
|
|
|
|
|
|
namespace mtx::http {
|
|
|
|
using RequestErr = const std::optional<mtx::http::ClientError> &;
|
|
|
|
}
|
2020-01-31 08:12:02 +03:00
|
|
|
namespace mtx::responses {
|
|
|
|
struct Timeline;
|
|
|
|
struct Messages;
|
|
|
|
struct ClaimKeys;
|
2022-06-18 02:35:30 +03:00
|
|
|
struct StateEvents;
|
2020-01-31 08:12:02 +03:00
|
|
|
}
|
2020-04-13 17:22:30 +03:00
|
|
|
struct RelatedInfo;
|
2019-09-11 01:00:04 +03:00
|
|
|
|
2019-09-03 00:28:05 +03:00
|
|
|
namespace qml_mtx_events {
|
|
|
|
Q_NAMESPACE
|
|
|
|
|
|
|
|
enum EventType
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
// Unsupported event
|
|
|
|
Unsupported,
|
|
|
|
/// m.room_key_request
|
|
|
|
KeyRequest,
|
|
|
|
/// m.reaction,
|
|
|
|
Reaction,
|
|
|
|
/// m.room.aliases
|
|
|
|
Aliases,
|
|
|
|
/// m.room.avatar
|
|
|
|
Avatar,
|
|
|
|
/// m.call.invite
|
|
|
|
CallInvite,
|
|
|
|
/// m.call.answer
|
|
|
|
CallAnswer,
|
|
|
|
/// m.call.hangup
|
|
|
|
CallHangUp,
|
|
|
|
/// m.call.candidates
|
|
|
|
CallCandidates,
|
2022-10-14 16:49:05 +03:00
|
|
|
/// m.call.select_answer
|
|
|
|
CallSelectAnswer,
|
|
|
|
/// m.call.reject
|
|
|
|
CallReject,
|
|
|
|
/// m.call.negotiate
|
|
|
|
CallNegotiate,
|
2021-09-18 01:22:33 +03:00
|
|
|
/// m.room.canonical_alias
|
|
|
|
CanonicalAlias,
|
|
|
|
/// m.room.create
|
|
|
|
RoomCreate,
|
|
|
|
/// m.room.encrypted.
|
|
|
|
Encrypted,
|
|
|
|
/// m.room.encryption.
|
|
|
|
Encryption,
|
|
|
|
/// m.room.guest_access
|
|
|
|
RoomGuestAccess,
|
|
|
|
/// m.room.history_visibility
|
|
|
|
RoomHistoryVisibility,
|
|
|
|
/// m.room.join_rules
|
|
|
|
RoomJoinRules,
|
|
|
|
/// m.room.member
|
|
|
|
Member,
|
|
|
|
/// m.room.name
|
|
|
|
Name,
|
|
|
|
/// m.room.power_levels
|
|
|
|
PowerLevels,
|
|
|
|
/// m.room.tombstone
|
|
|
|
Tombstone,
|
|
|
|
/// m.room.topic
|
|
|
|
Topic,
|
|
|
|
/// m.room.redaction
|
|
|
|
Redaction,
|
|
|
|
/// m.room.pinned_events
|
|
|
|
PinnedEvents,
|
|
|
|
// m.sticker
|
|
|
|
Sticker,
|
|
|
|
// m.tag
|
|
|
|
Tag,
|
2022-02-04 20:47:17 +03:00
|
|
|
// m.widget
|
|
|
|
Widget,
|
2021-09-18 01:22:33 +03:00
|
|
|
/// m.room.message
|
|
|
|
AudioMessage,
|
2023-04-01 22:41:49 +03:00
|
|
|
ElementEffectMessage,
|
2021-09-18 01:22:33 +03:00
|
|
|
EmoteMessage,
|
|
|
|
FileMessage,
|
|
|
|
ImageMessage,
|
|
|
|
LocationMessage,
|
|
|
|
NoticeMessage,
|
|
|
|
TextMessage,
|
2023-03-07 03:21:23 +03:00
|
|
|
UnknownMessage,
|
2021-09-18 01:22:33 +03:00
|
|
|
VideoMessage,
|
|
|
|
Redacted,
|
2023-03-07 03:21:23 +03:00
|
|
|
UnknownEvent,
|
2021-09-18 01:22:33 +03:00
|
|
|
KeyVerificationRequest,
|
|
|
|
KeyVerificationStart,
|
|
|
|
KeyVerificationMac,
|
|
|
|
KeyVerificationAccept,
|
|
|
|
KeyVerificationCancel,
|
|
|
|
KeyVerificationKey,
|
|
|
|
KeyVerificationDone,
|
|
|
|
KeyVerificationReady,
|
|
|
|
//! m.image_pack, currently im.ponies.room_emotes
|
|
|
|
ImagePackInRoom,
|
|
|
|
//! m.image_pack, currently im.ponies.user_emotes
|
|
|
|
ImagePackInAccountData,
|
|
|
|
//! m.image_pack.rooms, currently im.ponies.emote_rooms
|
|
|
|
ImagePackRooms,
|
2022-07-09 16:36:15 +03:00
|
|
|
// m.policy.rule.user
|
|
|
|
PolicyRuleUser,
|
|
|
|
// m.policy.rule.room
|
|
|
|
PolicyRuleRoom,
|
|
|
|
// m.policy.rule.server
|
|
|
|
PolicyRuleServer,
|
2021-12-11 08:10:41 +03:00
|
|
|
// m.space.parent
|
|
|
|
SpaceParent,
|
|
|
|
// m.space.child
|
|
|
|
SpaceChild,
|
2019-09-03 00:28:05 +03:00
|
|
|
};
|
|
|
|
Q_ENUM_NS(EventType)
|
2021-05-02 19:01:18 +03:00
|
|
|
mtx::events::EventType fromRoomEventType(qml_mtx_events::EventType);
|
2022-02-12 21:27:51 +03:00
|
|
|
qml_mtx_events::EventType
|
|
|
|
toRoomEventType(mtx::events::EventType e);
|
2019-09-18 23:58:25 +03:00
|
|
|
|
|
|
|
enum EventState
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
//! The plaintext message was received by the server.
|
|
|
|
Received,
|
|
|
|
//! At least one of the participants has read the message.
|
|
|
|
Read,
|
|
|
|
//! The client sent the message. Not yet received.
|
|
|
|
Sent,
|
2023-01-13 01:51:22 +03:00
|
|
|
//! The client sent the message, but it failed.
|
|
|
|
Failed,
|
2021-09-18 01:22:33 +03:00
|
|
|
//! When the message is loaded from cache or backfill.
|
|
|
|
Empty,
|
2019-09-18 23:58:25 +03:00
|
|
|
};
|
|
|
|
Q_ENUM_NS(EventState)
|
2022-11-02 01:26:21 +03:00
|
|
|
|
|
|
|
enum NotificationLevel
|
|
|
|
{
|
|
|
|
Nothing,
|
|
|
|
Notify,
|
|
|
|
Highlight,
|
|
|
|
};
|
|
|
|
Q_ENUM_NS(NotificationLevel)
|
2019-09-03 00:28:05 +03:00
|
|
|
}
|
|
|
|
|
2019-09-19 23:44:25 +03:00
|
|
|
class StateKeeper
|
|
|
|
{
|
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
StateKeeper(std::function<void()> &&fn)
|
|
|
|
: fn_(std::move(fn))
|
2022-09-25 21:05:08 +03:00
|
|
|
{
|
|
|
|
}
|
2019-09-19 23:44:25 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
~StateKeeper() { fn_(); }
|
2019-09-19 23:44:25 +03:00
|
|
|
|
|
|
|
private:
|
2021-09-18 01:22:33 +03:00
|
|
|
std::function<void()> fn_;
|
2019-09-19 23:44:25 +03:00
|
|
|
};
|
|
|
|
|
2019-09-08 17:50:32 +03:00
|
|
|
struct DecryptionResult
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
//! The decrypted content as a normal plaintext event.
|
|
|
|
mtx::events::collections::TimelineEvents event;
|
|
|
|
//! Whether or not the decryption was successful.
|
|
|
|
bool isDecrypted = false;
|
2019-09-08 17:50:32 +03:00
|
|
|
};
|
|
|
|
|
2019-10-03 19:07:01 +03:00
|
|
|
class TimelineViewManager;
|
|
|
|
|
2022-10-10 15:38:29 +03:00
|
|
|
class TimelineModel final : public QAbstractListModel
|
2019-08-31 00:20:53 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
|
|
|
|
Q_PROPERTY(std::vector<QString> typingUsers READ typingUsers WRITE updateTypingUsers NOTIFY
|
|
|
|
typingUsersChanged)
|
|
|
|
Q_PROPERTY(QString scrollTarget READ scrollTarget NOTIFY scrollTargetChanged)
|
|
|
|
Q_PROPERTY(QString reply READ reply WRITE setReply NOTIFY replyChanged RESET resetReply)
|
|
|
|
Q_PROPERTY(QString edit READ edit WRITE setEdit NOTIFY editChanged RESET resetEdit)
|
2022-09-30 04:27:05 +03:00
|
|
|
Q_PROPERTY(QString thread READ thread WRITE setThread NOTIFY threadChanged RESET resetThread)
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_PROPERTY(
|
|
|
|
bool paginationInProgress READ paginationInProgress NOTIFY paginationInProgressChanged)
|
|
|
|
Q_PROPERTY(QString roomId READ roomId CONSTANT)
|
|
|
|
Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged)
|
2022-07-15 17:19:06 +03:00
|
|
|
Q_PROPERTY(QString plainRoomName READ plainRoomName NOTIFY roomNameChanged)
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl NOTIFY roomAvatarUrlChanged)
|
|
|
|
Q_PROPERTY(QString roomTopic READ roomTopic NOTIFY roomTopicChanged)
|
2021-12-11 08:10:41 +03:00
|
|
|
Q_PROPERTY(QStringList pinnedMessages READ pinnedMessages NOTIFY pinnedMessagesChanged)
|
2022-02-04 20:47:17 +03:00
|
|
|
Q_PROPERTY(QStringList widgetLinks READ widgetLinks NOTIFY widgetLinksChanged)
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_PROPERTY(int roomMemberCount READ roomMemberCount NOTIFY roomMemberCountChanged)
|
|
|
|
Q_PROPERTY(bool isEncrypted READ isEncrypted NOTIFY encryptionChanged)
|
2022-09-12 02:05:20 +03:00
|
|
|
Q_PROPERTY(QString fullyReadEventId READ fullyReadEventId NOTIFY fullyReadEventIdChanged)
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_PROPERTY(bool isSpace READ isSpace CONSTANT)
|
|
|
|
Q_PROPERTY(int trustlevel READ trustlevel NOTIFY trustlevelChanged)
|
|
|
|
Q_PROPERTY(bool isDirect READ isDirect NOTIFY isDirectChanged)
|
|
|
|
Q_PROPERTY(
|
|
|
|
QString directChatOtherUserId READ directChatOtherUserId NOTIFY directChatOtherUserIdChanged)
|
|
|
|
Q_PROPERTY(InputBar *input READ input CONSTANT)
|
|
|
|
Q_PROPERTY(Permissions *permissions READ permissions NOTIFY permissionsChanged)
|
2022-09-20 22:26:28 +03:00
|
|
|
Q_PROPERTY(RoomSummary *parentSpace READ parentSpace NOTIFY parentSpaceChanged)
|
2019-08-31 00:20:53 +03:00
|
|
|
|
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
explicit TimelineModel(TimelineViewManager *manager,
|
2021-12-28 20:44:26 +03:00
|
|
|
QString room_id,
|
2021-09-18 01:22:33 +03:00
|
|
|
QObject *parent = nullptr);
|
|
|
|
|
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
Type,
|
|
|
|
TypeString,
|
|
|
|
IsOnlyEmoji,
|
|
|
|
Body,
|
|
|
|
FormattedBody,
|
|
|
|
IsSender,
|
|
|
|
UserId,
|
|
|
|
UserName,
|
|
|
|
Day,
|
|
|
|
Timestamp,
|
|
|
|
Url,
|
|
|
|
ThumbnailUrl,
|
2022-03-21 02:48:27 +03:00
|
|
|
Duration,
|
2021-09-18 01:22:33 +03:00
|
|
|
Blurhash,
|
|
|
|
Filename,
|
|
|
|
Filesize,
|
|
|
|
MimeType,
|
|
|
|
OriginalHeight,
|
|
|
|
OriginalWidth,
|
|
|
|
ProportionalHeight,
|
|
|
|
EventId,
|
|
|
|
State,
|
|
|
|
IsEdited,
|
|
|
|
IsEditable,
|
|
|
|
IsEncrypted,
|
2022-02-07 23:53:37 +03:00
|
|
|
IsStateEvent,
|
2021-09-18 01:22:33 +03:00
|
|
|
Trustlevel,
|
2022-11-02 01:26:21 +03:00
|
|
|
Notificationlevel,
|
2021-09-18 01:22:33 +03:00
|
|
|
EncryptionError,
|
|
|
|
ReplyTo,
|
2022-09-30 04:27:05 +03:00
|
|
|
ThreadId,
|
2021-09-18 01:22:33 +03:00
|
|
|
Reactions,
|
|
|
|
RoomId,
|
|
|
|
RoomName,
|
|
|
|
RoomTopic,
|
|
|
|
CallType,
|
|
|
|
Dump,
|
|
|
|
RelatedEventCacheBuster,
|
|
|
|
};
|
|
|
|
Q_ENUM(Roles);
|
|
|
|
|
2023-03-07 21:11:00 +03:00
|
|
|
enum SpecialEffect
|
|
|
|
{
|
|
|
|
Confetti,
|
|
|
|
Rainfall,
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(SpecialEffects, SpecialEffect)
|
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
|
|
QVariant data(const mtx::events::collections::TimelineEvents &event, int role) const;
|
2021-12-23 04:33:46 +03:00
|
|
|
Q_INVOKABLE QVariant dataById(const QString &id, int role, const QString &relatedTo);
|
2022-10-06 22:59:59 +03:00
|
|
|
Q_INVOKABLE QVariant dataByIndex(int i, int role = Qt::DisplayRole) const
|
|
|
|
{
|
|
|
|
return data(index(i), role);
|
|
|
|
}
|
2021-09-18 01:22:33 +03:00
|
|
|
|
|
|
|
bool canFetchMore(const QModelIndex &) const override;
|
|
|
|
void fetchMore(const QModelIndex &) override;
|
|
|
|
|
2022-06-24 02:44:50 +03:00
|
|
|
static QString getBareRoomLink(const QString &);
|
|
|
|
static QString getRoomVias(const QString &);
|
|
|
|
|
2021-12-23 04:55:25 +03:00
|
|
|
Q_INVOKABLE QString displayName(const QString &id) const;
|
|
|
|
Q_INVOKABLE QString avatarUrl(const QString &id) const;
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_INVOKABLE QString formatDateSeparator(QDate date) const;
|
2021-12-23 04:46:33 +03:00
|
|
|
Q_INVOKABLE QString formatTypingUsers(const std::vector<QString> &users, const QColor &bg);
|
2021-12-23 04:33:46 +03:00
|
|
|
Q_INVOKABLE bool showAcceptKnockButton(const QString &id);
|
|
|
|
Q_INVOKABLE void acceptKnock(const QString &id);
|
2022-12-13 07:08:05 +03:00
|
|
|
Q_INVOKABLE void joinReplacementRoom(const QString &id);
|
2021-12-23 04:33:46 +03:00
|
|
|
Q_INVOKABLE QString formatMemberEvent(const QString &id);
|
|
|
|
Q_INVOKABLE QString formatJoinRuleEvent(const QString &id);
|
|
|
|
Q_INVOKABLE QString formatHistoryVisibilityEvent(const QString &id);
|
|
|
|
Q_INVOKABLE QString formatGuestAccessEvent(const QString &id);
|
|
|
|
Q_INVOKABLE QString formatPowerLevelEvent(const QString &id);
|
2022-04-19 23:33:53 +03:00
|
|
|
Q_INVOKABLE QString formatImagePackEvent(const QString &id);
|
2022-07-09 16:36:15 +03:00
|
|
|
Q_INVOKABLE QString formatPolicyRule(const QString &id);
|
2021-12-23 04:33:46 +03:00
|
|
|
Q_INVOKABLE QVariantMap formatRedactedEvent(const QString &id);
|
2021-09-18 01:22:33 +03:00
|
|
|
|
2021-12-23 04:33:46 +03:00
|
|
|
Q_INVOKABLE void viewRawMessage(const QString &id);
|
|
|
|
Q_INVOKABLE void forwardMessage(const QString &eventId, QString roomId);
|
2021-12-23 04:46:33 +03:00
|
|
|
Q_INVOKABLE void viewDecryptedRawMessage(const QString &id);
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_INVOKABLE void openUserProfile(QString userid);
|
2021-12-23 04:33:46 +03:00
|
|
|
Q_INVOKABLE void unpin(const QString &id);
|
|
|
|
Q_INVOKABLE void pin(const QString &id);
|
2022-10-04 00:57:30 +03:00
|
|
|
Q_INVOKABLE void showReadReceipts(const QString &id);
|
2022-03-06 16:46:52 +03:00
|
|
|
Q_INVOKABLE void redactEvent(const QString &id, const QString &reason = "");
|
2022-07-01 11:24:12 +03:00
|
|
|
Q_INVOKABLE void redactAllFromUser(const QString &userid, const QString &reason = "");
|
2021-12-23 04:33:46 +03:00
|
|
|
Q_INVOKABLE int idToIndex(const QString &id) const;
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_INVOKABLE QString indexToId(int index) const;
|
2021-12-23 04:46:33 +03:00
|
|
|
Q_INVOKABLE void openMedia(const QString &eventId);
|
2021-12-23 04:33:46 +03:00
|
|
|
Q_INVOKABLE void cacheMedia(const QString &eventId);
|
|
|
|
Q_INVOKABLE bool saveMedia(const QString &eventId) const;
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_INVOKABLE void showEvent(QString eventId);
|
2021-12-23 04:33:46 +03:00
|
|
|
Q_INVOKABLE void copyLinkToEvent(const QString &eventId) const;
|
2022-05-27 17:31:54 +03:00
|
|
|
|
2021-12-27 22:49:27 +03:00
|
|
|
void
|
|
|
|
cacheMedia(const QString &eventId, const std::function<void(const QString filename)> &callback);
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_INVOKABLE void sendReset()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
2021-12-23 04:33:46 +03:00
|
|
|
Q_INVOKABLE void requestKeyForEvent(const QString &id);
|
2021-09-18 01:22:33 +03:00
|
|
|
|
|
|
|
std::vector<::Reaction> reactions(const std::string &event_id)
|
|
|
|
{
|
|
|
|
auto list = events.reactions(event_id);
|
|
|
|
std::vector<::Reaction> vec;
|
2021-12-29 08:01:38 +03:00
|
|
|
vec.reserve(list.size());
|
2021-09-18 01:22:33 +03:00
|
|
|
for (const auto &r : list)
|
|
|
|
vec.push_back(r.value<Reaction>());
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateLastMessage();
|
|
|
|
void sync(const mtx::responses::JoinedRoom &room);
|
|
|
|
void addEvents(const mtx::responses::Timeline &events);
|
|
|
|
void syncState(const mtx::responses::State &state);
|
|
|
|
template<class T>
|
|
|
|
void sendMessageEvent(const T &content, mtx::events::EventType eventType);
|
2021-12-23 04:33:46 +03:00
|
|
|
RelatedInfo relatedInfo(const QString &id);
|
2021-09-18 01:22:33 +03:00
|
|
|
|
2022-06-15 03:13:17 +03:00
|
|
|
DescInfo lastMessage() const;
|
|
|
|
uint64_t lastMessageTimestamp() const { return lastMessage_.timestamp; }
|
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
bool isSpace() const { return isSpace_; }
|
|
|
|
bool isEncrypted() const { return isEncrypted_; }
|
2022-09-12 02:05:20 +03:00
|
|
|
QString fullyReadEventId() const { return QString::fromStdString(fullyReadEventId_); }
|
2021-09-18 01:22:33 +03:00
|
|
|
crypto::Trust trustlevel() const;
|
|
|
|
int roomMemberCount() const;
|
|
|
|
bool isDirect() const { return roomMemberCount() <= 2; }
|
|
|
|
QString directChatOtherUserId() const;
|
|
|
|
|
2022-10-13 18:19:54 +03:00
|
|
|
mtx::pushrules::PushRuleEvaluator::RoomContext pushrulesRoomContext() const;
|
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
std::optional<mtx::events::collections::TimelineEvents> eventById(const QString &id)
|
|
|
|
{
|
|
|
|
auto e = events.get(id.toStdString(), "");
|
|
|
|
if (e)
|
|
|
|
return *e;
|
|
|
|
else
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
2021-08-28 01:38:33 +03:00
|
|
|
|
2019-09-01 00:44:17 +03:00
|
|
|
public slots:
|
2021-09-18 01:22:33 +03:00
|
|
|
void setCurrentIndex(int index);
|
|
|
|
int currentIndex() const { return idToIndex(currentId); }
|
|
|
|
void eventShown();
|
|
|
|
void markEventsAsRead(const std::vector<QString> &event_ids);
|
2022-10-04 00:57:30 +03:00
|
|
|
void updateLastReadId(const QString ¤tRoomId);
|
2022-09-12 02:05:20 +03:00
|
|
|
void lastReadIdOnWindowFocus();
|
|
|
|
void checkAfterFetch();
|
2021-12-23 04:33:46 +03:00
|
|
|
QVariantMap getDump(const QString &eventId, const QString &relatedTo) const;
|
2021-09-18 01:22:33 +03:00
|
|
|
void updateTypingUsers(const std::vector<QString> &users)
|
|
|
|
{
|
|
|
|
if (this->typingUsers_ != users) {
|
|
|
|
this->typingUsers_ = users;
|
|
|
|
emit typingUsersChanged(typingUsers_);
|
2020-01-17 03:25:14 +03:00
|
|
|
}
|
2021-09-18 01:22:33 +03:00
|
|
|
}
|
|
|
|
std::vector<QString> typingUsers() const { return typingUsers_; }
|
|
|
|
bool paginationInProgress() const { return m_paginationInProgress; }
|
|
|
|
QString reply() const { return reply_; }
|
2022-09-30 04:43:42 +03:00
|
|
|
void setReply(const QString &newReply);
|
2021-09-18 01:22:33 +03:00
|
|
|
void resetReply()
|
|
|
|
{
|
|
|
|
if (!reply_.isEmpty()) {
|
2021-12-29 06:28:08 +03:00
|
|
|
reply_ = QLatin1String("");
|
2021-09-18 01:22:33 +03:00
|
|
|
emit replyChanged(reply_);
|
2020-04-13 17:22:30 +03:00
|
|
|
}
|
2021-09-18 01:22:33 +03:00
|
|
|
}
|
|
|
|
QString edit() const { return edit_; }
|
2021-12-23 04:33:46 +03:00
|
|
|
void setEdit(const QString &newEdit);
|
2021-09-18 01:22:33 +03:00
|
|
|
void resetEdit();
|
2022-09-30 04:27:05 +03:00
|
|
|
QString thread() const { return thread_; }
|
|
|
|
void setThread(const QString &newThread);
|
|
|
|
void resetThread();
|
2021-09-18 01:22:33 +03:00
|
|
|
void setDecryptDescription(bool decrypt) { decryptDescription = decrypt; }
|
2023-01-02 06:21:26 +03:00
|
|
|
void clearTimeline()
|
|
|
|
{
|
|
|
|
events.clearTimeline();
|
|
|
|
setPaginationInProgress(false);
|
|
|
|
}
|
2022-02-05 10:40:56 +03:00
|
|
|
void resetState();
|
2021-09-18 01:22:33 +03:00
|
|
|
void receivedSessionKey(const std::string &session_key)
|
|
|
|
{
|
|
|
|
events.receivedSessionKey(session_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString roomName() const;
|
|
|
|
QString plainRoomName() const;
|
|
|
|
QString roomTopic() const;
|
2021-12-11 08:10:41 +03:00
|
|
|
QStringList pinnedMessages() const;
|
2022-02-04 20:47:17 +03:00
|
|
|
QStringList widgetLinks() const;
|
2021-09-18 01:22:33 +03:00
|
|
|
InputBar *input() { return &input_; }
|
|
|
|
Permissions *permissions() { return &permissions_; }
|
|
|
|
QString roomAvatarUrl() const;
|
|
|
|
QString roomId() const { return room_id_; }
|
2022-09-20 22:26:28 +03:00
|
|
|
RoomSummary *parentSpace();
|
2021-09-18 01:22:33 +03:00
|
|
|
|
2021-12-23 04:55:25 +03:00
|
|
|
bool hasMentions() const { return highlight_count > 0; }
|
2022-10-26 02:10:35 +03:00
|
|
|
int notificationCount() const { return static_cast<int>(notification_count); }
|
2021-09-18 01:22:33 +03:00
|
|
|
|
|
|
|
QString scrollTarget() const;
|
2021-04-29 20:09:16 +03:00
|
|
|
|
2022-12-10 18:17:15 +03:00
|
|
|
void triggerSpecialEffects();
|
|
|
|
void markSpecialEffectsDone();
|
|
|
|
|
2019-09-01 00:44:17 +03:00
|
|
|
private slots:
|
2021-09-18 01:22:33 +03:00
|
|
|
void addPendingMessage(mtx::events::collections::TimelineEvents event);
|
|
|
|
void scrollTimerEvent();
|
2019-09-01 00:44:17 +03:00
|
|
|
|
|
|
|
signals:
|
2021-11-08 21:32:14 +03:00
|
|
|
void dataAtIdChanged(QString id);
|
2021-09-18 01:22:33 +03:00
|
|
|
void currentIndexChanged(int index);
|
|
|
|
void redactionFailed(QString id);
|
|
|
|
void mediaCached(QString mxcUrl, QString cacheUrl);
|
|
|
|
void newEncryptedImage(mtx::crypto::EncryptedFile encryptionInfo);
|
|
|
|
void typingUsersChanged(std::vector<QString> users);
|
|
|
|
void replyChanged(QString reply);
|
|
|
|
void editChanged(QString reply);
|
2022-09-30 04:27:05 +03:00
|
|
|
void threadChanged(QString id);
|
2021-09-18 01:22:33 +03:00
|
|
|
void openReadReceiptsDialog(ReadReceiptsProxy *rr);
|
|
|
|
void showRawMessageDialog(QString rawMessage);
|
|
|
|
void paginationInProgressChanged(const bool);
|
|
|
|
void newCallEvent(const mtx::events::collections::TimelineEvents &event);
|
|
|
|
void scrollToIndex(int index);
|
2022-12-10 18:17:15 +03:00
|
|
|
void confetti();
|
2023-01-14 04:23:07 +03:00
|
|
|
void confettiDone();
|
2023-03-07 21:11:00 +03:00
|
|
|
void rainfall();
|
|
|
|
void rainfallDone();
|
2021-09-18 01:22:33 +03:00
|
|
|
|
|
|
|
void lastMessageChanged();
|
|
|
|
void notificationsChanged();
|
|
|
|
|
2022-06-18 02:35:30 +03:00
|
|
|
void newState(const mtx::responses::StateEvents &events);
|
2022-02-05 10:40:56 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
void newMessageToSend(mtx::events::collections::TimelineEvents event);
|
|
|
|
void addPendingMessageToStore(mtx::events::collections::TimelineEvents event);
|
|
|
|
void updateFlowEventId(std::string event_id);
|
|
|
|
|
2022-09-20 22:26:28 +03:00
|
|
|
void parentSpaceChanged();
|
2021-09-18 01:22:33 +03:00
|
|
|
void encryptionChanged();
|
2022-09-12 02:05:20 +03:00
|
|
|
void fullyReadEventIdChanged();
|
2021-09-18 01:22:33 +03:00
|
|
|
void trustlevelChanged();
|
|
|
|
void roomNameChanged();
|
|
|
|
void roomTopicChanged();
|
2021-12-11 08:10:41 +03:00
|
|
|
void pinnedMessagesChanged();
|
2022-02-04 20:47:17 +03:00
|
|
|
void widgetLinksChanged();
|
2021-09-18 01:22:33 +03:00
|
|
|
void roomAvatarUrlChanged();
|
|
|
|
void roomMemberCountChanged();
|
|
|
|
void isDirectChanged();
|
|
|
|
void directChatOtherUserIdChanged();
|
|
|
|
void permissionsChanged();
|
|
|
|
void forwardToRoom(mtx::events::collections::TimelineEvents *e, QString roomId);
|
|
|
|
|
|
|
|
void scrollTargetChanged();
|
2021-04-29 20:09:16 +03:00
|
|
|
|
2022-11-04 01:26:59 +03:00
|
|
|
void fetchedMore();
|
|
|
|
|
2019-08-31 00:20:53 +03:00
|
|
|
private:
|
2021-09-18 01:22:33 +03:00
|
|
|
template<typename T>
|
|
|
|
void sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::EventType eventType);
|
|
|
|
void readEvent(const std::string &id);
|
2019-09-08 17:50:32 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
void setPaginationInProgress(const bool paginationInProgress);
|
2020-04-28 12:07:24 +03:00
|
|
|
|
2021-12-28 20:44:26 +03:00
|
|
|
QString room_id_;
|
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QSet<QString> read;
|
2019-08-31 00:20:53 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
mutable EventStore events;
|
2020-07-10 00:15:22 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QString currentId, currentReadId;
|
2022-09-30 04:27:05 +03:00
|
|
|
QString reply_, edit_, thread_;
|
2021-09-18 01:22:33 +03:00
|
|
|
QString textBeforeEdit, replyBeforeEdit;
|
|
|
|
std::vector<QString> typingUsers_;
|
2019-10-03 19:07:01 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
TimelineViewManager *manager_;
|
2019-11-10 02:30:02 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
InputBar input_{this};
|
|
|
|
Permissions permissions_;
|
2020-11-01 01:24:07 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QTimer showEventTimer{this};
|
|
|
|
QString eventIdToShow;
|
|
|
|
int showEventTimerCounter = 0;
|
2021-04-29 20:09:16 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
DescInfo lastMessage_{};
|
2021-05-21 22:19:03 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
friend struct SendMessageVisitor;
|
2021-05-21 22:19:03 +03:00
|
|
|
|
2022-06-17 04:11:31 +03:00
|
|
|
uint64_t notification_count = 0, highlight_count = 0;
|
2021-06-18 15:05:52 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
unsigned int relatedEventCacheBuster = 0;
|
2021-07-20 15:09:19 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
bool decryptDescription = true;
|
|
|
|
bool m_paginationInProgress = false;
|
|
|
|
bool isSpace_ = false;
|
|
|
|
bool isEncrypted_ = false;
|
2022-09-12 02:05:20 +03:00
|
|
|
std::string last_event_id;
|
|
|
|
std::string fullyReadEventId_;
|
2022-09-20 22:26:28 +03:00
|
|
|
|
2022-12-10 18:17:15 +03:00
|
|
|
bool needsSpecialEffects_ = false;
|
2023-03-07 21:11:00 +03:00
|
|
|
QFlags<SpecialEffect> specialEffects_;
|
2022-12-10 18:17:15 +03:00
|
|
|
|
2022-09-24 11:36:26 +03:00
|
|
|
std::unique_ptr<RoomSummary, DeleteLaterDeleter> parentSummary = nullptr;
|
|
|
|
bool parentChecked = false;
|
2023-02-18 04:59:33 +03:00
|
|
|
|
|
|
|
friend void EventStore::refetchOnlineKeyBackupKeys(TimelineModel *room);
|
2019-08-31 00:20:53 +03:00
|
|
|
};
|
2019-09-11 01:00:04 +03:00
|
|
|
|
2023-03-07 21:11:00 +03:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(TimelineModel::SpecialEffects)
|
|
|
|
|
2019-09-11 01:00:04 +03:00
|
|
|
template<class T>
|
|
|
|
void
|
2020-07-11 02:19:48 +03:00
|
|
|
TimelineModel::sendMessageEvent(const T &content, mtx::events::EventType eventType)
|
2019-09-11 01:00:04 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if constexpr (std::is_same_v<T, mtx::events::msg::StickerImage>) {
|
|
|
|
mtx::events::Sticker msgCopy = {};
|
|
|
|
msgCopy.content = content;
|
|
|
|
msgCopy.type = eventType;
|
|
|
|
emit newMessageToSend(msgCopy);
|
|
|
|
} else {
|
|
|
|
mtx::events::RoomEvent<T> msgCopy = {};
|
|
|
|
msgCopy.content = content;
|
|
|
|
msgCopy.type = eventType;
|
|
|
|
emit newMessageToSend(msgCopy);
|
|
|
|
}
|
2022-09-12 02:05:20 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
resetReply();
|
|
|
|
resetEdit();
|
2019-09-11 01:00:04 +03:00
|
|
|
}
|