EventHandler Cleanup
Remove functions from eventhandler and replace with now uplifted functions in libquotient
This commit is contained in:
@@ -32,8 +32,6 @@ private:
|
|||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
|
|
||||||
void eventId();
|
|
||||||
void nullEventId();
|
|
||||||
void authorDisplayName();
|
void authorDisplayName();
|
||||||
void nullAuthorDisplayName();
|
void nullAuthorDisplayName();
|
||||||
void singleLineSidplayName();
|
void singleLineSidplayName();
|
||||||
@@ -56,14 +54,8 @@ private Q_SLOTS:
|
|||||||
void nullSubtitle();
|
void nullSubtitle();
|
||||||
void mediaInfo();
|
void mediaInfo();
|
||||||
void nullMediaInfo();
|
void nullMediaInfo();
|
||||||
void hasReply();
|
|
||||||
void nullHasReply();
|
|
||||||
void replyId();
|
|
||||||
void nullReplyId();
|
|
||||||
void replyAuthor();
|
void replyAuthor();
|
||||||
void nullReplyAuthor();
|
void nullReplyAuthor();
|
||||||
void thread();
|
|
||||||
void nullThread();
|
|
||||||
void location();
|
void location();
|
||||||
void nullLocation();
|
void nullLocation();
|
||||||
};
|
};
|
||||||
@@ -74,17 +66,6 @@ void EventHandlerTest::initTestCase()
|
|||||||
room = new TestUtils::TestRoom(connection, QStringLiteral("#myroom:kde.org"), QLatin1String("test-eventhandler-sync.json"));
|
room = new TestUtils::TestRoom(connection, QStringLiteral("#myroom:kde.org"), QLatin1String("test-eventhandler-sync.json"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::eventId()
|
|
||||||
{
|
|
||||||
QCOMPARE(EventHandler::id(room->messageEvents().at(0).get()), QStringLiteral("$153456789:example.org"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::nullEventId()
|
|
||||||
{
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "id called with event set to nullptr.");
|
|
||||||
QCOMPARE(EventHandler::id(nullptr), QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::authorDisplayName()
|
void EventHandlerTest::authorDisplayName()
|
||||||
{
|
{
|
||||||
QCOMPARE(EventHandler::authorDisplayName(room, room->messageEvents().at(1).get()), QStringLiteral("before"));
|
QCOMPARE(EventHandler::authorDisplayName(room, room->messageEvents().at(1).get()), QStringLiteral("before"));
|
||||||
@@ -295,30 +276,6 @@ void EventHandlerTest::nullMediaInfo()
|
|||||||
QCOMPARE(EventHandler::mediaInfo(room, nullptr), QVariantMap());
|
QCOMPARE(EventHandler::mediaInfo(room, nullptr), QVariantMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::hasReply()
|
|
||||||
{
|
|
||||||
QCOMPARE(EventHandler::hasReply(room->messageEvents().at(5).get()), true);
|
|
||||||
QCOMPARE(EventHandler::hasReply(room->messageEvents().at(0).get()), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::nullHasReply()
|
|
||||||
{
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "hasReply called with event set to nullptr.");
|
|
||||||
QCOMPARE(EventHandler::hasReply(nullptr), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::replyId()
|
|
||||||
{
|
|
||||||
QCOMPARE(EventHandler::replyId(room->messageEvents().at(5).get()), QStringLiteral("$153456789:example.org"));
|
|
||||||
QCOMPARE(EventHandler::replyId(room->messageEvents().at(0).get()), QStringLiteral(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::nullReplyId()
|
|
||||||
{
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "replyId called with event set to nullptr.");
|
|
||||||
QCOMPARE(EventHandler::replyId(nullptr), QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::replyAuthor()
|
void EventHandlerTest::replyAuthor()
|
||||||
{
|
{
|
||||||
auto replyEvent = room->messageEvents().at(0).get();
|
auto replyEvent = room->messageEvents().at(0).get();
|
||||||
@@ -344,29 +301,6 @@ void EventHandlerTest::nullReplyAuthor()
|
|||||||
QCOMPARE(EventHandler::replyAuthor(room, nullptr), RoomMember());
|
QCOMPARE(EventHandler::replyAuthor(room, nullptr), RoomMember());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::thread()
|
|
||||||
{
|
|
||||||
QCOMPARE(EventHandler::isThreaded(room->messageEvents().at(0).get()), false);
|
|
||||||
QCOMPARE(EventHandler::threadRoot(room->messageEvents().at(0).get()), QString());
|
|
||||||
|
|
||||||
QCOMPARE(EventHandler::isThreaded(room->messageEvents().at(9).get()), true);
|
|
||||||
QCOMPARE(EventHandler::threadRoot(room->messageEvents().at(9).get()), QStringLiteral("$threadroot:example.org"));
|
|
||||||
QCOMPARE(EventHandler::replyId(room->messageEvents().at(9).get()), QStringLiteral("$threadroot:example.org"));
|
|
||||||
|
|
||||||
QCOMPARE(EventHandler::isThreaded(room->messageEvents().at(10).get()), true);
|
|
||||||
QCOMPARE(EventHandler::threadRoot(room->messageEvents().at(10).get()), QStringLiteral("$threadroot:example.org"));
|
|
||||||
QCOMPARE(EventHandler::replyId(room->messageEvents().at(10).get()), QStringLiteral("$threadmessage1:example.org"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::nullThread()
|
|
||||||
{
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "isThreaded called with event set to nullptr.");
|
|
||||||
QCOMPARE(EventHandler::isThreaded(nullptr), false);
|
|
||||||
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "threadRoot called with event set to nullptr.");
|
|
||||||
QCOMPARE(EventHandler::threadRoot(nullptr), QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::location()
|
void EventHandlerTest::location()
|
||||||
{
|
{
|
||||||
QCOMPARE(EventHandler::latitude(room->messageEvents().at(7).get()), QStringLiteral("51.7035").toFloat());
|
QCOMPARE(EventHandler::latitude(room->messageEvents().at(7).get()), QStringLiteral("51.7035").toFloat());
|
||||||
|
|||||||
@@ -49,16 +49,6 @@ Q_DECLARE_FLAGS(MemberChanges, MemberChange)
|
|||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(MemberChanges)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(MemberChanges)
|
||||||
};
|
};
|
||||||
|
|
||||||
QString EventHandler::id(const Quotient::RoomEvent *event)
|
|
||||||
{
|
|
||||||
if (event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "id called with event set to nullptr.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return !event->id().isEmpty() ? event->id() : event->transactionId();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString EventHandler::authorDisplayName(const NeoChatRoom *room, const Quotient::RoomEvent *event, bool isPending)
|
QString EventHandler::authorDisplayName(const NeoChatRoom *room, const Quotient::RoomEvent *event, bool isPending)
|
||||||
{
|
{
|
||||||
if (room == nullptr) {
|
if (room == nullptr) {
|
||||||
@@ -834,31 +824,6 @@ QVariantMap EventHandler::getMediaInfoFromTumbnail(const NeoChatRoom *room, cons
|
|||||||
return thumbnailInfo;
|
return thumbnailInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventHandler::hasReply(const Quotient::RoomEvent *event, bool showFallbacks)
|
|
||||||
{
|
|
||||||
if (event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "hasReply called with event set to nullptr.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto relations = event->contentPart<QJsonObject>("m.relates_to"_ls);
|
|
||||||
if (!relations.isEmpty()) {
|
|
||||||
const bool hasReplyRelation = relations.contains("m.in_reply_to"_ls);
|
|
||||||
bool isFallingBack = relations["is_falling_back"_ls].toBool();
|
|
||||||
return hasReplyRelation && (showFallbacks ? true : !isFallingBack);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString EventHandler::replyId(const Quotient::RoomEvent *event)
|
|
||||||
{
|
|
||||||
if (event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "replyId called with event set to nullptr.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
return event->contentJson()["m.relates_to"_ls].toObject()["m.in_reply_to"_ls].toObject()["event_id"_ls].toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
Quotient::RoomMember EventHandler::replyAuthor(const NeoChatRoom *room, const Quotient::RoomEvent *event)
|
Quotient::RoomMember EventHandler::replyAuthor(const NeoChatRoom *room, const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (room == nullptr) {
|
if (room == nullptr) {
|
||||||
@@ -877,38 +842,6 @@ Quotient::RoomMember EventHandler::replyAuthor(const NeoChatRoom *room, const Qu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventHandler::isThreaded(const Quotient::RoomEvent *event)
|
|
||||||
{
|
|
||||||
if (event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "isThreaded called with event set to nullptr.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (event->contentPart<QJsonObject>("m.relates_to"_ls).contains("rel_type"_ls)
|
|
||||||
&& event->contentPart<QJsonObject>("m.relates_to"_ls)["rel_type"_ls].toString() == "m.thread"_ls)
|
|
||||||
|| (!event->unsignedPart<QJsonObject>("m.relations"_ls).isEmpty() && event->unsignedPart<QJsonObject>("m.relations"_ls).contains("m.thread"_ls));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString EventHandler::threadRoot(const Quotient::RoomEvent *event)
|
|
||||||
{
|
|
||||||
if (event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "threadRoot called with event set to nullptr.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the thread root ID from m.relates_to if it exists.
|
|
||||||
if (event->contentPart<QJsonObject>("m.relates_to"_ls).contains("rel_type"_ls)
|
|
||||||
&& event->contentPart<QJsonObject>("m.relates_to"_ls)["rel_type"_ls].toString() == "m.thread"_ls) {
|
|
||||||
return event->contentPart<QJsonObject>("m.relates_to"_ls)["event_id"_ls].toString();
|
|
||||||
}
|
|
||||||
// For thread root events they have an m.relations in the unsigned part with a m.thread object.
|
|
||||||
// If so return the event ID as it is the root.
|
|
||||||
if (!event->unsignedPart<QJsonObject>("m.relations"_ls).isEmpty() && event->unsignedPart<QJsonObject>("m.relations"_ls).contains("m.thread"_ls)) {
|
|
||||||
return id(event);
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
float EventHandler::latitude(const Quotient::RoomEvent *event)
|
float EventHandler::latitude(const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (event == nullptr) {
|
if (event == nullptr) {
|
||||||
|
|||||||
@@ -37,14 +37,6 @@ class NeoChatRoom;
|
|||||||
class EventHandler
|
class EventHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* @brief Return the ID of the event.
|
|
||||||
*
|
|
||||||
* Returns the transaction ID if the Matrix ID is empty, which may be the case
|
|
||||||
* for a pending event.
|
|
||||||
*/
|
|
||||||
static QString id(const Quotient::RoomEvent *event);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the display name of the event author.
|
* @brief Get the display name of the event author.
|
||||||
*
|
*
|
||||||
@@ -220,20 +212,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
static QVariantMap mediaInfo(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
static QVariantMap mediaInfo(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Whether the event is a reply to another in the timeline.
|
|
||||||
*
|
|
||||||
* @param showFallbacks whether message that have is_falling_back set true should
|
|
||||||
* show the fallback reply. Leave true for non-threaded
|
|
||||||
* timelines.
|
|
||||||
*/
|
|
||||||
static bool hasReply(const Quotient::RoomEvent *event, bool showFallbacks = true);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the Matrix ID of the event replied to.
|
|
||||||
*/
|
|
||||||
static QString replyId(const Quotient::RoomEvent *event);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the author of the event replied to in context of the room.
|
* @brief Get the author of the event replied to in context of the room.
|
||||||
*
|
*
|
||||||
@@ -249,20 +227,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
static Quotient::RoomMember replyAuthor(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
static Quotient::RoomMember replyAuthor(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Whether the message is part of a thread.
|
|
||||||
*
|
|
||||||
* i.e. There is a rel_type of m.thread.
|
|
||||||
*/
|
|
||||||
static bool isThreaded(const Quotient::RoomEvent *event);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the Matrix ID of the thread's root message.
|
|
||||||
*
|
|
||||||
* Empty if this not part of a thread.
|
|
||||||
*/
|
|
||||||
static QString threadRoot(const Quotient::RoomEvent *event);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the latitude for the event.
|
* @brief Return the latitude for the event.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
|||||||
return component.attributes;
|
return component.attributes;
|
||||||
}
|
}
|
||||||
if (role == EventIdRole) {
|
if (role == EventIdRole) {
|
||||||
return EventHandler::id(event.first);
|
return event.first->displayId();
|
||||||
}
|
}
|
||||||
if (role == TimeRole) {
|
if (role == TimeRole) {
|
||||||
const auto pendingIt = std::find_if(m_room->pendingEvents().cbegin(), m_room->pendingEvents().cend(), [event](const PendingEventItem &pendingEvent) {
|
const auto pendingIt = std::find_if(m_room->pendingEvents().cbegin(), m_room->pendingEvents().cend(), [event](const PendingEventItem &pendingEvent) {
|
||||||
@@ -348,7 +348,9 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant::fromValue<PollHandler *>(m_room->poll(m_eventId));
|
return QVariant::fromValue<PollHandler *>(m_room->poll(m_eventId));
|
||||||
}
|
}
|
||||||
if (role == ReplyEventIdRole) {
|
if (role == ReplyEventIdRole) {
|
||||||
return EventHandler::replyId(event.first);
|
if (const auto roomMessageEvent = eventCast<const RoomMessageEvent>(event.first)) {
|
||||||
|
return roomMessageEvent->replyEventId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (role == ReplyAuthorRole) {
|
if (role == ReplyAuthorRole) {
|
||||||
return QVariant::fromValue(EventHandler::replyAuthor(m_room, event.first));
|
return QVariant::fromValue(EventHandler::replyAuthor(m_room, event.first));
|
||||||
@@ -456,8 +458,8 @@ QList<MessageComponent> MessageContentModel::messageContentComponents(bool isEdi
|
|||||||
|
|
||||||
QList<MessageComponent> newComponents;
|
QList<MessageComponent> newComponents;
|
||||||
|
|
||||||
if (eventCast<const Quotient::RoomMessageEvent>(event.first)
|
const auto roomMessageEvent = eventCast<const Quotient::RoomMessageEvent>(event.first);
|
||||||
&& eventCast<const Quotient::RoomMessageEvent>(event.first)->rawMsgtype() == QStringLiteral("m.key.verification.request")) {
|
if (roomMessageEvent && roomMessageEvent->rawMsgtype() == QStringLiteral("m.key.verification.request")) {
|
||||||
newComponents += MessageComponent{MessageComponentType::Verification, QString(), {}};
|
newComponents += MessageComponent{MessageComponentType::Verification, QString(), {}};
|
||||||
return newComponents;
|
return newComponents;
|
||||||
}
|
}
|
||||||
@@ -482,7 +484,7 @@ QList<MessageComponent> MessageContentModel::messageContentComponents(bool isEdi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the event is already threaded the ThreadModel will handle displaying a chat bar.
|
// If the event is already threaded the ThreadModel will handle displaying a chat bar.
|
||||||
if (isThreading && !EventHandler::isThreaded(event.first)) {
|
if (isThreading && roomMessageEvent && roomMessageEvent->isThreaded()) {
|
||||||
newComponents += MessageComponent{MessageComponentType::ChatBar, QString(), {}};
|
newComponents += MessageComponent{MessageComponentType::ChatBar, QString(), {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,7 +498,8 @@ void MessageContentModel::updateReplyModel()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EventHandler::hasReply(event.first) || (EventHandler::isThreaded(event.first) && NeoChatConfig::self()->threads())) {
|
const auto roomMessageEvent = eventCast<const Quotient::RoomMessageEvent>(event.first);
|
||||||
|
if (!roomMessageEvent->isReply() || (roomMessageEvent && roomMessageEvent->isThreaded() && NeoChatConfig::self()->threads())) {
|
||||||
if (m_replyModel) {
|
if (m_replyModel) {
|
||||||
delete m_replyModel;
|
delete m_replyModel;
|
||||||
}
|
}
|
||||||
@@ -507,7 +510,7 @@ void MessageContentModel::updateReplyModel()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_replyModel = new MessageContentModel(m_room, EventHandler::replyId(event.first), true, false, this);
|
m_replyModel = new MessageContentModel(m_room, roomMessageEvent->replyEventId(), true, false, this);
|
||||||
|
|
||||||
connect(m_replyModel, &MessageContentModel::eventUpdated, this, [this]() {
|
connect(m_replyModel, &MessageContentModel::eventUpdated, this, [this]() {
|
||||||
Q_EMIT dataChanged(index(0), index(0), {ReplyAuthorRole});
|
Q_EMIT dataChanged(index(0), index(0), {ReplyAuthorRole});
|
||||||
|
|||||||
@@ -501,7 +501,8 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
return EventStatus::Hidden;
|
return EventStatus::Hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EventHandler::isThreaded(&evt) && EventHandler::threadRoot(&evt) != EventHandler::id(&evt) && NeoChatConfig::threads()) {
|
auto roomMessageEvent = eventCast<const RoomMessageEvent>(&evt);
|
||||||
|
if (roomMessageEvent && roomMessageEvent->isThreaded() && roomMessageEvent->threadRootEventId() != evt.id() && NeoChatConfig::threads()) {
|
||||||
return EventStatus::Hidden;
|
return EventStatus::Hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,7 +510,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (role == EventIdRole) {
|
if (role == EventIdRole) {
|
||||||
return EventHandler::id(&evt);
|
return evt.displayId();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == ProgressInfoRole) {
|
if (role == ProgressInfoRole) {
|
||||||
@@ -534,11 +535,18 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (role == IsThreadedRole) {
|
if (role == IsThreadedRole) {
|
||||||
return EventHandler::isThreaded(&evt);
|
if (auto roomMessageEvent = eventCast<const RoomMessageEvent>(&evt)) {
|
||||||
|
return roomMessageEvent->isThreaded();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == ThreadRootRole) {
|
if (role == ThreadRootRole) {
|
||||||
return EventHandler::threadRoot(&evt);
|
auto roomMessageEvent = eventCast<const RoomMessageEvent>(&evt);
|
||||||
|
if (roomMessageEvent && roomMessageEvent->isThreaded()) {
|
||||||
|
return roomMessageEvent->threadRootEventId();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == ShowSectionRole) {
|
if (role == ShowSectionRole) {
|
||||||
@@ -654,8 +662,10 @@ void MessageEventModel::createEventObjects(const Quotient::RoomEvent *event, boo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EventHandler::isThreaded(event) && !m_threadModels.contains(EventHandler::threadRoot(event))) {
|
const auto roomMessageEvent = eventCast<const Quotient::RoomMessageEvent>(event);
|
||||||
m_threadModels[EventHandler::threadRoot(event)] = QSharedPointer<ThreadModel>(new ThreadModel(EventHandler::threadRoot(event), m_currentRoom));
|
if (roomMessageEvent && roomMessageEvent->isThreaded() && !m_threadModels.contains(roomMessageEvent->threadRootEventId())) {
|
||||||
|
m_threadModels[roomMessageEvent->threadRootEventId()] =
|
||||||
|
QSharedPointer<ThreadModel>(new ThreadModel(roomMessageEvent->threadRootEventId(), m_currentRoom));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadMarkerModel handles updates to add and remove markers, we only need to
|
// ReadMarkerModel handles updates to add and remove markers, we only need to
|
||||||
|
|||||||
@@ -108,11 +108,17 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const
|
|||||||
case HighlightRole:
|
case HighlightRole:
|
||||||
return EventHandler::isHighlighted(m_room, &event);
|
return EventHandler::isHighlighted(m_room, &event);
|
||||||
case EventIdRole:
|
case EventIdRole:
|
||||||
return EventHandler::id(&event);
|
return event.displayId();
|
||||||
case IsThreadedRole:
|
case IsThreadedRole:
|
||||||
return EventHandler::isThreaded(&event);
|
if (auto roomMessageEvent = eventCast<const RoomMessageEvent>(&event)) {
|
||||||
|
return roomMessageEvent->isThreaded();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
case ThreadRootRole:
|
case ThreadRootRole:
|
||||||
return EventHandler::threadRoot(&event);
|
if (auto roomMessageEvent = eventCast<const RoomMessageEvent>(&event); roomMessageEvent->isThreaded()) {
|
||||||
|
return roomMessageEvent->threadRootEventId();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
case ContentModelRole: {
|
case ContentModelRole: {
|
||||||
if (!event.isStateEvent()) {
|
if (!event.isStateEvent()) {
|
||||||
return QVariant::fromValue<MessageContentModel *>(new MessageContentModel(m_room, event.id()));
|
return QVariant::fromValue<MessageContentModel *>(new MessageContentModel(m_room, event.id()));
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ ThreadModel::ThreadModel(const QString &threadRootId, NeoChatRoom *room)
|
|||||||
|
|
||||||
connect(room, &Quotient::Room::pendingEventAboutToAdd, this, [this](Quotient::RoomEvent *event) {
|
connect(room, &Quotient::Room::pendingEventAboutToAdd, this, [this](Quotient::RoomEvent *event) {
|
||||||
if (auto roomEvent = eventCast<const Quotient::RoomMessageEvent>(event)) {
|
if (auto roomEvent = eventCast<const Quotient::RoomMessageEvent>(event)) {
|
||||||
if (EventHandler::isThreaded(roomEvent) && EventHandler::threadRoot(roomEvent) == m_threadRootId) {
|
if (roomEvent->isThreaded() && roomEvent->threadRootEventId() == m_threadRootId) {
|
||||||
addNewEvent(event);
|
addNewEvent(event);
|
||||||
addModels();
|
addModels();
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ ThreadModel::ThreadModel(const QString &threadRootId, NeoChatRoom *room)
|
|||||||
connect(room, &Quotient::Room::aboutToAddNewMessages, this, [this](Quotient::RoomEventsRange events) {
|
connect(room, &Quotient::Room::aboutToAddNewMessages, this, [this](Quotient::RoomEventsRange events) {
|
||||||
for (const auto &event : events) {
|
for (const auto &event : events) {
|
||||||
if (auto roomEvent = eventCast<const Quotient::RoomMessageEvent>(event)) {
|
if (auto roomEvent = eventCast<const Quotient::RoomMessageEvent>(event)) {
|
||||||
if (EventHandler::isThreaded(roomEvent) && EventHandler::threadRoot(roomEvent) == m_threadRootId) {
|
if (roomEvent->isThreaded() && roomEvent->threadRootEventId() == m_threadRootId) {
|
||||||
addNewEvent(roomEvent);
|
addNewEvent(roomEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -514,7 +514,7 @@ void NeoChatRoom::postHtmlMessage(const QString &text,
|
|||||||
QString replyEventId = isFallingBack ? fallbackId : QString();
|
QString replyEventId = isFallingBack ? fallbackId : QString();
|
||||||
if (isReply) {
|
if (isReply) {
|
||||||
isFallingBack = false;
|
isFallingBack = false;
|
||||||
replyEventId = EventHandler::id(replyIt->get());
|
replyEventId = replyIt->event()->displayId();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we are not replying and there is no fallback ID it means a new thread
|
// If we are not replying and there is no fallback ID it means a new thread
|
||||||
|
|||||||
Reference in New Issue
Block a user