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
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QColor>
|
2019-09-01 23:58:26 +03:00
|
|
|
#include <QDate>
|
2019-08-31 23:43:31 +03:00
|
|
|
#include <QHash>
|
2019-09-18 23:58:25 +03:00
|
|
|
#include <QSet>
|
2021-04-29 20:09:16 +03:00
|
|
|
#include <QTimer>
|
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"
|
2021-02-11 21:20:45 +03:00
|
|
|
#include "ui/RoomSettings.h"
|
2021-02-13 21:29:42 +03:00
|
|
|
#include "ui/UserProfile.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;
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
// Unsupported event
|
|
|
|
Unsupported,
|
|
|
|
/// m.room_key_request
|
|
|
|
KeyRequest,
|
2020-05-06 13:52:13 +03:00
|
|
|
/// m.reaction,
|
|
|
|
Reaction,
|
2019-09-03 00:28:05 +03:00
|
|
|
/// m.room.aliases
|
|
|
|
Aliases,
|
|
|
|
/// m.room.avatar
|
|
|
|
Avatar,
|
2020-07-11 02:19:48 +03:00
|
|
|
/// m.call.invite
|
|
|
|
CallInvite,
|
|
|
|
/// m.call.answer
|
|
|
|
CallAnswer,
|
|
|
|
/// m.call.hangup
|
|
|
|
CallHangUp,
|
2020-08-18 00:30:36 +03:00
|
|
|
/// m.call.candidates
|
|
|
|
CallCandidates,
|
2019-09-03 00:28:05 +03:00
|
|
|
/// m.room.canonical_alias
|
|
|
|
CanonicalAlias,
|
|
|
|
/// m.room.create
|
2020-02-29 03:27:51 +03:00
|
|
|
RoomCreate,
|
2019-09-03 00:28:05 +03:00
|
|
|
/// m.room.encrypted.
|
|
|
|
Encrypted,
|
|
|
|
/// m.room.encryption.
|
|
|
|
Encryption,
|
|
|
|
/// m.room.guest_access
|
2020-02-29 03:27:51 +03:00
|
|
|
RoomGuestAccess,
|
2019-09-03 00:28:05 +03:00
|
|
|
/// m.room.history_visibility
|
2020-02-29 03:27:51 +03:00
|
|
|
RoomHistoryVisibility,
|
2019-09-03 00:28:05 +03:00
|
|
|
/// m.room.join_rules
|
2020-02-29 03:27:51 +03:00
|
|
|
RoomJoinRules,
|
2019-09-03 00:28:05 +03:00
|
|
|
/// 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,
|
|
|
|
/// m.room.message
|
|
|
|
AudioMessage,
|
|
|
|
EmoteMessage,
|
|
|
|
FileMessage,
|
|
|
|
ImageMessage,
|
|
|
|
LocationMessage,
|
|
|
|
NoticeMessage,
|
|
|
|
TextMessage,
|
|
|
|
VideoMessage,
|
2019-09-09 22:42:33 +03:00
|
|
|
Redacted,
|
2019-09-03 00:28:05 +03:00
|
|
|
UnknownMessage,
|
2020-07-17 23:16:30 +03:00
|
|
|
KeyVerificationRequest,
|
|
|
|
KeyVerificationStart,
|
|
|
|
KeyVerificationMac,
|
|
|
|
KeyVerificationAccept,
|
|
|
|
KeyVerificationCancel,
|
|
|
|
KeyVerificationKey,
|
|
|
|
KeyVerificationDone,
|
2021-08-06 02:45:47 +03:00
|
|
|
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,
|
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);
|
2019-09-18 23:58:25 +03:00
|
|
|
|
|
|
|
enum EventState
|
|
|
|
{
|
|
|
|
//! 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,
|
|
|
|
//! When the message is loaded from cache or backfill.
|
|
|
|
Empty,
|
|
|
|
};
|
|
|
|
Q_ENUM_NS(EventState)
|
2019-09-03 00:28:05 +03:00
|
|
|
}
|
|
|
|
|
2019-09-19 23:44:25 +03:00
|
|
|
class StateKeeper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StateKeeper(std::function<void()> &&fn)
|
|
|
|
: fn_(std::move(fn))
|
|
|
|
{}
|
|
|
|
|
|
|
|
~StateKeeper() { fn_(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::function<void()> fn_;
|
|
|
|
};
|
|
|
|
|
2019-09-08 17:50:32 +03:00
|
|
|
struct DecryptionResult
|
|
|
|
{
|
|
|
|
//! The decrypted content as a normal plaintext event.
|
|
|
|
mtx::events::collections::TimelineEvents event;
|
|
|
|
//! Whether or not the decryption was successful.
|
|
|
|
bool isDecrypted = false;
|
|
|
|
};
|
|
|
|
|
2019-10-03 19:07:01 +03:00
|
|
|
class TimelineViewManager;
|
|
|
|
|
2019-08-31 00:20:53 +03:00
|
|
|
class TimelineModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2019-09-18 21:34:30 +03:00
|
|
|
Q_PROPERTY(
|
|
|
|
int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
|
2020-01-17 03:25:14 +03:00
|
|
|
Q_PROPERTY(std::vector<QString> typingUsers READ typingUsers WRITE updateTypingUsers NOTIFY
|
|
|
|
typingUsersChanged)
|
2021-04-29 20:09:16 +03:00
|
|
|
Q_PROPERTY(QString scrollTarget READ scrollTarget NOTIFY scrollTargetChanged)
|
2020-04-13 17:22:30 +03:00
|
|
|
Q_PROPERTY(QString reply READ reply WRITE setReply NOTIFY replyChanged RESET resetReply)
|
2021-02-01 00:41:43 +03:00
|
|
|
Q_PROPERTY(QString edit READ edit WRITE setEdit NOTIFY editChanged RESET resetEdit)
|
2020-05-01 08:40:27 +03:00
|
|
|
Q_PROPERTY(
|
|
|
|
bool paginationInProgress READ paginationInProgress NOTIFY paginationInProgressChanged)
|
2021-06-11 03:11:49 +03:00
|
|
|
Q_PROPERTY(QString roomId READ roomId CONSTANT)
|
2020-09-03 18:01:58 +03:00
|
|
|
Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged)
|
2021-07-21 02:17:20 +03:00
|
|
|
Q_PROPERTY(QString plainRoomName READ plainRoomName NOTIFY plainRoomNameChanged)
|
2020-09-03 18:01:58 +03:00
|
|
|
Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl NOTIFY roomAvatarUrlChanged)
|
|
|
|
Q_PROPERTY(QString roomTopic READ roomTopic NOTIFY roomTopicChanged)
|
2021-06-18 17:22:06 +03:00
|
|
|
Q_PROPERTY(int roomMemberCount READ roomMemberCount NOTIFY roomMemberCountChanged)
|
2021-07-10 17:12:38 +03:00
|
|
|
Q_PROPERTY(bool isEncrypted READ isEncrypted NOTIFY encryptionChanged)
|
2021-06-18 15:05:52 +03:00
|
|
|
Q_PROPERTY(bool isSpace READ isSpace CONSTANT)
|
2021-08-14 00:13:09 +03:00
|
|
|
Q_PROPERTY(int trustlevel READ trustlevel NOTIFY trustlevelChanged)
|
2021-08-31 03:08:47 +03:00
|
|
|
Q_PROPERTY(bool isDirect READ isDirect NOTIFY isDirectChanged)
|
2021-09-05 04:51:06 +03:00
|
|
|
Q_PROPERTY(QString directChatOtherUserId READ directChatOtherUserId NOTIFY
|
|
|
|
directChatOtherUserIdChanged)
|
2020-11-15 06:52:49 +03:00
|
|
|
Q_PROPERTY(InputBar *input READ input CONSTANT)
|
2021-05-02 19:01:18 +03:00
|
|
|
Q_PROPERTY(Permissions *permissions READ permissions NOTIFY permissionsChanged)
|
2019-08-31 00:20:53 +03:00
|
|
|
|
|
|
|
public:
|
2020-02-04 23:16:04 +03:00
|
|
|
explicit TimelineModel(TimelineViewManager *manager,
|
|
|
|
QString room_id,
|
|
|
|
QObject *parent = nullptr);
|
2019-08-31 00:20:53 +03:00
|
|
|
|
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
Type,
|
2020-01-23 22:59:17 +03:00
|
|
|
TypeString,
|
2020-05-19 22:04:38 +03:00
|
|
|
IsOnlyEmoji,
|
2019-08-31 00:20:53 +03:00
|
|
|
Body,
|
|
|
|
FormattedBody,
|
2021-01-20 01:58:25 +03:00
|
|
|
PreviousMessageUserId,
|
2021-05-02 19:01:18 +03:00
|
|
|
IsSender,
|
2019-08-31 00:20:53 +03:00
|
|
|
UserId,
|
|
|
|
UserName,
|
2021-01-20 01:58:25 +03:00
|
|
|
PreviousMessageDay,
|
|
|
|
Day,
|
2019-08-31 00:20:53 +03:00
|
|
|
Timestamp,
|
2019-09-08 13:44:46 +03:00
|
|
|
Url,
|
2019-10-09 01:36:03 +03:00
|
|
|
ThumbnailUrl,
|
2020-03-01 21:55:43 +03:00
|
|
|
Blurhash,
|
2019-09-29 11:45:35 +03:00
|
|
|
Filename,
|
2019-10-04 02:10:46 +03:00
|
|
|
Filesize,
|
2019-09-29 11:45:35 +03:00
|
|
|
MimeType,
|
2021-07-12 01:24:33 +03:00
|
|
|
OriginalHeight,
|
|
|
|
OriginalWidth,
|
2019-09-08 13:44:46 +03:00
|
|
|
ProportionalHeight,
|
2021-07-12 01:24:33 +03:00
|
|
|
EventId,
|
2019-09-18 23:58:25 +03:00
|
|
|
State,
|
2021-02-01 00:41:43 +03:00
|
|
|
IsEdited,
|
|
|
|
IsEditable,
|
2019-09-20 00:02:56 +03:00
|
|
|
IsEncrypted,
|
2021-05-07 13:19:46 +03:00
|
|
|
Trustlevel,
|
2021-08-07 23:51:09 +03:00
|
|
|
EncryptionError,
|
2019-11-05 19:16:04 +03:00
|
|
|
ReplyTo,
|
2020-05-04 14:14:54 +03:00
|
|
|
Reactions,
|
2020-02-29 03:27:51 +03:00
|
|
|
RoomId,
|
2019-12-10 16:46:52 +03:00
|
|
|
RoomName,
|
|
|
|
RoomTopic,
|
2020-07-24 20:30:12 +03:00
|
|
|
CallType,
|
2020-01-04 01:21:33 +03:00
|
|
|
Dump,
|
2021-07-20 15:09:19 +03:00
|
|
|
RelatedEventCacheBuster,
|
2019-08-31 00:20:53 +03:00
|
|
|
};
|
2021-07-12 23:28:01 +03:00
|
|
|
Q_ENUM(Roles);
|
2019-08-31 00:20:53 +03:00
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
2019-09-03 00:28:05 +03:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
2020-07-10 00:15:22 +03:00
|
|
|
QVariant data(const mtx::events::collections::TimelineEvents &event, int role) const;
|
2021-07-16 12:47:49 +03:00
|
|
|
Q_INVOKABLE QVariant dataById(QString id, int role, QString relatedTo);
|
2019-08-31 00:20:53 +03:00
|
|
|
|
2020-01-06 18:42:56 +03:00
|
|
|
bool canFetchMore(const QModelIndex &) const override;
|
|
|
|
void fetchMore(const QModelIndex &) override;
|
|
|
|
|
2019-09-01 23:34:36 +03:00
|
|
|
Q_INVOKABLE QString displayName(QString id) const;
|
2019-09-07 23:22:07 +03:00
|
|
|
Q_INVOKABLE QString avatarUrl(QString id) const;
|
2019-09-01 23:58:26 +03:00
|
|
|
Q_INVOKABLE QString formatDateSeparator(QDate date) const;
|
2020-01-17 03:25:14 +03:00
|
|
|
Q_INVOKABLE QString formatTypingUsers(const std::vector<QString> &users, QColor bg);
|
2021-08-18 00:31:25 +03:00
|
|
|
Q_INVOKABLE bool showAcceptKnockButton(QString id);
|
|
|
|
Q_INVOKABLE void acceptKnock(QString id);
|
2020-01-23 22:34:04 +03:00
|
|
|
Q_INVOKABLE QString formatMemberEvent(QString id);
|
2020-02-29 03:27:51 +03:00
|
|
|
Q_INVOKABLE QString formatJoinRuleEvent(QString id);
|
|
|
|
Q_INVOKABLE QString formatHistoryVisibilityEvent(QString id);
|
|
|
|
Q_INVOKABLE QString formatGuestAccessEvent(QString id);
|
|
|
|
Q_INVOKABLE QString formatPowerLevelEvent(QString id);
|
2019-10-03 19:07:01 +03:00
|
|
|
|
2021-07-31 05:13:58 +03:00
|
|
|
Q_INVOKABLE void viewRawMessage(QString id);
|
2021-04-11 17:31:49 +03:00
|
|
|
Q_INVOKABLE void forwardMessage(QString eventId, QString roomId);
|
2021-07-31 05:13:58 +03:00
|
|
|
Q_INVOKABLE void viewDecryptedRawMessage(QString id);
|
2021-04-30 16:33:17 +03:00
|
|
|
Q_INVOKABLE void openUserProfile(QString userid);
|
2021-02-01 00:41:43 +03:00
|
|
|
Q_INVOKABLE void editAction(QString id);
|
2019-09-11 01:54:40 +03:00
|
|
|
Q_INVOKABLE void replyAction(QString id);
|
2021-07-24 01:11:33 +03:00
|
|
|
Q_INVOKABLE void showReadReceipts(QString id);
|
2019-09-29 13:29:17 +03:00
|
|
|
Q_INVOKABLE void redactEvent(QString id);
|
2019-09-18 21:34:30 +03:00
|
|
|
Q_INVOKABLE int idToIndex(QString id) const;
|
|
|
|
Q_INVOKABLE QString indexToId(int index) const;
|
2021-01-24 03:29:30 +03:00
|
|
|
Q_INVOKABLE void openMedia(QString eventId);
|
2019-12-03 04:26:41 +03:00
|
|
|
Q_INVOKABLE void cacheMedia(QString eventId);
|
2020-03-20 16:05:12 +03:00
|
|
|
Q_INVOKABLE bool saveMedia(QString eventId) const;
|
2021-04-29 20:09:16 +03:00
|
|
|
Q_INVOKABLE void showEvent(QString eventId);
|
2021-04-29 22:46:49 +03:00
|
|
|
Q_INVOKABLE void copyLinkToEvent(QString eventId) const;
|
2021-01-24 03:29:30 +03:00
|
|
|
void cacheMedia(QString eventId, std::function<void(const QString filename)> callback);
|
2021-07-12 01:24:33 +03:00
|
|
|
Q_INVOKABLE void sendReset()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
endResetModel();
|
|
|
|
}
|
2019-09-01 00:44:17 +03:00
|
|
|
|
2021-08-07 23:51:09 +03:00
|
|
|
Q_INVOKABLE void requestKeyForEvent(QString id);
|
|
|
|
|
2020-07-20 01:42:48 +03:00
|
|
|
std::vector<::Reaction> reactions(const std::string &event_id)
|
|
|
|
{
|
|
|
|
auto list = events.reactions(event_id);
|
|
|
|
std::vector<::Reaction> vec;
|
|
|
|
for (const auto &r : list)
|
|
|
|
vec.push_back(r.value<Reaction>());
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:21:20 +03:00
|
|
|
void updateLastMessage();
|
2021-05-21 22:19:03 +03:00
|
|
|
void sync(const mtx::responses::JoinedRoom &room);
|
2019-08-31 23:43:31 +03:00
|
|
|
void addEvents(const mtx::responses::Timeline &events);
|
2020-09-03 18:01:58 +03:00
|
|
|
void syncState(const mtx::responses::State &state);
|
2019-09-11 01:00:04 +03:00
|
|
|
template<class T>
|
2020-07-11 02:19:48 +03:00
|
|
|
void sendMessageEvent(const T &content, mtx::events::EventType eventType);
|
2020-04-13 17:22:30 +03:00
|
|
|
RelatedInfo relatedInfo(QString id);
|
2019-08-31 23:43:31 +03:00
|
|
|
|
2021-05-21 22:19:03 +03:00
|
|
|
DescInfo lastMessage() const { return lastMessage_; }
|
2021-06-18 15:05:52 +03:00
|
|
|
bool isSpace() const { return isSpace_; }
|
2021-07-10 17:12:38 +03:00
|
|
|
bool isEncrypted() const { return isEncrypted_; }
|
2021-08-14 00:13:09 +03:00
|
|
|
crypto::Trust trustlevel() const;
|
2021-06-18 17:22:06 +03:00
|
|
|
int roomMemberCount() const;
|
2021-08-31 03:08:47 +03:00
|
|
|
bool isDirect() const { return roomMemberCount() <= 2; } // TODO: handle invites
|
2021-09-05 03:53:33 +03:00
|
|
|
QString directChatOtherUserId() const;
|
2021-05-21 22:19:03 +03:00
|
|
|
|
2021-08-28 01:38: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;
|
|
|
|
}
|
|
|
|
|
2019-09-01 00:44:17 +03:00
|
|
|
public slots:
|
2019-10-03 23:39:56 +03:00
|
|
|
void setCurrentIndex(int index);
|
2019-09-18 21:34:30 +03:00
|
|
|
int currentIndex() const { return idToIndex(currentId); }
|
2021-04-29 20:09:16 +03:00
|
|
|
void eventShown();
|
2019-09-19 00:37:30 +03:00
|
|
|
void markEventsAsRead(const std::vector<QString> &event_ids);
|
2020-07-10 00:15:22 +03:00
|
|
|
QVariantMap getDump(QString eventId, QString relatedTo) const;
|
2020-01-17 03:25:14 +03:00
|
|
|
void updateTypingUsers(const std::vector<QString> &users)
|
|
|
|
{
|
|
|
|
if (this->typingUsers_ != users) {
|
|
|
|
this->typingUsers_ = users;
|
|
|
|
emit typingUsersChanged(typingUsers_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::vector<QString> typingUsers() const { return typingUsers_; }
|
2020-04-28 12:07:24 +03:00
|
|
|
bool paginationInProgress() const { return m_paginationInProgress; }
|
2020-04-13 17:22:30 +03:00
|
|
|
QString reply() const { return reply_; }
|
|
|
|
void setReply(QString newReply)
|
|
|
|
{
|
2021-02-10 20:07:55 +03:00
|
|
|
if (edit_.startsWith('m'))
|
|
|
|
return;
|
|
|
|
|
2020-04-13 17:22:30 +03:00
|
|
|
if (reply_ != newReply) {
|
|
|
|
reply_ = newReply;
|
|
|
|
emit replyChanged(reply_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void resetReply()
|
|
|
|
{
|
|
|
|
if (!reply_.isEmpty()) {
|
|
|
|
reply_ = "";
|
|
|
|
emit replyChanged(reply_);
|
|
|
|
}
|
|
|
|
}
|
2021-02-01 00:41:43 +03:00
|
|
|
QString edit() const { return edit_; }
|
|
|
|
void setEdit(QString newEdit);
|
2021-02-01 04:22:53 +03:00
|
|
|
void resetEdit();
|
2020-04-24 02:21:20 +03:00
|
|
|
void setDecryptDescription(bool decrypt) { decryptDescription = decrypt; }
|
2020-08-10 00:36:47 +03:00
|
|
|
void clearTimeline() { events.clearTimeline(); }
|
2020-10-20 20:46:37 +03:00
|
|
|
void receivedSessionKey(const std::string &session_key)
|
|
|
|
{
|
|
|
|
events.receivedSessionKey(session_key);
|
|
|
|
}
|
2020-04-13 17:22:30 +03:00
|
|
|
|
2020-09-03 18:01:58 +03:00
|
|
|
QString roomName() const;
|
2021-05-22 11:16:42 +03:00
|
|
|
QString plainRoomName() const;
|
2020-09-03 18:01:58 +03:00
|
|
|
QString roomTopic() const;
|
2020-11-01 01:24:07 +03:00
|
|
|
InputBar *input() { return &input_; }
|
2021-05-02 19:01:18 +03:00
|
|
|
Permissions *permissions() { return &permissions_; }
|
2020-09-03 18:01:58 +03:00
|
|
|
QString roomAvatarUrl() const;
|
2020-09-03 20:34:17 +03:00
|
|
|
QString roomId() const { return room_id_; }
|
2020-09-03 18:01:58 +03:00
|
|
|
|
2021-05-21 22:19:03 +03:00
|
|
|
bool hasMentions() { return highlight_count > 0; }
|
|
|
|
int notificationCount() { return notification_count; }
|
|
|
|
|
2021-04-29 20:09:16 +03:00
|
|
|
QString scrollTarget() const;
|
|
|
|
|
2019-09-01 00:44:17 +03:00
|
|
|
private slots:
|
2019-11-10 02:30:02 +03:00
|
|
|
void addPendingMessage(mtx::events::collections::TimelineEvents event);
|
2021-04-29 20:09:16 +03:00
|
|
|
void scrollTimerEvent();
|
2019-09-01 00:44:17 +03:00
|
|
|
|
|
|
|
signals:
|
2019-09-18 21:34:30 +03:00
|
|
|
void currentIndexChanged(int index);
|
2019-09-29 13:29:17 +03:00
|
|
|
void redactionFailed(QString id);
|
|
|
|
void eventRedacted(QString id);
|
2019-12-03 04:26:41 +03:00
|
|
|
void mediaCached(QString mxcUrl, QString cacheUrl);
|
2019-12-04 01:34:16 +03:00
|
|
|
void newEncryptedImage(mtx::crypto::EncryptedFile encryptionInfo);
|
2020-01-17 03:25:14 +03:00
|
|
|
void typingUsersChanged(std::vector<QString> users);
|
2020-04-13 17:22:30 +03:00
|
|
|
void replyChanged(QString reply);
|
2021-02-01 00:41:43 +03:00
|
|
|
void editChanged(QString reply);
|
2021-07-29 04:31:37 +03:00
|
|
|
void openReadReceiptsDialog(ReadReceiptsProxy *rr);
|
2021-07-31 05:13:58 +03:00
|
|
|
void showRawMessageDialog(QString rawMessage);
|
2020-04-28 12:07:24 +03:00
|
|
|
void paginationInProgressChanged(const bool);
|
2020-07-11 02:19:48 +03:00
|
|
|
void newCallEvent(const mtx::events::collections::TimelineEvents &event);
|
2021-04-29 20:09:16 +03:00
|
|
|
void scrollToIndex(int index);
|
2019-09-01 00:44:17 +03:00
|
|
|
|
2021-05-21 22:19:03 +03:00
|
|
|
void lastMessageChanged();
|
|
|
|
void notificationsChanged();
|
|
|
|
|
2020-08-09 06:05:15 +03:00
|
|
|
void newMessageToSend(mtx::events::collections::TimelineEvents event);
|
|
|
|
void addPendingMessageToStore(mtx::events::collections::TimelineEvents event);
|
|
|
|
void updateFlowEventId(std::string event_id);
|
|
|
|
|
2021-07-10 17:12:38 +03:00
|
|
|
void encryptionChanged();
|
2021-08-14 00:13:09 +03:00
|
|
|
void trustlevelChanged();
|
2020-09-03 18:01:58 +03:00
|
|
|
void roomNameChanged();
|
2021-07-21 02:17:20 +03:00
|
|
|
void plainRoomNameChanged();
|
2020-09-03 18:01:58 +03:00
|
|
|
void roomTopicChanged();
|
|
|
|
void roomAvatarUrlChanged();
|
2021-06-18 17:22:06 +03:00
|
|
|
void roomMemberCountChanged();
|
2021-08-31 03:08:47 +03:00
|
|
|
void isDirectChanged();
|
2021-09-05 03:53:33 +03:00
|
|
|
void directChatOtherUserIdChanged();
|
2021-05-02 19:01:18 +03:00
|
|
|
void permissionsChanged();
|
2021-04-17 20:28:04 +03:00
|
|
|
void forwardToRoom(mtx::events::collections::TimelineEvents *e, QString roomId);
|
2020-09-03 18:01:58 +03:00
|
|
|
|
2021-04-29 20:09:16 +03:00
|
|
|
void scrollTargetChanged();
|
|
|
|
|
2019-08-31 00:20:53 +03:00
|
|
|
private:
|
2020-08-09 06:05:15 +03:00
|
|
|
template<typename T>
|
2020-08-30 19:57:14 +03:00
|
|
|
void sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::EventType eventType);
|
2019-10-31 16:09:51 +03:00
|
|
|
void readEvent(const std::string &id);
|
2019-09-08 17:50:32 +03:00
|
|
|
|
2020-04-28 12:07:24 +03:00
|
|
|
void setPaginationInProgress(const bool paginationInProgress);
|
|
|
|
|
2020-04-17 02:02:32 +03:00
|
|
|
QSet<QString> read;
|
2019-08-31 00:20:53 +03:00
|
|
|
|
2020-07-10 00:15:22 +03:00
|
|
|
mutable EventStore events;
|
|
|
|
|
2019-09-01 00:44:17 +03:00
|
|
|
QString room_id_;
|
|
|
|
|
2021-02-10 03:03:20 +03:00
|
|
|
QString currentId, currentReadId;
|
2021-02-01 00:41:43 +03:00
|
|
|
QString reply_, edit_;
|
2021-02-25 01:51:05 +03:00
|
|
|
QString textBeforeEdit, replyBeforeEdit;
|
2020-01-17 03:25:14 +03:00
|
|
|
std::vector<QString> typingUsers_;
|
2019-10-03 19:07:01 +03:00
|
|
|
|
|
|
|
TimelineViewManager *manager_;
|
2019-11-10 02:30:02 +03:00
|
|
|
|
2020-11-01 01:24:07 +03:00
|
|
|
InputBar input_{this};
|
2021-06-12 20:17:31 +03:00
|
|
|
Permissions permissions_;
|
2020-11-01 01:24:07 +03:00
|
|
|
|
2021-04-29 20:09:16 +03:00
|
|
|
QTimer showEventTimer{this};
|
|
|
|
QString eventIdToShow;
|
|
|
|
int showEventTimerCounter = 0;
|
|
|
|
|
2021-05-22 01:57:14 +03:00
|
|
|
DescInfo lastMessage_{};
|
2021-05-21 22:19:03 +03:00
|
|
|
|
2019-11-10 02:30:02 +03:00
|
|
|
friend struct SendMessageVisitor;
|
2021-05-21 22:19:03 +03:00
|
|
|
|
|
|
|
int notification_count = 0, highlight_count = 0;
|
2021-06-18 15:05:52 +03:00
|
|
|
|
2021-07-20 15:09:19 +03:00
|
|
|
unsigned int relatedEventCacheBuster = 0;
|
|
|
|
|
2021-06-18 15:05:52 +03:00
|
|
|
bool decryptDescription = true;
|
|
|
|
bool m_paginationInProgress = false;
|
|
|
|
bool isSpace_ = false;
|
2021-07-10 17:12:38 +03:00
|
|
|
bool isEncrypted_ = false;
|
2019-08-31 00:20:53 +03:00
|
|
|
};
|
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-07-15 21:37:52 +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);
|
|
|
|
}
|
2021-02-25 02:50:17 +03:00
|
|
|
resetReply();
|
|
|
|
resetEdit();
|
2019-09-11 01:00:04 +03:00
|
|
|
}
|