Rework event handler to be just a series of static helper functions
- Clear out unused functions - All functions are now static This is because we pretty much always used it in the form: ``` EventHandler eventHandler(room, event); eventHandler.function(); ``` This simplifies it all to a single call.
This commit is contained in:
@@ -29,8 +29,6 @@ private:
|
|||||||
Connection *connection = nullptr;
|
Connection *connection = nullptr;
|
||||||
TestUtils::TestRoom *room = nullptr;
|
TestUtils::TestRoom *room = nullptr;
|
||||||
|
|
||||||
EventHandler emptyHandler = EventHandler(nullptr, nullptr);
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
|
|
||||||
@@ -43,7 +41,6 @@ private Q_SLOTS:
|
|||||||
void time();
|
void time();
|
||||||
void nullTime();
|
void nullTime();
|
||||||
void timeString();
|
void timeString();
|
||||||
void nullTimeString();
|
|
||||||
void highlighted();
|
void highlighted();
|
||||||
void nullHighlighted();
|
void nullHighlighted();
|
||||||
void hidden();
|
void hidden();
|
||||||
@@ -65,10 +62,6 @@ private Q_SLOTS:
|
|||||||
void nullReplyId();
|
void nullReplyId();
|
||||||
void replyAuthor();
|
void replyAuthor();
|
||||||
void nullReplyAuthor();
|
void nullReplyAuthor();
|
||||||
void replyBody();
|
|
||||||
void nullReplyBody();
|
|
||||||
void replyMediaInfo();
|
|
||||||
void nullReplyMediaInfo();
|
|
||||||
void thread();
|
void thread();
|
||||||
void nullThread();
|
void nullThread();
|
||||||
void location();
|
void location();
|
||||||
@@ -83,157 +76,136 @@ void EventHandlerTest::initTestCase()
|
|||||||
|
|
||||||
void EventHandlerTest::eventId()
|
void EventHandlerTest::eventId()
|
||||||
{
|
{
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(0).get());
|
QCOMPARE(EventHandler::id(room->messageEvents().at(0).get()), QStringLiteral("$153456789:example.org"));
|
||||||
QCOMPARE(eventHandler.getId(), QStringLiteral("$153456789:example.org"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullEventId()
|
void EventHandlerTest::nullEventId()
|
||||||
{
|
{
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "id called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getId called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::id(nullptr), QString());
|
||||||
QCOMPARE(noEventHandler.getId(), QString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::authorDisplayName()
|
void EventHandlerTest::authorDisplayName()
|
||||||
{
|
{
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(1).get());
|
QCOMPARE(EventHandler::authorDisplayName(room, room->messageEvents().at(1).get()), QStringLiteral("before"));
|
||||||
QCOMPARE(eventHandler.getAuthorDisplayName(), QStringLiteral("before"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullAuthorDisplayName()
|
void EventHandlerTest::nullAuthorDisplayName()
|
||||||
{
|
{
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getAuthorDisplayName called with m_room set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "authorDisplayName called with room set to nullptr.");
|
||||||
QCOMPARE(emptyHandler.getAuthorDisplayName(), QString());
|
QCOMPARE(EventHandler::authorDisplayName(nullptr, nullptr), QString());
|
||||||
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "authorDisplayName called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getAuthorDisplayName called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::authorDisplayName(room, nullptr), QString());
|
||||||
QCOMPARE(noEventHandler.getAuthorDisplayName(), QString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::singleLineSidplayName()
|
void EventHandlerTest::singleLineSidplayName()
|
||||||
{
|
{
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(11).get());
|
QCOMPARE(EventHandler::singleLineAuthorDisplayname(room, room->messageEvents().at(11).get()),
|
||||||
QCOMPARE(eventHandler.singleLineAuthorDisplayname(), QStringLiteral("Look at me I put newlines in my display name"));
|
QStringLiteral("Look at me I put newlines in my display name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullSingleLineDisplayName()
|
void EventHandlerTest::nullSingleLineDisplayName()
|
||||||
{
|
{
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getAuthorDisplayName called with m_room set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "singleLineAuthorDisplayname called with room set to nullptr.");
|
||||||
QCOMPARE(emptyHandler.singleLineAuthorDisplayname(), QString());
|
QCOMPARE(EventHandler::singleLineAuthorDisplayname(nullptr, nullptr), QString());
|
||||||
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "singleLineAuthorDisplayname called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getAuthorDisplayName called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::singleLineAuthorDisplayname(room, nullptr), QString());
|
||||||
QCOMPARE(noEventHandler.singleLineAuthorDisplayname(), QString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::time()
|
void EventHandlerTest::time()
|
||||||
{
|
{
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(0).get());
|
const auto event = room->messageEvents().at(0).get();
|
||||||
|
|
||||||
QCOMPARE(eventHandler.getTime(), QDateTime::fromMSecsSinceEpoch(1432735824654, Qt::UTC));
|
QCOMPARE(EventHandler::time(event), QDateTime::fromMSecsSinceEpoch(1432735824654, Qt::UTC));
|
||||||
QCOMPARE(eventHandler.getTime(true, QDateTime::fromMSecsSinceEpoch(1234, Qt::UTC)), QDateTime::fromMSecsSinceEpoch(1234, Qt::UTC));
|
QCOMPARE(EventHandler::time(event, true, QDateTime::fromMSecsSinceEpoch(1234, Qt::UTC)), QDateTime::fromMSecsSinceEpoch(1234, Qt::UTC));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullTime()
|
void EventHandlerTest::nullTime()
|
||||||
{
|
{
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "time called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getTime called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::time(nullptr), QDateTime());
|
||||||
QCOMPARE(noEventHandler.getTime(), QDateTime());
|
|
||||||
|
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(0).get());
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "a value must be provided for lastUpdated for a pending event.");
|
QTest::ignoreMessage(QtWarningMsg, "a value must be provided for lastUpdated for a pending event.");
|
||||||
QCOMPARE(eventHandler.getTime(true), QDateTime());
|
QCOMPARE(EventHandler::time(room->messageEvents().at(0).get(), true), QDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::timeString()
|
void EventHandlerTest::timeString()
|
||||||
{
|
{
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(0).get());
|
const auto event = room->messageEvents().at(0).get();
|
||||||
|
|
||||||
KFormat format;
|
KFormat format;
|
||||||
|
|
||||||
QCOMPARE(eventHandler.getTimeString(false),
|
QCOMPARE(EventHandler::timeString(event, false),
|
||||||
QLocale().toString(QDateTime::fromMSecsSinceEpoch(1432735824654, Qt::UTC).toLocalTime().time(), QLocale::ShortFormat));
|
QLocale().toString(QDateTime::fromMSecsSinceEpoch(1432735824654, Qt::UTC).toLocalTime().time(), QLocale::ShortFormat));
|
||||||
QCOMPARE(eventHandler.getTimeString(true),
|
QCOMPARE(EventHandler::timeString(event, true),
|
||||||
format.formatRelativeDate(QDateTime::fromMSecsSinceEpoch(1432735824654, Qt::UTC).toLocalTime().date(), QLocale::ShortFormat));
|
format.formatRelativeDate(QDateTime::fromMSecsSinceEpoch(1432735824654, Qt::UTC).toLocalTime().date(), QLocale::ShortFormat));
|
||||||
QCOMPARE(eventHandler.getTimeString(false, QLocale::ShortFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)),
|
QCOMPARE(EventHandler::timeString(event, false, QLocale::ShortFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)),
|
||||||
QLocale().toString(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().time(), QLocale::ShortFormat));
|
QLocale().toString(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().time(), QLocale::ShortFormat));
|
||||||
QCOMPARE(eventHandler.getTimeString(true, QLocale::ShortFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)),
|
QCOMPARE(EventHandler::timeString(event, true, QLocale::ShortFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)),
|
||||||
format.formatRelativeDate(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().date(), QLocale::ShortFormat));
|
format.formatRelativeDate(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().date(), QLocale::ShortFormat));
|
||||||
QCOMPARE(eventHandler.getTimeString(false, QLocale::LongFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)),
|
QCOMPARE(EventHandler::timeString(event, false, QLocale::LongFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)),
|
||||||
QLocale().toString(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().time(), QLocale::LongFormat));
|
QLocale().toString(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().time(), QLocale::LongFormat));
|
||||||
QCOMPARE(eventHandler.getTimeString(true, QLocale::LongFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)),
|
QCOMPARE(EventHandler::timeString(event, true, QLocale::LongFormat, true, QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC)),
|
||||||
format.formatRelativeDate(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().date(), QLocale::LongFormat));
|
format.formatRelativeDate(QDateTime::fromMSecsSinceEpoch(1690699214545, Qt::UTC).toLocalTime().date(), QLocale::LongFormat));
|
||||||
QCOMPARE(eventHandler.getTimeString(QStringLiteral("hh:mm")), QDateTime::fromMSecsSinceEpoch(1432735824654, Qt::UTC).toString(QStringLiteral("hh:mm")));
|
QCOMPARE(EventHandler::timeString(event, QStringLiteral("hh:mm")),
|
||||||
}
|
QDateTime::fromMSecsSinceEpoch(1432735824654, Qt::UTC).toString(QStringLiteral("hh:mm")));
|
||||||
|
|
||||||
void EventHandlerTest::nullTimeString()
|
|
||||||
{
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getTimeString called with m_event set to nullptr.");
|
|
||||||
QCOMPARE(noEventHandler.getTimeString(false), QString());
|
|
||||||
|
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(0).get());
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "a value must be provided for lastUpdated for a pending event.");
|
|
||||||
QCOMPARE(eventHandler.getTimeString(false, QLocale::ShortFormat, true), QString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::highlighted()
|
void EventHandlerTest::highlighted()
|
||||||
{
|
{
|
||||||
EventHandler eventHandlerHighlight(room, room->messageEvents().at(2).get());
|
QCOMPARE(EventHandler::isHighlighted(room, room->messageEvents().at(2).get()), true);
|
||||||
QCOMPARE(eventHandlerHighlight.isHighlighted(), true);
|
QCOMPARE(EventHandler::isHighlighted(room, room->messageEvents().at(0).get()), false);
|
||||||
|
|
||||||
EventHandler eventHandlerNoHighlight(room, room->messageEvents().at(0).get());
|
|
||||||
QCOMPARE(eventHandlerNoHighlight.isHighlighted(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullHighlighted()
|
void EventHandlerTest::nullHighlighted()
|
||||||
{
|
{
|
||||||
QTest::ignoreMessage(QtWarningMsg, "isHighlighted called with m_room set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "isHighlighted called with room set to nullptr.");
|
||||||
QCOMPARE(emptyHandler.isHighlighted(), false);
|
QCOMPARE(EventHandler::isHighlighted(nullptr, nullptr), false);
|
||||||
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "isHighlighted called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "isHighlighted called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::isHighlighted(room, nullptr), false);
|
||||||
QCOMPARE(noEventHandler.isHighlighted(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::hidden()
|
void EventHandlerTest::hidden()
|
||||||
{
|
{
|
||||||
EventHandler eventHandlerHidden(room, room->messageEvents().at(3).get());
|
QCOMPARE(EventHandler::isHidden(room, room->messageEvents().at(3).get()), true);
|
||||||
QCOMPARE(eventHandlerHidden.isHidden(), true);
|
QCOMPARE(EventHandler::isHidden(room, room->messageEvents().at(0).get()), false);
|
||||||
|
|
||||||
EventHandler eventHandlerNoHidden(room, room->messageEvents().at(0).get());
|
|
||||||
QCOMPARE(eventHandlerNoHidden.isHidden(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullHidden()
|
void EventHandlerTest::nullHidden()
|
||||||
{
|
{
|
||||||
QTest::ignoreMessage(QtWarningMsg, "isHidden called with m_room set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "isHidden called with room set to nullptr.");
|
||||||
QCOMPARE(emptyHandler.isHidden(), false);
|
QCOMPARE(EventHandler::isHidden(nullptr, nullptr), false);
|
||||||
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "isHidden called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "isHidden called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::isHidden(room, nullptr), false);
|
||||||
QCOMPARE(noEventHandler.isHidden(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::body()
|
void EventHandlerTest::body()
|
||||||
{
|
{
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(0).get());
|
const auto event = room->messageEvents().at(0).get();
|
||||||
|
|
||||||
QCOMPARE(eventHandler.getRichBody(), QStringLiteral("<b>This is an example<br>text message</b>"));
|
QCOMPARE(EventHandler::richBody(room, event), QStringLiteral("<b>This is an example<br>text message</b>"));
|
||||||
QCOMPARE(eventHandler.getRichBody(true), QStringLiteral("<b>This is an example text message</b>"));
|
QCOMPARE(EventHandler::richBody(room, event, true), QStringLiteral("<b>This is an example text message</b>"));
|
||||||
QCOMPARE(eventHandler.getPlainBody(), QStringLiteral("This is an example\ntext message"));
|
QCOMPARE(EventHandler::plainBody(room, event), QStringLiteral("This is an example\ntext message"));
|
||||||
QCOMPARE(eventHandler.getPlainBody(true), QStringLiteral("This is an example text message"));
|
QCOMPARE(EventHandler::plainBody(room, event, true), QStringLiteral("This is an example text message"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullBody()
|
void EventHandlerTest::nullBody()
|
||||||
{
|
{
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "richBody called with room set to nullptr.");
|
||||||
|
QCOMPARE(EventHandler::richBody(nullptr, nullptr), QString());
|
||||||
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getRichBody called with m_event set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "richBody called with event set to nullptr.");
|
||||||
QCOMPARE(noEventHandler.getRichBody(), QString());
|
QCOMPARE(EventHandler::richBody(room, nullptr), QString());
|
||||||
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getPlainBody called with m_event set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "plainBody called with room set to nullptr.");
|
||||||
QCOMPARE(noEventHandler.getPlainBody(), QString());
|
QCOMPARE(EventHandler::plainBody(nullptr, nullptr), QString());
|
||||||
|
|
||||||
|
QTest::ignoreMessage(QtWarningMsg, "plainBody called with event set to nullptr.");
|
||||||
|
QCOMPARE(EventHandler::plainBody(room, nullptr), QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::genericBody_data()
|
void EventHandlerTest::genericBody_data()
|
||||||
@@ -253,54 +225,45 @@ void EventHandlerTest::genericBody()
|
|||||||
QFETCH(int, eventNum);
|
QFETCH(int, eventNum);
|
||||||
QFETCH(QString, output);
|
QFETCH(QString, output);
|
||||||
|
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(eventNum).get());
|
QCOMPARE(EventHandler::genericBody(room->messageEvents().at(eventNum).get()), output);
|
||||||
|
|
||||||
QCOMPARE(eventHandler.getGenericBody(), output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullGenericBody()
|
void EventHandlerTest::nullGenericBody()
|
||||||
{
|
{
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "genericBody called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getGenericBody called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::genericBody(nullptr), QString());
|
||||||
QCOMPARE(noEventHandler.getGenericBody(), QString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::markdownBody()
|
void EventHandlerTest::markdownBody()
|
||||||
{
|
{
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(0).get());
|
QCOMPARE(EventHandler::markdownBody(room->messageEvents().at(0).get()), QStringLiteral("This is an example\ntext message"));
|
||||||
|
|
||||||
QCOMPARE(eventHandler.getMarkdownBody(), QStringLiteral("This is an example\ntext message"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::markdownBodyReply()
|
void EventHandlerTest::markdownBodyReply()
|
||||||
{
|
{
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(5).get());
|
QCOMPARE(EventHandler::markdownBody(room->messageEvents().at(5).get()), QStringLiteral("reply"));
|
||||||
|
|
||||||
QCOMPARE(eventHandler.getMarkdownBody(), QStringLiteral("reply"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::subtitle()
|
void EventHandlerTest::subtitle()
|
||||||
{
|
{
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(0).get());
|
QCOMPARE(EventHandler::subtitleText(room, room->messageEvents().at(0).get()), QStringLiteral("after: This is an example text message"));
|
||||||
QCOMPARE(eventHandler.subtitleText(), QStringLiteral("after: This is an example text message"));
|
QCOMPARE(EventHandler::subtitleText(room, room->messageEvents().at(2).get()),
|
||||||
|
QStringLiteral("after: This is a highlight @bob:kde.org and this is a link https://kde.org"));
|
||||||
EventHandler eventHandler2(room, room->messageEvents().at(2).get());
|
|
||||||
QCOMPARE(eventHandler2.subtitleText(), QStringLiteral("after: This is a highlight @bob:kde.org and this is a link https://kde.org"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullSubtitle()
|
void EventHandlerTest::nullSubtitle()
|
||||||
{
|
{
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "subtitleText called with room set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "subtitleText called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::subtitleText(nullptr, nullptr), QString());
|
||||||
QCOMPARE(noEventHandler.subtitleText(), QString());
|
|
||||||
|
QTest::ignoreMessage(QtWarningMsg, "subtitleText called with event set to nullptr.");
|
||||||
|
QCOMPARE(EventHandler::subtitleText(room, nullptr), QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::mediaInfo()
|
void EventHandlerTest::mediaInfo()
|
||||||
{
|
{
|
||||||
auto event = room->messageEvents().at(4).get();
|
auto event = room->messageEvents().at(4).get();
|
||||||
EventHandler eventHandler(room, event);
|
auto mediaInfo = EventHandler::mediaInfo(room, event);
|
||||||
|
|
||||||
auto mediaInfo = eventHandler.getMediaInfo();
|
|
||||||
auto thumbnailInfo = mediaInfo["tempInfo"_ls].toMap();
|
auto thumbnailInfo = mediaInfo["tempInfo"_ls].toMap();
|
||||||
|
|
||||||
QCOMPARE(mediaInfo["source"_ls], room->makeMediaUrl(event->id(), QUrl("mxc://kde.org/1234567"_ls)));
|
QCOMPARE(mediaInfo["source"_ls], room->makeMediaUrl(event->id(), QUrl("mxc://kde.org/1234567"_ls)));
|
||||||
@@ -320,53 +283,42 @@ void EventHandlerTest::mediaInfo()
|
|||||||
|
|
||||||
void EventHandlerTest::nullMediaInfo()
|
void EventHandlerTest::nullMediaInfo()
|
||||||
{
|
{
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getMediaInfo called with m_room set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "mediaInfo called with room set to nullptr.");
|
||||||
QCOMPARE(emptyHandler.getMediaInfo(), QVariantMap());
|
QCOMPARE(EventHandler::mediaInfo(nullptr, nullptr), QVariantMap());
|
||||||
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "mediaInfo called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getMediaInfo called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::mediaInfo(room, nullptr), QVariantMap());
|
||||||
QCOMPARE(noEventHandler.getMediaInfo(), QVariantMap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::hasReply()
|
void EventHandlerTest::hasReply()
|
||||||
{
|
{
|
||||||
EventHandler eventHandlerReply(room, room->messageEvents().at(5).get());
|
QCOMPARE(EventHandler::hasReply(room->messageEvents().at(5).get()), true);
|
||||||
QCOMPARE(eventHandlerReply.hasReply(), true);
|
QCOMPARE(EventHandler::hasReply(room->messageEvents().at(0).get()), false);
|
||||||
|
|
||||||
EventHandler eventHandlerNoReply(room, room->messageEvents().at(0).get());
|
|
||||||
QCOMPARE(eventHandlerNoReply.hasReply(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullHasReply()
|
void EventHandlerTest::nullHasReply()
|
||||||
{
|
{
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "hasReply called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "hasReply called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::hasReply(nullptr), false);
|
||||||
QCOMPARE(noEventHandler.hasReply(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::replyId()
|
void EventHandlerTest::replyId()
|
||||||
{
|
{
|
||||||
EventHandler eventHandlerReply(room, room->messageEvents().at(5).get());
|
QCOMPARE(EventHandler::replyId(room->messageEvents().at(5).get()), QStringLiteral("$153456789:example.org"));
|
||||||
QCOMPARE(eventHandlerReply.getReplyId(), QStringLiteral("$153456789:example.org"));
|
QCOMPARE(EventHandler::replyId(room->messageEvents().at(0).get()), QStringLiteral(""));
|
||||||
|
|
||||||
EventHandler eventHandlerNoReply(room, room->messageEvents().at(0).get());
|
|
||||||
QCOMPARE(eventHandlerNoReply.getReplyId(), QStringLiteral(""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullReplyId()
|
void EventHandlerTest::nullReplyId()
|
||||||
{
|
{
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "replyId called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getReplyId called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::replyId(nullptr), QString());
|
||||||
QCOMPARE(noEventHandler.getReplyId(), QString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::replyAuthor()
|
void EventHandlerTest::replyAuthor()
|
||||||
{
|
{
|
||||||
auto replyEvent = room->messageEvents().at(0).get();
|
auto replyEvent = room->messageEvents().at(0).get();
|
||||||
auto replyAuthor = room->member(replyEvent->senderId());
|
auto replyAuthor = room->member(replyEvent->senderId());
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(5).get());
|
auto eventHandlerReplyAuthor = EventHandler::replyAuthor(room, room->messageEvents().at(5).get());
|
||||||
|
|
||||||
auto eventHandlerReplyAuthor = eventHandler.getReplyAuthor();
|
|
||||||
|
|
||||||
QCOMPARE(eventHandlerReplyAuthor.isLocalMember(), replyAuthor.id() == room->localMember().id());
|
QCOMPARE(eventHandlerReplyAuthor.isLocalMember(), replyAuthor.id() == room->localMember().id());
|
||||||
QCOMPARE(eventHandlerReplyAuthor.id(), replyAuthor.id());
|
QCOMPARE(eventHandlerReplyAuthor.id(), replyAuthor.id());
|
||||||
@@ -375,121 +327,58 @@ void EventHandlerTest::replyAuthor()
|
|||||||
QCOMPARE(eventHandlerReplyAuthor.avatarMediaId(), replyAuthor.avatarMediaId());
|
QCOMPARE(eventHandlerReplyAuthor.avatarMediaId(), replyAuthor.avatarMediaId());
|
||||||
QCOMPARE(eventHandlerReplyAuthor.color(), replyAuthor.color());
|
QCOMPARE(eventHandlerReplyAuthor.color(), replyAuthor.color());
|
||||||
|
|
||||||
EventHandler eventHandlerNoAuthor(room, room->messageEvents().at(0).get());
|
QCOMPARE(EventHandler::replyAuthor(room, room->messageEvents().at(0).get()), RoomMember());
|
||||||
QCOMPARE(eventHandlerNoAuthor.getReplyAuthor(), RoomMember());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullReplyAuthor()
|
void EventHandlerTest::nullReplyAuthor()
|
||||||
{
|
{
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getReplyAuthor called with m_room set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "replyAuthor called with room set to nullptr.");
|
||||||
QCOMPARE(emptyHandler.getReplyAuthor(), RoomMember());
|
QCOMPARE(EventHandler::replyAuthor(nullptr, nullptr), RoomMember());
|
||||||
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "replyAuthor called with event set to nullptr. Returning empty user.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getReplyAuthor called with m_event set to nullptr. Returning empty user.");
|
QCOMPARE(EventHandler::replyAuthor(room, nullptr), RoomMember());
|
||||||
QCOMPARE(noEventHandler.getReplyAuthor(), RoomMember());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::replyBody()
|
|
||||||
{
|
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(5).get());
|
|
||||||
|
|
||||||
QCOMPARE(eventHandler.getReplyRichBody(), QStringLiteral("<b>This is an example<br>text message</b>"));
|
|
||||||
QCOMPARE(eventHandler.getReplyRichBody(true), QStringLiteral("<b>This is an example text message</b>"));
|
|
||||||
QCOMPARE(eventHandler.getReplyPlainBody(), QStringLiteral("This is an example\ntext message"));
|
|
||||||
QCOMPARE(eventHandler.getReplyPlainBody(true), QStringLiteral("This is an example text message"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::nullReplyBody()
|
|
||||||
{
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
|
||||||
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getReplyRichBody called with m_event set to nullptr.");
|
|
||||||
QCOMPARE(noEventHandler.getReplyRichBody(), QString());
|
|
||||||
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getReplyPlainBody called with m_event set to nullptr.");
|
|
||||||
QCOMPARE(noEventHandler.getReplyPlainBody(), QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::replyMediaInfo()
|
|
||||||
{
|
|
||||||
auto event = room->messageEvents().at(6).get();
|
|
||||||
auto replyEvent = room->messageEvents().at(4).get();
|
|
||||||
EventHandler eventHandler(room, event);
|
|
||||||
|
|
||||||
auto mediaInfo = eventHandler.getReplyMediaInfo();
|
|
||||||
auto thumbnailInfo = mediaInfo["tempInfo"_ls].toMap();
|
|
||||||
|
|
||||||
QCOMPARE(mediaInfo["source"_ls], room->makeMediaUrl(replyEvent->id(), QUrl("mxc://kde.org/1234567"_ls)));
|
|
||||||
QCOMPARE(mediaInfo["mimeType"_ls], QStringLiteral("video/mp4"));
|
|
||||||
QCOMPARE(mediaInfo["mimeIcon"_ls], QStringLiteral("video-mp4"));
|
|
||||||
QCOMPARE(mediaInfo["size"_ls], 62650636);
|
|
||||||
QCOMPARE(mediaInfo["duration"_ls], 10);
|
|
||||||
QCOMPARE(mediaInfo["width"_ls], 1920);
|
|
||||||
QCOMPARE(mediaInfo["height"_ls], 1080);
|
|
||||||
QCOMPARE(thumbnailInfo["source"_ls], room->makeMediaUrl(replyEvent->id(), QUrl("mxc://kde.org/2234567"_ls)));
|
|
||||||
QCOMPARE(thumbnailInfo["mimeType"_ls], QStringLiteral("image/jpeg"));
|
|
||||||
QCOMPARE(thumbnailInfo["mimeIcon"_ls], QStringLiteral("image-jpeg"));
|
|
||||||
QCOMPARE(thumbnailInfo["size"_ls], 382249);
|
|
||||||
QCOMPARE(thumbnailInfo["width"_ls], 800);
|
|
||||||
QCOMPARE(thumbnailInfo["height"_ls], 450);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandlerTest::nullReplyMediaInfo()
|
|
||||||
{
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getReplyMediaInfo called with m_room set to nullptr.");
|
|
||||||
QCOMPARE(emptyHandler.getReplyMediaInfo(), QVariantMap());
|
|
||||||
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getReplyMediaInfo called with m_event set to nullptr.");
|
|
||||||
QCOMPARE(noEventHandler.getReplyMediaInfo(), QVariantMap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::thread()
|
void EventHandlerTest::thread()
|
||||||
{
|
{
|
||||||
EventHandler eventHandlerNoThread(room, room->messageEvents().at(0).get());
|
QCOMPARE(EventHandler::isThreaded(room->messageEvents().at(0).get()), false);
|
||||||
QCOMPARE(eventHandlerNoThread.isThreaded(), false);
|
QCOMPARE(EventHandler::threadRoot(room->messageEvents().at(0).get()), QString());
|
||||||
QCOMPARE(eventHandlerNoThread.threadRoot(), QString());
|
|
||||||
|
|
||||||
EventHandler eventHandlerThreadRoot(room, room->messageEvents().at(9).get());
|
QCOMPARE(EventHandler::isThreaded(room->messageEvents().at(9).get()), true);
|
||||||
QCOMPARE(eventHandlerThreadRoot.isThreaded(), true);
|
QCOMPARE(EventHandler::threadRoot(room->messageEvents().at(9).get()), QStringLiteral("$threadroot:example.org"));
|
||||||
QCOMPARE(eventHandlerThreadRoot.threadRoot(), QStringLiteral("$threadroot:example.org"));
|
QCOMPARE(EventHandler::replyId(room->messageEvents().at(9).get()), QStringLiteral("$threadroot:example.org"));
|
||||||
QCOMPARE(eventHandlerThreadRoot.getReplyId(), QStringLiteral("$threadroot:example.org"));
|
|
||||||
|
|
||||||
EventHandler eventHandlerThreadReply(room, room->messageEvents().at(10).get());
|
QCOMPARE(EventHandler::isThreaded(room->messageEvents().at(10).get()), true);
|
||||||
QCOMPARE(eventHandlerThreadReply.isThreaded(), true);
|
QCOMPARE(EventHandler::threadRoot(room->messageEvents().at(10).get()), QStringLiteral("$threadroot:example.org"));
|
||||||
QCOMPARE(eventHandlerThreadReply.threadRoot(), QStringLiteral("$threadroot:example.org"));
|
QCOMPARE(EventHandler::replyId(room->messageEvents().at(10).get()), QStringLiteral("$threadmessage1:example.org"));
|
||||||
QCOMPARE(eventHandlerThreadReply.getReplyId(), QStringLiteral("$threadmessage1:example.org"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullThread()
|
void EventHandlerTest::nullThread()
|
||||||
{
|
{
|
||||||
QTest::ignoreMessage(QtWarningMsg, "isThreaded called with m_event set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "isThreaded called with event set to nullptr.");
|
||||||
QCOMPARE(emptyHandler.isThreaded(), false);
|
QCOMPARE(EventHandler::isThreaded(nullptr), false);
|
||||||
|
|
||||||
EventHandler noEventHandler(room, nullptr);
|
QTest::ignoreMessage(QtWarningMsg, "threadRoot called with event set to nullptr.");
|
||||||
QTest::ignoreMessage(QtWarningMsg, "threadRoot called with m_event set to nullptr.");
|
QCOMPARE(EventHandler::threadRoot(nullptr), QString());
|
||||||
QCOMPARE(noEventHandler.threadRoot(), QString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::location()
|
void EventHandlerTest::location()
|
||||||
{
|
{
|
||||||
EventHandler eventHandler(room, room->messageEvents().at(7).get());
|
QCOMPARE(EventHandler::latitude(room->messageEvents().at(7).get()), QStringLiteral("51.7035").toFloat());
|
||||||
|
QCOMPARE(EventHandler::longitude(room->messageEvents().at(7).get()), QStringLiteral("-1.14394").toFloat());
|
||||||
QCOMPARE(eventHandler.getLatitude(), QStringLiteral("51.7035").toFloat());
|
QCOMPARE(EventHandler::locationAssetType(room->messageEvents().at(7).get()), QStringLiteral("m.pin"));
|
||||||
QCOMPARE(eventHandler.getLongitude(), QStringLiteral("-1.14394").toFloat());
|
|
||||||
QCOMPARE(eventHandler.getLocationAssetType(), QStringLiteral("m.pin"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandlerTest::nullLocation()
|
void EventHandlerTest::nullLocation()
|
||||||
{
|
{
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getLatitude called with m_event set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "latitude called with event set to nullptr.");
|
||||||
QCOMPARE(emptyHandler.getLatitude(), -100.0);
|
QCOMPARE(EventHandler::latitude(nullptr), -100.0);
|
||||||
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getLongitude called with m_event set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "longitude called with event set to nullptr.");
|
||||||
QCOMPARE(emptyHandler.getLongitude(), -200.0);
|
QCOMPARE(EventHandler::longitude(nullptr), -200.0);
|
||||||
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "getLocationAssetType called with m_event set to nullptr.");
|
QTest::ignoreMessage(QtWarningMsg, "locationAssetType called with event set to nullptr.");
|
||||||
QCOMPARE(emptyHandler.getLocationAssetType(), QString());
|
QCOMPARE(EventHandler::locationAssetType(nullptr), QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(EventHandlerTest)
|
QTEST_MAIN(EventHandlerTest)
|
||||||
|
|||||||
@@ -119,8 +119,7 @@ QString ChatBarCache::relationMessage() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (auto event = room->findInTimeline(m_relationId); event != room->historyEdge()) {
|
if (auto event = room->findInTimeline(m_relationId); event != room->historyEdge()) {
|
||||||
EventHandler eventhandler(room, &**event);
|
return EventHandler::markdownBody(&**event);
|
||||||
return eventhandler.getMarkdownBody();
|
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,16 @@
|
|||||||
|
|
||||||
#include <QMovie>
|
#include <QMovie>
|
||||||
|
|
||||||
|
#include <KFormat>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
#include <Quotient/events/encryptionevent.h>
|
#include <Quotient/events/encryptionevent.h>
|
||||||
|
#include <Quotient/events/event.h>
|
||||||
#include <Quotient/events/reactionevent.h>
|
#include <Quotient/events/reactionevent.h>
|
||||||
#include <Quotient/events/redactionevent.h>
|
#include <Quotient/events/redactionevent.h>
|
||||||
#include <Quotient/events/roomavatarevent.h>
|
#include <Quotient/events/roomavatarevent.h>
|
||||||
#include <Quotient/events/roomcanonicalaliasevent.h>
|
#include <Quotient/events/roomcanonicalaliasevent.h>
|
||||||
|
#include <Quotient/events/roomevent.h>
|
||||||
#include <Quotient/events/roommemberevent.h>
|
#include <Quotient/events/roommemberevent.h>
|
||||||
#include <Quotient/events/roompowerlevelsevent.h>
|
#include <Quotient/events/roompowerlevelsevent.h>
|
||||||
#include <Quotient/events/simplestateevents.h>
|
#include <Quotient/events/simplestateevents.h>
|
||||||
@@ -23,9 +26,6 @@
|
|||||||
#include "events/locationbeaconevent.h"
|
#include "events/locationbeaconevent.h"
|
||||||
#include "events/pollevent.h"
|
#include "events/pollevent.h"
|
||||||
#include "events/widgetevent.h"
|
#include "events/widgetevent.h"
|
||||||
#include "linkpreviewer.h"
|
|
||||||
#include "messagecomponenttype.h"
|
|
||||||
#include "models/reactionmodel.h"
|
|
||||||
#include "neochatconfig.h"
|
#include "neochatconfig.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
#include "texthandler.h"
|
#include "texthandler.h"
|
||||||
@@ -33,68 +33,52 @@
|
|||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
|
|
||||||
EventHandler::EventHandler(const NeoChatRoom *room, const RoomEvent *event)
|
QString EventHandler::id(const Quotient::RoomEvent *event)
|
||||||
: m_room(room)
|
|
||||||
, m_event(event)
|
|
||||||
{
|
{
|
||||||
}
|
if (event == nullptr) {
|
||||||
|
qCWarning(EventHandling) << "id called with event set to nullptr.";
|
||||||
QString EventHandler::getId() const
|
|
||||||
{
|
|
||||||
if (m_event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "getId called with m_event set to nullptr.";
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return !m_event->id().isEmpty() ? m_event->id() : m_event->transactionId();
|
return !event->id().isEmpty() ? event->id() : event->transactionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageComponentType::Type EventHandler::messageComponentType() const
|
QString EventHandler::authorDisplayName(const NeoChatRoom *room, const Quotient::RoomEvent *event, bool isPending)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (room == nullptr) {
|
||||||
qCWarning(EventHandling) << "messageComponentType called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "authorDisplayName called with room set to nullptr.";
|
||||||
return MessageComponentType::Other;
|
|
||||||
}
|
|
||||||
|
|
||||||
return MessageComponentType::typeForEvent(*m_event);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString EventHandler::getAuthorDisplayName(bool isPending) const
|
|
||||||
{
|
|
||||||
if (m_room == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "getAuthorDisplayName called with m_room set to nullptr.";
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getAuthorDisplayName called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "authorDisplayName called with event set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is<RoomMemberEvent>(*m_event) && !m_event->unsignedJson()[QStringLiteral("prev_content")][QStringLiteral("displayname")].isNull()
|
if (is<RoomMemberEvent>(*event) && !event->unsignedJson()[QStringLiteral("prev_content")][QStringLiteral("displayname")].isNull()
|
||||||
&& m_event->stateKey() == m_event->senderId()) {
|
&& event->stateKey() == event->senderId()) {
|
||||||
auto previousDisplayName = m_event->unsignedJson()[QStringLiteral("prev_content")][QStringLiteral("displayname")].toString().toHtmlEscaped();
|
auto previousDisplayName = event->unsignedJson()[QStringLiteral("prev_content")][QStringLiteral("displayname")].toString().toHtmlEscaped();
|
||||||
if (previousDisplayName.isEmpty()) {
|
if (previousDisplayName.isEmpty()) {
|
||||||
previousDisplayName = m_event->senderId();
|
previousDisplayName = event->senderId();
|
||||||
}
|
}
|
||||||
return previousDisplayName;
|
return previousDisplayName;
|
||||||
} else {
|
} else {
|
||||||
const auto author = isPending ? m_room->localMember() : m_room->member(m_event->senderId());
|
const auto author = isPending ? room->localMember() : room->member(event->senderId());
|
||||||
return author.htmlSafeDisplayName();
|
return author.htmlSafeDisplayName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::singleLineAuthorDisplayname(bool isPending) const
|
QString EventHandler::singleLineAuthorDisplayname(const NeoChatRoom *room, const Quotient::RoomEvent *event, bool isPending)
|
||||||
{
|
{
|
||||||
if (m_room == nullptr) {
|
if (room == nullptr) {
|
||||||
qCWarning(EventHandling) << "getAuthorDisplayName called with m_room set to nullptr.";
|
qCWarning(EventHandling) << "singleLineAuthorDisplayname called with room set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getAuthorDisplayName called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "singleLineAuthorDisplayname called with event set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto author = isPending ? m_room->localMember() : m_room->member(m_event->senderId());
|
const auto author = isPending ? room->localMember() : room->member(event->senderId());
|
||||||
auto displayName = author.displayName();
|
auto displayName = author.displayName();
|
||||||
displayName.replace(QStringLiteral("<br>\n"), QStringLiteral(" "));
|
displayName.replace(QStringLiteral("<br>\n"), QStringLiteral(" "));
|
||||||
displayName.replace(QStringLiteral("<br>"), QStringLiteral(" "));
|
displayName.replace(QStringLiteral("<br>"), QStringLiteral(" "));
|
||||||
@@ -105,10 +89,10 @@ QString EventHandler::singleLineAuthorDisplayname(bool isPending) const
|
|||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime EventHandler::getTime(bool isPending, QDateTime lastUpdated) const
|
QDateTime EventHandler::time(const Quotient::RoomEvent *event, bool isPending, QDateTime lastUpdated)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getTime called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "time called with event set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (isPending && lastUpdated == QDateTime()) {
|
if (isPending && lastUpdated == QDateTime()) {
|
||||||
@@ -116,24 +100,16 @@ QDateTime EventHandler::getTime(bool isPending, QDateTime lastUpdated) const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return isPending ? lastUpdated : m_event->originTimestamp();
|
return isPending ? lastUpdated : event->originTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getTimeString(bool relative, QLocale::FormatType format, bool isPending, QDateTime lastUpdated) const
|
QString EventHandler::timeString(const Quotient::RoomEvent *event, bool relative, QLocale::FormatType format, bool isPending, QDateTime lastUpdated)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
auto ts = time(event, isPending, lastUpdated);
|
||||||
qCWarning(EventHandling) << "getTimeString called with m_event set to nullptr.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
if (isPending && lastUpdated == QDateTime()) {
|
|
||||||
qCWarning(EventHandling) << "a value must be provided for lastUpdated for a pending event.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ts = getTime(isPending, lastUpdated);
|
|
||||||
if (ts.isValid()) {
|
if (ts.isValid()) {
|
||||||
if (relative) {
|
if (relative) {
|
||||||
return m_format.formatRelativeDate(ts.toLocalTime().date(), format);
|
KFormat formatter;
|
||||||
|
return formatter.formatRelativeDate(ts.toLocalTime().date(), format);
|
||||||
} else {
|
} else {
|
||||||
return QLocale().toString(ts.toLocalTime().time(), format);
|
return QLocale().toString(ts.toLocalTime().time(), format);
|
||||||
}
|
}
|
||||||
@@ -141,41 +117,41 @@ QString EventHandler::getTimeString(bool relative, QLocale::FormatType format, b
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getTimeString(const QString &format, bool isPending, const QDateTime &lastUpdated)
|
QString EventHandler::timeString(const Quotient::RoomEvent *event, const QString &format, bool isPending, const QDateTime &lastUpdated)
|
||||||
{
|
{
|
||||||
return getTime(isPending, lastUpdated).toLocalTime().toString(format);
|
return time(event, isPending, lastUpdated).toLocalTime().toString(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventHandler::isHighlighted()
|
bool EventHandler::isHighlighted(const NeoChatRoom *room, const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_room == nullptr) {
|
if (room == nullptr) {
|
||||||
qCWarning(EventHandling) << "isHighlighted called with m_room set to nullptr.";
|
qCWarning(EventHandling) << "isHighlighted called with room set to nullptr.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "isHighlighted called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "isHighlighted called with event set to nullptr.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !m_room->isDirectChat() && m_room->isEventHighlighted(m_event);
|
return !room->isDirectChat() && room->isEventHighlighted(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventHandler::isHidden()
|
bool EventHandler::isHidden(const NeoChatRoom *room, const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_room == nullptr) {
|
if (room == nullptr) {
|
||||||
qCWarning(EventHandling) << "isHidden called with m_room set to nullptr.";
|
qCWarning(EventHandling) << "isHidden called with room set to nullptr.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "isHidden called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "isHidden called with event set to nullptr.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_event->isStateEvent() && !NeoChatConfig::self()->showStateEvent()) {
|
if (event->isStateEvent() && !NeoChatConfig::self()->showStateEvent()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto roomMemberEvent = eventCast<const RoomMemberEvent>(m_event)) {
|
if (auto roomMemberEvent = eventCast<const RoomMemberEvent>(event)) {
|
||||||
if ((roomMemberEvent->isJoin() || roomMemberEvent->isLeave()) && !NeoChatConfig::self()->showLeaveJoinEvent()) {
|
if ((roomMemberEvent->isJoin() || roomMemberEvent->isLeave()) && !NeoChatConfig::self()->showLeaveJoinEvent()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (roomMemberEvent->isRename() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::self()->showRename()) {
|
} else if (roomMemberEvent->isRename() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::self()->showRename()) {
|
||||||
@@ -186,33 +162,33 @@ bool EventHandler::isHidden()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_event->isStateEvent() && eventCast<const StateEvent>(m_event)->repeatsState()) {
|
if (event->isStateEvent() && eventCast<const StateEvent>(event)->repeatsState()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// isReplacement?
|
// isReplacement?
|
||||||
if (auto e = eventCast<const RoomMessageEvent>(m_event)) {
|
if (auto e = eventCast<const RoomMessageEvent>(event)) {
|
||||||
if (!e->replacedEvent().isEmpty()) {
|
if (!e->replacedEvent().isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is<RedactionEvent>(*m_event) || is<ReactionEvent>(*m_event)) {
|
if (is<RedactionEvent>(*event) || is<ReactionEvent>(*event)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto e = eventCast<const RoomMessageEvent>(m_event)) {
|
if (auto e = eventCast<const RoomMessageEvent>(event)) {
|
||||||
if (!e->replacedEvent().isEmpty() && e->replacedEvent() != e->id()) {
|
if (!e->replacedEvent().isEmpty() && e->replacedEvent() != e->id()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_room->connection()->isIgnored(m_event->senderId())) {
|
if (room->connection()->isIgnored(event->senderId())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide ending live location beacons
|
// hide ending live location beacons
|
||||||
if (m_event->isStateEvent() && m_event->matrixType() == "org.matrix.msc3672.beacon_info"_ls && !m_event->contentJson()["live"_ls].toBool()) {
|
if (event->isStateEvent() && event->matrixType() == "org.matrix.msc3672.beacon_info"_ls && !event->contentJson()["live"_ls].toBool()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,44 +227,52 @@ QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event)
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getRichBody(bool stripNewlines) const
|
QString EventHandler::richBody(const NeoChatRoom *room, const Quotient::RoomEvent *event, bool stripNewlines)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (room == nullptr) {
|
||||||
qCWarning(EventHandling) << "getRichBody called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "richBody called with room set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return getBody(m_event, Qt::RichText, stripNewlines);
|
if (event == nullptr) {
|
||||||
|
qCWarning(EventHandling) << "richBody called with event set to nullptr.";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return getBody(room, event, Qt::RichText, stripNewlines);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getPlainBody(bool stripNewlines) const
|
QString EventHandler::plainBody(const NeoChatRoom *room, const Quotient::RoomEvent *event, bool stripNewlines)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (room == nullptr) {
|
||||||
qCWarning(EventHandling) << "getPlainBody called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "plainBody called with room set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return getBody(m_event, Qt::PlainText, stripNewlines);
|
if (event == nullptr) {
|
||||||
|
qCWarning(EventHandling) << "plainBody called with event set to nullptr.";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return getBody(room, event, Qt::PlainText, stripNewlines);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getMarkdownBody() const
|
QString EventHandler::markdownBody(const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getMarkdownBody called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "markdownBody called with event set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_event->is<RoomMessageEvent>()) {
|
if (!event->is<RoomMessageEvent>()) {
|
||||||
qCWarning(EventHandling) << "getMarkdownBody called when m_event isn't a RoomMessageEvent.";
|
qCWarning(EventHandling) << "markdownBody called when event isn't a RoomMessageEvent.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto roomMessageEvent = eventCast<const RoomMessageEvent>(m_event);
|
const auto roomMessageEvent = eventCast<const RoomMessageEvent>(event);
|
||||||
|
|
||||||
QString plainBody = roomMessageEvent->plainBody();
|
QString plainBody = roomMessageEvent->plainBody();
|
||||||
plainBody.remove(TextRegex::removeReply);
|
plainBody.remove(TextRegex::removeReply);
|
||||||
return plainBody;
|
return plainBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getBody(const Quotient::RoomEvent *event, Qt::TextFormat format, bool stripNewlines) const
|
QString EventHandler::getBody(const NeoChatRoom *room, const Quotient::RoomEvent *event, Qt::TextFormat format, bool stripNewlines)
|
||||||
{
|
{
|
||||||
if (event->isRedacted()) {
|
if (event->isRedacted()) {
|
||||||
auto reason = event->redactedBecause()->reason();
|
auto reason = event->redactedBecause()->reason();
|
||||||
@@ -299,15 +283,15 @@ QString EventHandler::getBody(const Quotient::RoomEvent *event, Qt::TextFormat f
|
|||||||
|
|
||||||
return switchOnType(
|
return switchOnType(
|
||||||
*event,
|
*event,
|
||||||
[this, format, stripNewlines](const RoomMessageEvent &event) {
|
[room, format, stripNewlines](const RoomMessageEvent &event) {
|
||||||
return getMessageBody(event, format, stripNewlines);
|
return getMessageBody(room, event, format, stripNewlines);
|
||||||
},
|
},
|
||||||
[](const StickerEvent &e) {
|
[](const StickerEvent &e) {
|
||||||
return e.body();
|
return e.body();
|
||||||
},
|
},
|
||||||
[this, prettyPrint](const RoomMemberEvent &e) {
|
[room, prettyPrint](const RoomMemberEvent &e) {
|
||||||
// FIXME: Rewind to the name that was at the time of this event
|
// FIXME: Rewind to the name that was at the time of this event
|
||||||
auto subjectName = m_room->member(e.userId()).htmlSafeDisplayName();
|
auto subjectName = room->member(e.userId()).htmlSafeDisplayName();
|
||||||
if (e.membership() == Membership::Leave) {
|
if (e.membership() == Membership::Leave) {
|
||||||
if (e.prevContent() && e.prevContent()->displayName) {
|
if (e.prevContent() && e.prevContent()->displayName) {
|
||||||
subjectName = sanitized(*e.prevContent()->displayName);
|
subjectName = sanitized(*e.prevContent()->displayName);
|
||||||
@@ -319,7 +303,7 @@ QString EventHandler::getBody(const Quotient::RoomEvent *event, Qt::TextFormat f
|
|||||||
|
|
||||||
if (prettyPrint) {
|
if (prettyPrint) {
|
||||||
subjectName = QStringLiteral("<a href=\"https://matrix.to/#/%1\" style=\"color: %2\">%3</a>")
|
subjectName = QStringLiteral("<a href=\"https://matrix.to/#/%1\" style=\"color: %2\">%3</a>")
|
||||||
.arg(e.userId(), m_room->member(e.userId()).color().name(), subjectName);
|
.arg(e.userId(), room->member(e.userId()).color().name(), subjectName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The below code assumes senderName output in AuthorRole
|
// The below code assumes senderName output in AuthorRole
|
||||||
@@ -455,7 +439,7 @@ QString EventHandler::getBody(const Quotient::RoomEvent *event, Qt::TextFormat f
|
|||||||
i18n("Unknown event"));
|
i18n("Unknown event"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getMessageBody(const RoomMessageEvent &event, Qt::TextFormat format, bool stripNewlines) const
|
QString EventHandler::getMessageBody(const NeoChatRoom *room, const RoomMessageEvent &event, Qt::TextFormat format, bool stripNewlines)
|
||||||
{
|
{
|
||||||
TextHandler textHandler;
|
TextHandler textHandler;
|
||||||
|
|
||||||
@@ -487,24 +471,24 @@ QString EventHandler::getMessageBody(const RoomMessageEvent &event, Qt::TextForm
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (format == Qt::RichText) {
|
if (format == Qt::RichText) {
|
||||||
return textHandler.handleRecieveRichText(inputFormat, m_room, &event, stripNewlines, event.isReplaced());
|
return textHandler.handleRecieveRichText(inputFormat, room, &event, stripNewlines, event.isReplaced());
|
||||||
} else {
|
} else {
|
||||||
return textHandler.handleRecievePlainText(inputFormat, stripNewlines);
|
return textHandler.handleRecievePlainText(inputFormat, stripNewlines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getGenericBody() const
|
QString EventHandler::genericBody(const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getGenericBody called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "genericBody called with event set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (m_event->isRedacted()) {
|
if (event->isRedacted()) {
|
||||||
return i18n("<i>[This message was deleted]</i>");
|
return i18n("<i>[This message was deleted]</i>");
|
||||||
}
|
}
|
||||||
|
|
||||||
return switchOnType(
|
return switchOnType(
|
||||||
*m_event,
|
*event,
|
||||||
[](const RoomMessageEvent &e) {
|
[](const RoomMessageEvent &e) {
|
||||||
Q_UNUSED(e)
|
Q_UNUSED(e)
|
||||||
return i18n("sent a message");
|
return i18n("sent a message");
|
||||||
@@ -624,29 +608,33 @@ QString EventHandler::getGenericBody() const
|
|||||||
i18n("Unknown event"));
|
i18n("Unknown event"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::subtitleText() const
|
QString EventHandler::subtitleText(const NeoChatRoom *room, const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (room == nullptr) {
|
||||||
qCWarning(EventHandling) << "subtitleText called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "subtitleText called with room set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return singleLineAuthorDisplayname() + (m_event->isStateEvent() ? QLatin1String(" ") : QLatin1String(": ")) + getPlainBody(true);
|
if (event == nullptr) {
|
||||||
|
qCWarning(EventHandling) << "subtitleText called with event set to nullptr.";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return singleLineAuthorDisplayname(room, event) + (event->isStateEvent() ? QLatin1String(" ") : QLatin1String(": ")) + plainBody(room, event, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap EventHandler::getMediaInfo() const
|
QVariantMap EventHandler::mediaInfo(const NeoChatRoom *room, const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_room == nullptr) {
|
if (room == nullptr) {
|
||||||
qCWarning(EventHandling) << "getMediaInfo called with m_room set to nullptr.";
|
qCWarning(EventHandling) << "mediaInfo called with room set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getMediaInfo called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "mediaInfo called with event set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return getMediaInfoForEvent(m_event);
|
return getMediaInfoForEvent(room, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap EventHandler::getMediaInfoForEvent(const Quotient::RoomEvent *event) const
|
QVariantMap EventHandler::getMediaInfoForEvent(const NeoChatRoom *room, const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
QString eventId = event->id();
|
QString eventId = event->id();
|
||||||
|
|
||||||
@@ -659,7 +647,7 @@ QVariantMap EventHandler::getMediaInfoForEvent(const Quotient::RoomEvent *event)
|
|||||||
|
|
||||||
const EventContent::FileInfo *fileInfo;
|
const EventContent::FileInfo *fileInfo;
|
||||||
fileInfo = roomMessageEvent->content()->fileInfo();
|
fileInfo = roomMessageEvent->content()->fileInfo();
|
||||||
QVariantMap mediaInfo = getMediaInfoFromFileInfo(fileInfo, eventId, false, false);
|
QVariantMap mediaInfo = getMediaInfoFromFileInfo(room, fileInfo, eventId, false, false);
|
||||||
// if filename isn't specifically given, it is in body
|
// if filename isn't specifically given, it is in body
|
||||||
// https://spec.matrix.org/latest/client-server-api/#mfile
|
// https://spec.matrix.org/latest/client-server-api/#mfile
|
||||||
mediaInfo["filename"_ls] = (fileInfo->originalName.isEmpty()) ? roomMessageEvent->plainBody() : fileInfo->originalName;
|
mediaInfo["filename"_ls] = (fileInfo->originalName.isEmpty()) ? roomMessageEvent->plainBody() : fileInfo->originalName;
|
||||||
@@ -671,13 +659,17 @@ QVariantMap EventHandler::getMediaInfoForEvent(const Quotient::RoomEvent *event)
|
|||||||
auto stickerEvent = eventCast<const StickerEvent>(event);
|
auto stickerEvent = eventCast<const StickerEvent>(event);
|
||||||
fileInfo = &stickerEvent->image();
|
fileInfo = &stickerEvent->image();
|
||||||
|
|
||||||
return getMediaInfoFromFileInfo(fileInfo, eventId, false, true);
|
return getMediaInfoFromFileInfo(room, fileInfo, eventId, false, true);
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap EventHandler::getMediaInfoFromFileInfo(const EventContent::FileInfo *fileInfo, const QString &eventId, bool isThumbnail, bool isSticker) const
|
QVariantMap EventHandler::getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
||||||
|
const EventContent::FileInfo *fileInfo,
|
||||||
|
const QString &eventId,
|
||||||
|
bool isThumbnail,
|
||||||
|
bool isSticker)
|
||||||
{
|
{
|
||||||
QVariantMap mediaInfo;
|
QVariantMap mediaInfo;
|
||||||
|
|
||||||
@@ -685,7 +677,7 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const EventContent::FileInfo
|
|||||||
if (!fileInfo->url().isValid() || fileInfo->url().scheme() != QStringLiteral("mxc") || eventId.isEmpty()) {
|
if (!fileInfo->url().isValid() || fileInfo->url().scheme() != QStringLiteral("mxc") || eventId.isEmpty()) {
|
||||||
mediaInfo["source"_ls] = QUrl();
|
mediaInfo["source"_ls] = QUrl();
|
||||||
} else {
|
} else {
|
||||||
QUrl source = m_room->makeMediaUrl(eventId, fileInfo->url());
|
QUrl source = room->makeMediaUrl(eventId, fileInfo->url());
|
||||||
|
|
||||||
if (source.isValid()) {
|
if (source.isValid()) {
|
||||||
mediaInfo["source"_ls] = source;
|
mediaInfo["source"_ls] = source;
|
||||||
@@ -717,7 +709,7 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const EventContent::FileInfo
|
|||||||
|
|
||||||
if (!isThumbnail) {
|
if (!isThumbnail) {
|
||||||
QVariantMap tempInfo;
|
QVariantMap tempInfo;
|
||||||
auto thumbnailInfo = getMediaInfoFromFileInfo(castInfo->thumbnailInfo(), eventId, true);
|
auto thumbnailInfo = getMediaInfoFromFileInfo(room, castInfo->thumbnailInfo(), eventId, true);
|
||||||
if (thumbnailInfo["source"_ls].toUrl().scheme() == "mxc"_ls) {
|
if (thumbnailInfo["source"_ls].toUrl().scheme() == "mxc"_ls) {
|
||||||
tempInfo = thumbnailInfo;
|
tempInfo = thumbnailInfo;
|
||||||
} else {
|
} else {
|
||||||
@@ -740,7 +732,7 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const EventContent::FileInfo
|
|||||||
|
|
||||||
if (!isThumbnail) {
|
if (!isThumbnail) {
|
||||||
QVariantMap tempInfo;
|
QVariantMap tempInfo;
|
||||||
auto thumbnailInfo = getMediaInfoFromFileInfo(castInfo->thumbnailInfo(), eventId, true);
|
auto thumbnailInfo = getMediaInfoFromFileInfo(room, castInfo->thumbnailInfo(), eventId, true);
|
||||||
if (thumbnailInfo["source"_ls].toUrl().scheme() == "mxc"_ls) {
|
if (thumbnailInfo["source"_ls].toUrl().scheme() == "mxc"_ls) {
|
||||||
tempInfo = thumbnailInfo;
|
tempInfo = thumbnailInfo;
|
||||||
} else {
|
} else {
|
||||||
@@ -764,14 +756,14 @@ QVariantMap EventHandler::getMediaInfoFromFileInfo(const EventContent::FileInfo
|
|||||||
return mediaInfo;
|
return mediaInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventHandler::hasReply(bool showFallbacks) const
|
bool EventHandler::hasReply(const Quotient::RoomEvent *event, bool showFallbacks)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "hasReply called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "hasReply called with event set to nullptr.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto relations = m_event->contentPart<QJsonObject>("m.relates_to"_ls);
|
const auto relations = event->contentPart<QJsonObject>("m.relates_to"_ls);
|
||||||
if (!relations.isEmpty()) {
|
if (!relations.isEmpty()) {
|
||||||
const bool hasReplyRelation = relations.contains("m.in_reply_to"_ls);
|
const bool hasReplyRelation = relations.contains("m.in_reply_to"_ls);
|
||||||
bool isFallingBack = relations["is_falling_back"_ls].toBool();
|
bool isFallingBack = relations["is_falling_back"_ls].toBool();
|
||||||
@@ -780,147 +772,73 @@ bool EventHandler::hasReply(bool showFallbacks) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getReplyId() const
|
QString EventHandler::replyId(const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getReplyId called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "replyId called with event set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return m_event->contentJson()["m.relates_to"_ls].toObject()["m.in_reply_to"_ls].toObject()["event_id"_ls].toString();
|
return event->contentJson()["m.relates_to"_ls].toObject()["m.in_reply_to"_ls].toObject()["event_id"_ls].toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageComponentType::Type EventHandler::replyMessageComponentType() const
|
Quotient::RoomMember EventHandler::replyAuthor(const NeoChatRoom *room, const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_room == nullptr) {
|
if (room == nullptr) {
|
||||||
qCWarning(EventHandling) << "replyMessageComponentType called with m_room set to nullptr.";
|
qCWarning(EventHandling) << "replyAuthor called with room set to nullptr.";
|
||||||
return MessageComponentType::Other;
|
|
||||||
}
|
|
||||||
if (m_event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "replyMessageComponentType called with m_event set to nullptr.";
|
|
||||||
return MessageComponentType::Other;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto replyEvent = m_room->getReplyForEvent(*m_event);
|
|
||||||
if (replyEvent == nullptr) {
|
|
||||||
return MessageComponentType::Other;
|
|
||||||
}
|
|
||||||
return MessageComponentType::typeForEvent(*replyEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
Quotient::RoomMember EventHandler::getReplyAuthor() const
|
|
||||||
{
|
|
||||||
if (m_room == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "getReplyAuthor called with m_room set to nullptr.";
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getReplyAuthor called with m_event set to nullptr. Returning empty user.";
|
qCWarning(EventHandling) << "replyAuthor called with event set to nullptr. Returning empty user.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto replyPtr = m_room->getReplyForEvent(*m_event)) {
|
if (auto replyPtr = room->getReplyForEvent(*event)) {
|
||||||
return m_room->member(replyPtr->senderId());
|
return room->member(replyPtr->senderId());
|
||||||
} else {
|
} else {
|
||||||
return m_room->member(QString());
|
return room->member(QString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getReplyRichBody(bool stripNewlines) const
|
bool EventHandler::isThreaded(const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_room == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getReplyRichBody called with m_room set to nullptr.";
|
qCWarning(EventHandling) << "isThreaded called with event set to nullptr.";
|
||||||
return {};
|
|
||||||
}
|
|
||||||
if (m_event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "getReplyRichBody called with m_event set to nullptr.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto replyEvent = m_room->getReplyForEvent(*m_event);
|
|
||||||
if (replyEvent == nullptr) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return getBody(replyEvent, Qt::RichText, stripNewlines);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString EventHandler::getReplyPlainBody(bool stripNewlines) const
|
|
||||||
{
|
|
||||||
if (m_room == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "getReplyPlainBody called with m_room set to nullptr.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
if (m_event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "getReplyPlainBody called with m_event set to nullptr.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto replyEvent = m_room->getReplyForEvent(*m_event);
|
|
||||||
if (replyEvent == nullptr) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return getBody(replyEvent, Qt::PlainText, stripNewlines);
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantMap EventHandler::getReplyMediaInfo() const
|
|
||||||
{
|
|
||||||
if (m_room == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "getReplyMediaInfo called with m_room set to nullptr.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
if (m_event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "getReplyMediaInfo called with m_event set to nullptr.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto replyPtr = m_room->getReplyForEvent(*m_event);
|
|
||||||
if (!replyPtr) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
return getMediaInfoForEvent(replyPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EventHandler::isThreaded() const
|
|
||||||
{
|
|
||||||
if (m_event == nullptr) {
|
|
||||||
qCWarning(EventHandling) << "isThreaded called with m_event set to nullptr.";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (m_event->contentPart<QJsonObject>("m.relates_to"_ls).contains("rel_type"_ls)
|
return (event->contentPart<QJsonObject>("m.relates_to"_ls).contains("rel_type"_ls)
|
||||||
&& m_event->contentPart<QJsonObject>("m.relates_to"_ls)["rel_type"_ls].toString() == "m.thread"_ls)
|
&& event->contentPart<QJsonObject>("m.relates_to"_ls)["rel_type"_ls].toString() == "m.thread"_ls)
|
||||||
|| (!m_event->unsignedPart<QJsonObject>("m.relations"_ls).isEmpty() && m_event->unsignedPart<QJsonObject>("m.relations"_ls).contains("m.thread"_ls));
|
|| (!event->unsignedPart<QJsonObject>("m.relations"_ls).isEmpty() && event->unsignedPart<QJsonObject>("m.relations"_ls).contains("m.thread"_ls));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::threadRoot() const
|
QString EventHandler::threadRoot(const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "threadRoot called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "threadRoot called with event set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the thread root ID from m.relates_to if it exists.
|
// Get the thread root ID from m.relates_to if it exists.
|
||||||
if (m_event->contentPart<QJsonObject>("m.relates_to"_ls).contains("rel_type"_ls)
|
if (event->contentPart<QJsonObject>("m.relates_to"_ls).contains("rel_type"_ls)
|
||||||
&& m_event->contentPart<QJsonObject>("m.relates_to"_ls)["rel_type"_ls].toString() == "m.thread"_ls) {
|
&& event->contentPart<QJsonObject>("m.relates_to"_ls)["rel_type"_ls].toString() == "m.thread"_ls) {
|
||||||
return m_event->contentPart<QJsonObject>("m.relates_to"_ls)["event_id"_ls].toString();
|
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.
|
// 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 so return the event ID as it is the root.
|
||||||
if (!m_event->unsignedPart<QJsonObject>("m.relations"_ls).isEmpty() && m_event->unsignedPart<QJsonObject>("m.relations"_ls).contains("m.thread"_ls)) {
|
if (!event->unsignedPart<QJsonObject>("m.relations"_ls).isEmpty() && event->unsignedPart<QJsonObject>("m.relations"_ls).contains("m.thread"_ls)) {
|
||||||
return getId();
|
return id(event);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
float EventHandler::getLatitude() const
|
float EventHandler::latitude(const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getLatitude called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "latitude called with event set to nullptr.";
|
||||||
return -100.0;
|
return -100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto geoUri = m_event->contentJson()["geo_uri"_ls].toString();
|
const auto geoUri = event->contentJson()["geo_uri"_ls].toString();
|
||||||
if (geoUri.isEmpty()) {
|
if (geoUri.isEmpty()) {
|
||||||
return -100.0; // latitude runs from -90deg to +90deg so -100 is out of range.
|
return -100.0; // latitude runs from -90deg to +90deg so -100 is out of range.
|
||||||
}
|
}
|
||||||
@@ -928,14 +846,14 @@ float EventHandler::getLatitude() const
|
|||||||
return latitude.toFloat();
|
return latitude.toFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
float EventHandler::getLongitude() const
|
float EventHandler::longitude(const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getLongitude called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "longitude called with event set to nullptr.";
|
||||||
return -200.0;
|
return -200.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto geoUri = m_event->contentJson()["geo_uri"_ls].toString();
|
const auto geoUri = event->contentJson()["geo_uri"_ls].toString();
|
||||||
if (geoUri.isEmpty()) {
|
if (geoUri.isEmpty()) {
|
||||||
return -200.0; // longitude runs from -180deg to +180deg so -200 is out of range.
|
return -200.0; // longitude runs from -180deg to +180deg so -200 is out of range.
|
||||||
}
|
}
|
||||||
@@ -943,14 +861,14 @@ float EventHandler::getLongitude() const
|
|||||||
return latitude.toFloat();
|
return latitude.toFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventHandler::getLocationAssetType() const
|
QString EventHandler::locationAssetType(const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (m_event == nullptr) {
|
if (event == nullptr) {
|
||||||
qCWarning(EventHandling) << "getLocationAssetType called with m_event set to nullptr.";
|
qCWarning(EventHandling) << "locationAssetType called with event set to nullptr.";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto assetType = m_event->contentJson()["org.matrix.msc3488.asset"_ls].toObject()["type"_ls].toString();
|
const auto assetType = event->contentJson()["org.matrix.msc3488.asset"_ls].toObject()["type"_ls].toString();
|
||||||
if (assetType.isEmpty()) {
|
if (assetType.isEmpty()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,24 +3,22 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QDateTime>
|
||||||
|
#include <QString>
|
||||||
#include <KFormat>
|
#include <Quotient/events/eventcontent.h>
|
||||||
|
|
||||||
#include <Quotient/eventitem.h>
|
|
||||||
#include <Quotient/events/roomevent.h>
|
|
||||||
#include <Quotient/events/roommessageevent.h>
|
|
||||||
|
|
||||||
#include "enums/messagecomponenttype.h"
|
|
||||||
|
|
||||||
namespace Quotient
|
namespace Quotient
|
||||||
{
|
{
|
||||||
|
namespace EventContent
|
||||||
|
{
|
||||||
|
class FileInfo;
|
||||||
|
}
|
||||||
|
class RoomEvent;
|
||||||
class RoomMember;
|
class RoomMember;
|
||||||
|
class RoomMessageEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LinkPreviewer;
|
|
||||||
class NeoChatRoom;
|
class NeoChatRoom;
|
||||||
class ReactionModel;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class EventHandler
|
* @class EventHandler
|
||||||
@@ -38,20 +36,14 @@ class ReactionModel;
|
|||||||
*/
|
*/
|
||||||
class EventHandler
|
class EventHandler
|
||||||
{
|
{
|
||||||
Q_GADGET
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EventHandler(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the Matrix ID of the event.
|
* @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.
|
||||||
*/
|
*/
|
||||||
QString getId() const;
|
static QString id(const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The MessageComponentType to use to visualise the main event content.
|
|
||||||
*/
|
|
||||||
MessageComponentType::Type messageComponentType() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the display name of the event author.
|
* @brief Get the display name of the event author.
|
||||||
@@ -64,7 +56,7 @@ public:
|
|||||||
* @param isPending whether the event is pending as this cannot be derived from
|
* @param isPending whether the event is pending as this cannot be derived from
|
||||||
* just the event object.
|
* just the event object.
|
||||||
*/
|
*/
|
||||||
QString getAuthorDisplayName(bool isPending = false) const;
|
static QString authorDisplayName(const NeoChatRoom *room, const Quotient::RoomEvent *event, bool isPending = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the display name of the event author but with any newlines removed.
|
* @brief Get the display name of the event author but with any newlines removed.
|
||||||
@@ -75,12 +67,12 @@ public:
|
|||||||
* @param isPending whether the event is pending as this cannot be derived from
|
* @param isPending whether the event is pending as this cannot be derived from
|
||||||
* just the event object.
|
* just the event object.
|
||||||
*/
|
*/
|
||||||
QString singleLineAuthorDisplayname(bool isPending = false) const;
|
static QString singleLineAuthorDisplayname(const NeoChatRoom *room, const Quotient::RoomEvent *event, bool isPending = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return a QDateTime object for the event timestamp.
|
* @brief Return a QDateTime object for the event timestamp.
|
||||||
*/
|
*/
|
||||||
QDateTime getTime(bool isPending = false, QDateTime lastUpdated = {}) const;
|
static QDateTime time(const Quotient::RoomEvent *event, bool isPending = false, QDateTime lastUpdated = {});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return a QString for the event timestamp.
|
* @brief Return a QString for the event timestamp.
|
||||||
@@ -96,16 +88,32 @@ public:
|
|||||||
* @param lastUpdated the time the event was last updated locally as this cannot be
|
* @param lastUpdated the time the event was last updated locally as this cannot be
|
||||||
* obtained from the event.
|
* obtained from the event.
|
||||||
*/
|
*/
|
||||||
QString getTimeString(bool relative, QLocale::FormatType format = QLocale::ShortFormat, bool isPending = false, QDateTime lastUpdated = {}) const;
|
static QString timeString(const Quotient::RoomEvent *event,
|
||||||
|
bool relative,
|
||||||
|
QLocale::FormatType format = QLocale::ShortFormat,
|
||||||
|
bool isPending = false,
|
||||||
|
QDateTime lastUpdated = {});
|
||||||
|
|
||||||
QString getTimeString(const QString &format, bool isPending = false, const QDateTime &lastUpdated = {});
|
/**
|
||||||
|
* @brief Return a QString for the event timestamp.
|
||||||
|
*
|
||||||
|
* This is intended to return a string that is read for display in the UI without
|
||||||
|
* any further manipulation required.
|
||||||
|
*
|
||||||
|
* @param format the format to use as a string.
|
||||||
|
* @param isPending whether the event is pending as this cannot be derived from
|
||||||
|
* just the event object.
|
||||||
|
* @param lastUpdated the time the event was last updated locally as this cannot be
|
||||||
|
* obtained from the event.
|
||||||
|
*/
|
||||||
|
static QString timeString(const Quotient::RoomEvent *event, const QString &format, bool isPending = false, const QDateTime &lastUpdated = {});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Whether the event should be highlighted in the timeline.
|
* @brief Whether the event should be highlighted in the timeline.
|
||||||
*
|
*
|
||||||
* @note Messages in direct chats are never highlighted.
|
* @note Messages in direct chats are never highlighted.
|
||||||
*/
|
*/
|
||||||
bool isHighlighted();
|
static bool isHighlighted(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Whether the event should be hidden in the timeline.
|
* @brief Whether the event should be hidden in the timeline.
|
||||||
@@ -114,7 +122,7 @@ public:
|
|||||||
* user has hidden all state events or if the sender has been ignored by the local
|
* user has hidden all state events or if the sender has been ignored by the local
|
||||||
* user.
|
* user.
|
||||||
*/
|
*/
|
||||||
bool isHidden();
|
static bool isHidden(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The input format of the body in the message.
|
* @brief The input format of the body in the message.
|
||||||
@@ -146,7 +154,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param stripNewlines whether the output should have new lines in it.
|
* @param stripNewlines whether the output should have new lines in it.
|
||||||
*/
|
*/
|
||||||
QString getRichBody(bool stripNewlines = false) const;
|
static QString richBody(const NeoChatRoom *room, const Quotient::RoomEvent *event, bool stripNewlines = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Output a string for the message content ready for display in a plain text field.
|
* @brief Output a string for the message content ready for display in a plain text field.
|
||||||
@@ -162,14 +170,14 @@ public:
|
|||||||
*
|
*
|
||||||
* @param stripNewlines whether the output should have new lines in it.
|
* @param stripNewlines whether the output should have new lines in it.
|
||||||
*/
|
*/
|
||||||
QString getPlainBody(bool stripNewlines = false) const;
|
static QString plainBody(const NeoChatRoom *room, const Quotient::RoomEvent *event, bool stripNewlines = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Output the original body for the message content, useful for editing the original message.
|
* @brief Output the original body for the message content, useful for editing the original message.
|
||||||
*
|
*
|
||||||
* The event type must be a room message event.
|
* The event type must be a room message event.
|
||||||
*/
|
*/
|
||||||
QString getMarkdownBody() const;
|
static QString markdownBody(const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Output a generic string for the message content ready for display.
|
* @brief Output a generic string for the message content ready for display.
|
||||||
@@ -182,9 +190,9 @@ public:
|
|||||||
* E.g. For a message the text will be:
|
* E.g. For a message the text will be:
|
||||||
* "sent a message"
|
* "sent a message"
|
||||||
*
|
*
|
||||||
* @sa getRichBody(), getPlainBody()
|
* @sa richBody(), plainBody()
|
||||||
*/
|
*/
|
||||||
QString getGenericBody() const;
|
static QString genericBody(const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Output a string for the event to be used as a RoomList subtitle.
|
* @brief Output a string for the event to be used as a RoomList subtitle.
|
||||||
@@ -192,7 +200,7 @@ public:
|
|||||||
* The output includes the username followed by the plain message, all with no
|
* The output includes the username followed by the plain message, all with no
|
||||||
* line breaks.
|
* line breaks.
|
||||||
*/
|
*/
|
||||||
QString subtitleText() const;
|
static QString subtitleText(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the media info for the event.
|
* @brief Return the media info for the event.
|
||||||
@@ -210,7 +218,7 @@ public:
|
|||||||
* - tempInfo - mediaInfo (with the same properties as this except no tempInfo) for a temporary image while the file downloads.
|
* - tempInfo - mediaInfo (with the same properties as this except no tempInfo) for a temporary image while the file downloads.
|
||||||
* - isSticker - Whether the image is a sticker or not
|
* - isSticker - Whether the image is a sticker or not
|
||||||
*/
|
*/
|
||||||
QVariantMap getMediaInfo() const;
|
static QVariantMap mediaInfo(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Whether the event is a reply to another in the timeline.
|
* @brief Whether the event is a reply to another in the timeline.
|
||||||
@@ -219,17 +227,12 @@ public:
|
|||||||
* show the fallback reply. Leave true for non-threaded
|
* show the fallback reply. Leave true for non-threaded
|
||||||
* timelines.
|
* timelines.
|
||||||
*/
|
*/
|
||||||
bool hasReply(bool showFallbacks = true) const;
|
static bool hasReply(const Quotient::RoomEvent *event, bool showFallbacks = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the Matrix ID of the event replied to.
|
* @brief Return the Matrix ID of the event replied to.
|
||||||
*/
|
*/
|
||||||
QString getReplyId() const;
|
static QString replyId(const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The MessageComponentType to use to visualise the reply content.
|
|
||||||
*/
|
|
||||||
MessageComponentType::Type replyMessageComponentType() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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.
|
||||||
@@ -244,73 +247,21 @@ public:
|
|||||||
*
|
*
|
||||||
* @sa Quotient::RoomMember
|
* @sa Quotient::RoomMember
|
||||||
*/
|
*/
|
||||||
Quotient::RoomMember getReplyAuthor() const;
|
static Quotient::RoomMember replyAuthor(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Output a string for the message content of the event replied to ready
|
|
||||||
* for display in a rich text field.
|
|
||||||
*
|
|
||||||
* The output string is dependant upon the event type and the desired output format.
|
|
||||||
*
|
|
||||||
* For most messages this is the body content of the message. For media messages
|
|
||||||
* this will be the caption and for state events it will be a string specific
|
|
||||||
* to that event with some dynamic details about the event added.
|
|
||||||
*
|
|
||||||
* E.g. For a room topic state event the text will be:
|
|
||||||
* "set the topic to: <new topic text>"
|
|
||||||
*
|
|
||||||
* @param stripNewlines whether the output should have new lines in it.
|
|
||||||
*/
|
|
||||||
QString getReplyRichBody(bool stripNewlines = false) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Output a string for the message content of the event replied to ready
|
|
||||||
* for display in a plain text field.
|
|
||||||
*
|
|
||||||
* The output string is dependant upon the event type and the desired output format.
|
|
||||||
*
|
|
||||||
* For most messages this is the body content of the message. For media messages
|
|
||||||
* this will be the caption and for state events it will be a string specific
|
|
||||||
* to that event with some dynamic details about the event added.
|
|
||||||
*
|
|
||||||
* E.g. For a room topic state event the text will be:
|
|
||||||
* "set the topic to: <new topic text>"
|
|
||||||
*
|
|
||||||
* @param stripNewlines whether the output should have new lines in it.
|
|
||||||
*/
|
|
||||||
QString getReplyPlainBody(bool stripNewlines = false) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the media info for the event replied to.
|
|
||||||
*
|
|
||||||
* An empty QVariantMap will be returned for any event that doesn't have any
|
|
||||||
* media info.
|
|
||||||
*
|
|
||||||
* @return This should consist of the following:
|
|
||||||
* - source - The mxc URL for the media.
|
|
||||||
* - mimeType - The MIME type of the media (should be image/xxx for this delegate).
|
|
||||||
* - mimeIcon - The MIME icon name (should be image-xxx).
|
|
||||||
* - size - The file size in bytes.
|
|
||||||
* - width - The width in pixels of the audio media.
|
|
||||||
* - height - The height in pixels of the audio media.
|
|
||||||
* - tempInfo - mediaInfo (with the same properties as this except no tempInfo) for a temporary image while the file downloads.
|
|
||||||
* - isSticker - Whether the image is a sticker or not
|
|
||||||
*/
|
|
||||||
QVariantMap getReplyMediaInfo() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Whether the message is part of a thread.
|
* @brief Whether the message is part of a thread.
|
||||||
*
|
*
|
||||||
* i.e. There is a rel_type of m.thread.
|
* i.e. There is a rel_type of m.thread.
|
||||||
*/
|
*/
|
||||||
bool isThreaded() const;
|
static bool isThreaded(const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the Matrix ID of the thread's root message.
|
* @brief Return the Matrix ID of the thread's root message.
|
||||||
*
|
*
|
||||||
* Empty if this not part of a thread.
|
* Empty if this not part of a thread.
|
||||||
*/
|
*/
|
||||||
QString threadRoot() const;
|
static QString threadRoot(const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the latitude for the event.
|
* @brief Return the latitude for the event.
|
||||||
@@ -318,7 +269,7 @@ public:
|
|||||||
* Returns -100.0 if the event doesn't have a location (latitudes are in the
|
* Returns -100.0 if the event doesn't have a location (latitudes are in the
|
||||||
* range -90deg to +90deg so -100 is out of range).
|
* range -90deg to +90deg so -100 is out of range).
|
||||||
*/
|
*/
|
||||||
float getLatitude() const;
|
static float latitude(const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the longitude for the event.
|
* @brief Return the longitude for the event.
|
||||||
@@ -326,23 +277,21 @@ public:
|
|||||||
* Returns -200.0 if the event doesn't have a location (latitudes are in the
|
* Returns -200.0 if the event doesn't have a location (latitudes are in the
|
||||||
* range -180deg to +180deg so -200 is out of range).
|
* range -180deg to +180deg so -200 is out of range).
|
||||||
*/
|
*/
|
||||||
float getLongitude() const;
|
static float longitude(const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the type of location marker for the event.
|
* @brief Return the type of location marker for the event.
|
||||||
*/
|
*/
|
||||||
QString getLocationAssetType() const;
|
static QString locationAssetType(const Quotient::RoomEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const NeoChatRoom *m_room = nullptr;
|
static QString getBody(const NeoChatRoom *room, const Quotient::RoomEvent *event, Qt::TextFormat format, bool stripNewlines);
|
||||||
const Quotient::RoomEvent *m_event = nullptr;
|
static QString getMessageBody(const NeoChatRoom *room, const Quotient::RoomMessageEvent &event, Qt::TextFormat format, bool stripNewlines);
|
||||||
|
|
||||||
KFormat m_format;
|
static QVariantMap getMediaInfoForEvent(const NeoChatRoom *room, const Quotient::RoomEvent *event);
|
||||||
|
QVariantMap static getMediaInfoFromFileInfo(const NeoChatRoom *room,
|
||||||
QString getBody(const Quotient::RoomEvent *event, Qt::TextFormat format, bool stripNewlines) const;
|
const Quotient::EventContent::FileInfo *fileInfo,
|
||||||
QString getMessageBody(const Quotient::RoomMessageEvent &event, Qt::TextFormat format, bool stripNewlines) const;
|
const QString &eventId,
|
||||||
|
bool isThumbnail = false,
|
||||||
QVariantMap getMediaInfoForEvent(const Quotient::RoomEvent *event) const;
|
bool isSticker = false);
|
||||||
QVariantMap
|
|
||||||
getMediaInfoFromFileInfo(const Quotient::EventContent::FileInfo *fileInfo, const QString &eventId, bool isThumbnail = false, bool isSticker = false) const;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||||
|
|
||||||
#include "messagecontentmodel.h"
|
#include "messagecontentmodel.h"
|
||||||
|
#include "eventhandler.h"
|
||||||
#include "neochatconfig.h"
|
#include "neochatconfig.h"
|
||||||
|
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
@@ -228,7 +229,6 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
EventHandler eventHandler(m_room, m_event.get());
|
|
||||||
const auto component = m_components[index.row()];
|
const auto component = m_components[index.row()];
|
||||||
|
|
||||||
if (role == DisplayRole) {
|
if (role == DisplayRole) {
|
||||||
@@ -246,7 +246,7 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
|||||||
if (!component.content.isEmpty()) {
|
if (!component.content.isEmpty()) {
|
||||||
return component.content;
|
return component.content;
|
||||||
}
|
}
|
||||||
return eventHandler.getRichBody();
|
return EventHandler::richBody(m_room, m_event.get());
|
||||||
}
|
}
|
||||||
if (role == ComponentTypeRole) {
|
if (role == ComponentTypeRole) {
|
||||||
return component.type;
|
return component.type;
|
||||||
@@ -255,7 +255,7 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
|||||||
return component.attributes;
|
return component.attributes;
|
||||||
}
|
}
|
||||||
if (role == EventIdRole) {
|
if (role == EventIdRole) {
|
||||||
return eventHandler.getId();
|
return EventHandler::id(m_event.get());
|
||||||
}
|
}
|
||||||
if (role == TimeRole) {
|
if (role == TimeRole) {
|
||||||
const auto pendingIt = std::find_if(m_room->pendingEvents().cbegin(), m_room->pendingEvents().cend(), [this](const PendingEventItem &pendingEvent) {
|
const auto pendingIt = std::find_if(m_room->pendingEvents().cbegin(), m_room->pendingEvents().cend(), [this](const PendingEventItem &pendingEvent) {
|
||||||
@@ -263,7 +263,7 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto lastUpdated = pendingIt == m_room->pendingEvents().cend() ? QDateTime() : pendingIt->lastUpdated();
|
auto lastUpdated = pendingIt == m_room->pendingEvents().cend() ? QDateTime() : pendingIt->lastUpdated();
|
||||||
return eventHandler.getTime(m_isPending, lastUpdated);
|
return EventHandler::time(m_event.get(), m_isPending, lastUpdated);
|
||||||
}
|
}
|
||||||
if (role == TimeStringRole) {
|
if (role == TimeStringRole) {
|
||||||
const auto pendingIt = std::find_if(m_room->pendingEvents().cbegin(), m_room->pendingEvents().cend(), [this](const PendingEventItem &pendingEvent) {
|
const auto pendingIt = std::find_if(m_room->pendingEvents().cbegin(), m_room->pendingEvents().cend(), [this](const PendingEventItem &pendingEvent) {
|
||||||
@@ -271,13 +271,13 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto lastUpdated = pendingIt == m_room->pendingEvents().cend() ? QDateTime() : pendingIt->lastUpdated();
|
auto lastUpdated = pendingIt == m_room->pendingEvents().cend() ? QDateTime() : pendingIt->lastUpdated();
|
||||||
return eventHandler.getTimeString(QStringLiteral("hh:mm"), m_isPending, lastUpdated);
|
return EventHandler::timeString(m_event.get(), QStringLiteral("hh:mm"), m_isPending, lastUpdated);
|
||||||
}
|
}
|
||||||
if (role == AuthorRole) {
|
if (role == AuthorRole) {
|
||||||
return QVariant::fromValue<NeochatRoomMember *>(m_eventSenderObject.get());
|
return QVariant::fromValue<NeochatRoomMember *>(m_eventSenderObject.get());
|
||||||
}
|
}
|
||||||
if (role == MediaInfoRole) {
|
if (role == MediaInfoRole) {
|
||||||
return eventHandler.getMediaInfo();
|
return EventHandler::mediaInfo(m_room, m_event.get());
|
||||||
}
|
}
|
||||||
if (role == FileTransferInfoRole) {
|
if (role == FileTransferInfoRole) {
|
||||||
return QVariant::fromValue(m_room->cachedFileTransferInfo(m_event.get()));
|
return QVariant::fromValue(m_room->cachedFileTransferInfo(m_event.get()));
|
||||||
@@ -286,25 +286,22 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant::fromValue<ItineraryModel *>(m_itineraryModel);
|
return QVariant::fromValue<ItineraryModel *>(m_itineraryModel);
|
||||||
}
|
}
|
||||||
if (role == LatitudeRole) {
|
if (role == LatitudeRole) {
|
||||||
return eventHandler.getLatitude();
|
return EventHandler::latitude(m_event.get());
|
||||||
}
|
}
|
||||||
if (role == LongitudeRole) {
|
if (role == LongitudeRole) {
|
||||||
return eventHandler.getLongitude();
|
return EventHandler::longitude(m_event.get());
|
||||||
}
|
}
|
||||||
if (role == AssetRole) {
|
if (role == AssetRole) {
|
||||||
return eventHandler.getLocationAssetType();
|
return EventHandler::locationAssetType(m_event.get());
|
||||||
}
|
}
|
||||||
if (role == PollHandlerRole) {
|
if (role == PollHandlerRole) {
|
||||||
return QVariant::fromValue<PollHandler *>(m_room->poll(m_eventId));
|
return QVariant::fromValue<PollHandler *>(m_room->poll(m_eventId));
|
||||||
}
|
}
|
||||||
if (role == IsReplyRole) {
|
|
||||||
return eventHandler.hasReply();
|
|
||||||
}
|
|
||||||
if (role == ReplyEventIdRole) {
|
if (role == ReplyEventIdRole) {
|
||||||
return eventHandler.getReplyId();
|
return EventHandler::replyId(m_event.get());
|
||||||
}
|
}
|
||||||
if (role == ReplyAuthorRole) {
|
if (role == ReplyAuthorRole) {
|
||||||
return QVariant::fromValue(eventHandler.getReplyAuthor());
|
return QVariant::fromValue(EventHandler::replyAuthor(m_room, m_event.get()));
|
||||||
}
|
}
|
||||||
if (role == ReplyContentModelRole) {
|
if (role == ReplyContentModelRole) {
|
||||||
return QVariant::fromValue<MessageContentModel *>(m_replyModel);
|
return QVariant::fromValue<MessageContentModel *>(m_replyModel);
|
||||||
@@ -344,7 +341,6 @@ QHash<int, QByteArray> MessageContentModel::roleNames() const
|
|||||||
roles[LongitudeRole] = "longitude";
|
roles[LongitudeRole] = "longitude";
|
||||||
roles[AssetRole] = "asset";
|
roles[AssetRole] = "asset";
|
||||||
roles[PollHandlerRole] = "pollHandler";
|
roles[PollHandlerRole] = "pollHandler";
|
||||||
roles[IsReplyRole] = "isReply";
|
|
||||||
roles[ReplyEventIdRole] = "replyEventId";
|
roles[ReplyEventIdRole] = "replyEventId";
|
||||||
roles[ReplyAuthorRole] = "replyAuthor";
|
roles[ReplyAuthorRole] = "replyAuthor";
|
||||||
roles[ReplyContentModelRole] = "replyContentModel";
|
roles[ReplyContentModelRole] = "replyContentModel";
|
||||||
@@ -411,8 +407,7 @@ QList<MessageComponent> MessageContentModel::messageContentComponents(bool isEdi
|
|||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
newComponents += MessageComponent{MessageComponentType::Edit, QString(), {}};
|
newComponents += MessageComponent{MessageComponentType::Edit, QString(), {}};
|
||||||
} else {
|
} else {
|
||||||
EventHandler eventHandler(m_room, m_event.get());
|
newComponents.append(componentsForType(MessageComponentType::typeForEvent(*m_event.get())));
|
||||||
newComponents.append(componentsForType(eventHandler.messageComponentType()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_room->urlPreviewEnabled()) {
|
if (m_room->urlPreviewEnabled()) {
|
||||||
@@ -428,8 +423,7 @@ void MessageContentModel::updateReplyModel()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventHandler eventHandler(m_room, m_event.get());
|
if (!EventHandler::hasReply(m_event.get()) || (EventHandler::isThreaded(m_event.get()) && NeoChatConfig::self()->threads())) {
|
||||||
if (!eventHandler.hasReply() || (eventHandler.isThreaded() && NeoChatConfig::self()->threads())) {
|
|
||||||
if (m_replyModel) {
|
if (m_replyModel) {
|
||||||
delete m_replyModel;
|
delete m_replyModel;
|
||||||
}
|
}
|
||||||
@@ -440,9 +434,9 @@ void MessageContentModel::updateReplyModel()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto replyEvent = m_room->findInTimeline(eventHandler.getReplyId());
|
const auto replyEvent = m_room->findInTimeline(EventHandler::replyId(m_event.get()));
|
||||||
if (replyEvent == m_room->historyEdge()) {
|
if (replyEvent == m_room->historyEdge()) {
|
||||||
m_replyModel = new MessageContentModel(m_room, eventHandler.getReplyId(), true, false, this);
|
m_replyModel = new MessageContentModel(m_room, EventHandler::replyId(m_event.get()), true, false, this);
|
||||||
} else {
|
} else {
|
||||||
m_replyModel = new MessageContentModel(m_room, replyEvent->get(), true, false, this);
|
m_replyModel = new MessageContentModel(m_room, replyEvent->get(), true, false, this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#include <Quotient/room.h>
|
#include <Quotient/room.h>
|
||||||
|
|
||||||
#include "enums/messagecomponenttype.h"
|
#include "enums/messagecomponenttype.h"
|
||||||
#include "eventhandler.h"
|
|
||||||
#include "itinerarymodel.h"
|
#include "itinerarymodel.h"
|
||||||
#include "neochatroommember.h"
|
#include "neochatroommember.h"
|
||||||
|
|
||||||
@@ -66,7 +65,6 @@ public:
|
|||||||
AssetRole, /**< Type of location event, e.g. self pin of the user location. */
|
AssetRole, /**< Type of location event, e.g. self pin of the user location. */
|
||||||
PollHandlerRole, /**< The PollHandler for the event, if any. */
|
PollHandlerRole, /**< The PollHandler for the event, if any. */
|
||||||
|
|
||||||
IsReplyRole, /**< Is the message a reply to another event. */
|
|
||||||
ReplyEventIdRole, /**< The matrix ID of the message that was replied to. */
|
ReplyEventIdRole, /**< The matrix ID of the message that was replied to. */
|
||||||
ReplyAuthorRole, /**< The author of the event that was replied to. */
|
ReplyAuthorRole, /**< The author of the event that was replied to. */
|
||||||
ReplyContentModelRole, /**< The MessageContentModel for the reply event. */
|
ReplyContentModelRole, /**< The MessageContentModel for the reply event. */
|
||||||
|
|||||||
@@ -432,15 +432,13 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
const auto pendingIt = m_currentRoom->pendingEvents().crbegin() + std::min(row, timelineBaseIndex());
|
const auto pendingIt = m_currentRoom->pendingEvents().crbegin() + std::min(row, timelineBaseIndex());
|
||||||
const auto &evt = isPending ? **pendingIt : **timelineIt;
|
const auto &evt = isPending ? **pendingIt : **timelineIt;
|
||||||
|
|
||||||
EventHandler eventHandler(m_currentRoom, &evt);
|
|
||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
if (evt.isRedacted()) {
|
if (evt.isRedacted()) {
|
||||||
auto reason = evt.redactedBecause()->reason();
|
auto reason = evt.redactedBecause()->reason();
|
||||||
return (reason.isEmpty()) ? i18n("<i>[This message was deleted]</i>")
|
return (reason.isEmpty()) ? i18n("<i>[This message was deleted]</i>")
|
||||||
: i18n("<i>[This message was deleted: %1]</i>", evt.redactedBecause()->reason());
|
: i18n("<i>[This message was deleted: %1]</i>", evt.redactedBecause()->reason());
|
||||||
}
|
}
|
||||||
return eventHandler.getRichBody();
|
return EventHandler::richBody(m_currentRoom, &evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == ContentModelRole) {
|
if (role == ContentModelRole) {
|
||||||
@@ -457,7 +455,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (role == GenericDisplayRole) {
|
if (role == GenericDisplayRole) {
|
||||||
return eventHandler.getGenericBody();
|
return EventHandler::genericBody(&evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == DelegateTypeRole) {
|
if (role == DelegateTypeRole) {
|
||||||
@@ -480,7 +478,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (role == HighlightRole) {
|
if (role == HighlightRole) {
|
||||||
return eventHandler.isHighlighted();
|
return EventHandler::isHighlighted(m_currentRoom, &evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == SpecialMarksRole) {
|
if (role == SpecialMarksRole) {
|
||||||
@@ -493,11 +491,11 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
return pendingIt->deliveryStatus();
|
return pendingIt->deliveryStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventHandler.isHidden()) {
|
if (EventHandler::isHidden(m_currentRoom, &evt)) {
|
||||||
return EventStatus::Hidden;
|
return EventStatus::Hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventHandler.isThreaded() && eventHandler.threadRoot() != eventHandler.getId() && NeoChatConfig::threads()) {
|
if (EventHandler::isThreaded(&evt) && EventHandler::threadRoot(&evt) != EventHandler::id(&evt) && NeoChatConfig::threads()) {
|
||||||
return EventStatus::Hidden;
|
return EventStatus::Hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,7 +503,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (role == EventIdRole) {
|
if (role == EventIdRole) {
|
||||||
return eventHandler.getId();
|
return EventHandler::id(&evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == ProgressInfoRole) {
|
if (role == ProgressInfoRole) {
|
||||||
@@ -521,20 +519,20 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
|
|
||||||
if (role == TimeRole) {
|
if (role == TimeRole) {
|
||||||
auto lastUpdated = isPending ? pendingIt->lastUpdated() : QDateTime();
|
auto lastUpdated = isPending ? pendingIt->lastUpdated() : QDateTime();
|
||||||
return eventHandler.getTime(isPending, lastUpdated);
|
return EventHandler::time(&evt, isPending, lastUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == SectionRole) {
|
if (role == SectionRole) {
|
||||||
auto lastUpdated = isPending ? pendingIt->lastUpdated() : QDateTime();
|
auto lastUpdated = isPending ? pendingIt->lastUpdated() : QDateTime();
|
||||||
return eventHandler.getTimeString(true, QLocale::ShortFormat, isPending, lastUpdated);
|
return EventHandler::timeString(&evt, true, QLocale::ShortFormat, isPending, lastUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == IsThreadedRole) {
|
if (role == IsThreadedRole) {
|
||||||
return eventHandler.isThreaded();
|
return EventHandler::isThreaded(&evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == ThreadRootRole) {
|
if (role == ThreadRootRole) {
|
||||||
return eventHandler.threadRoot();
|
return EventHandler::threadRoot(&evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == ShowSectionRole) {
|
if (role == ShowSectionRole) {
|
||||||
@@ -587,7 +585,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (role == AuthorDisplayNameRole) {
|
if (role == AuthorDisplayNameRole) {
|
||||||
return eventHandler.getAuthorDisplayName(isPending);
|
return EventHandler::authorDisplayName(m_currentRoom, &evt, isPending);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == IsRedactedRole) {
|
if (role == IsRedactedRole) {
|
||||||
@@ -599,11 +597,11 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (role == MediaInfoRole) {
|
if (role == MediaInfoRole) {
|
||||||
return eventHandler.getMediaInfo();
|
return EventHandler::mediaInfo(m_currentRoom, &evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == IsEditableRole) {
|
if (role == IsEditableRole) {
|
||||||
return eventHandler.messageComponentType() == MessageComponentType::Text && evt.senderId() == m_currentRoom->localMember().id();
|
return MessageComponentType::typeForEvent(evt) == MessageComponentType::Text && evt.senderId() == m_currentRoom->localMember().id();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@@ -650,9 +648,8 @@ void MessageEventModel::createEventObjects(const Quotient::RoomEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto eventHandler = EventHandler(m_currentRoom, event);
|
if (EventHandler::isThreaded(event) && !m_threadModels.contains(EventHandler::threadRoot(event))) {
|
||||||
if (eventHandler.isThreaded() && !m_threadModels.contains(eventHandler.threadRoot())) {
|
m_threadModels[EventHandler::threadRoot(event)] = QSharedPointer<ThreadModel>(new ThreadModel(EventHandler::threadRoot(event), m_currentRoom));
|
||||||
m_threadModels[eventHandler.threadRoot()] = QSharedPointer<ThreadModel>(new ThreadModel(eventHandler.threadRoot(), 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
|
||||||
|
|||||||
@@ -121,12 +121,11 @@ void NotificationsModel::loadData()
|
|||||||
const auto &authorAvatar = avatar.isValid() && avatar.scheme() == QStringLiteral("mxc") ? avatar : QUrl();
|
const auto &authorAvatar = avatar.isValid() && avatar.scheme() == QStringLiteral("mxc") ? avatar : QUrl();
|
||||||
|
|
||||||
const auto &roomEvent = eventCast<const RoomEvent>(notification.event.get());
|
const auto &roomEvent = eventCast<const RoomEvent>(notification.event.get());
|
||||||
EventHandler eventHandler(dynamic_cast<NeoChatRoom *>(room), roomEvent);
|
|
||||||
beginInsertRows({}, m_notifications.length(), m_notifications.length());
|
beginInsertRows({}, m_notifications.length(), m_notifications.length());
|
||||||
m_notifications += Notification{
|
m_notifications += Notification{
|
||||||
.roomId = notification.roomId,
|
.roomId = notification.roomId,
|
||||||
.text = room->member(authorId).htmlSafeDisplayName() + (roomEvent->is<StateEvent>() ? QStringLiteral(" ") : QStringLiteral(": "))
|
.text = room->member(authorId).htmlSafeDisplayName() + (roomEvent->is<StateEvent>() ? QStringLiteral(" ") : QStringLiteral(": "))
|
||||||
+ eventHandler.getPlainBody(true),
|
+ EventHandler::plainBody(dynamic_cast<NeoChatRoom *>(room), roomEvent, true),
|
||||||
.authorName = room->member(authorId).htmlSafeDisplayName(),
|
.authorName = room->member(authorId).htmlSafeDisplayName(),
|
||||||
.authorAvatar = authorAvatar,
|
.authorAvatar = authorAvatar,
|
||||||
.eventId = roomEvent->id(),
|
.eventId = roomEvent->id(),
|
||||||
|
|||||||
@@ -245,8 +245,7 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
|
|||||||
if (room->lastEvent() == nullptr || room->lastEventIsSpoiler()) {
|
if (room->lastEvent() == nullptr || room->lastEventIsSpoiler()) {
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
EventHandler eventHandler(room, room->lastEvent());
|
return EventHandler::subtitleText(room, room->lastEvent());
|
||||||
return eventHandler.subtitleText();
|
|
||||||
}
|
}
|
||||||
if (role == AvatarImageRole) {
|
if (role == AvatarImageRole) {
|
||||||
return room->avatar(128);
|
return room->avatar(128);
|
||||||
|
|||||||
@@ -357,8 +357,7 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const
|
|||||||
if (room->lastEvent() == nullptr || room->lastEventIsSpoiler()) {
|
if (room->lastEvent() == nullptr || room->lastEventIsSpoiler()) {
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
EventHandler eventHandler(room, room->lastEvent());
|
return EventHandler::subtitleText(room, room->lastEvent());
|
||||||
return eventHandler.subtitleText();
|
|
||||||
}
|
}
|
||||||
if (role == AvatarImageRole) {
|
if (role == AvatarImageRole) {
|
||||||
return room->avatar(128);
|
return room->avatar(128);
|
||||||
|
|||||||
@@ -89,8 +89,6 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const
|
|||||||
auto row = index.row();
|
auto row = index.row();
|
||||||
const auto &event = *m_result->results[row].result;
|
const auto &event = *m_result->results[row].result;
|
||||||
|
|
||||||
EventHandler eventHandler(m_room, &event);
|
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case AuthorRole:
|
case AuthorRole:
|
||||||
return QVariant::fromValue<NeochatRoomMember *>(m_memberObjects.at(event.senderId()).get());
|
return QVariant::fromValue<NeochatRoomMember *>(m_memberObjects.at(event.senderId()).get());
|
||||||
@@ -100,7 +98,7 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
return event.originTimestamp().date() != m_result->results[row - 1].result->originTimestamp().date();
|
return event.originTimestamp().date() != m_result->results[row - 1].result->originTimestamp().date();
|
||||||
case SectionRole:
|
case SectionRole:
|
||||||
return eventHandler.getTimeString(true);
|
return EventHandler::timeString(&event, true);
|
||||||
case ShowReactionsRole:
|
case ShowReactionsRole:
|
||||||
return false;
|
return false;
|
||||||
case ShowReadMarkersRole:
|
case ShowReadMarkersRole:
|
||||||
@@ -108,13 +106,13 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const
|
|||||||
case IsPendingRole:
|
case IsPendingRole:
|
||||||
return false;
|
return false;
|
||||||
case HighlightRole:
|
case HighlightRole:
|
||||||
return eventHandler.isHighlighted();
|
return EventHandler::isHighlighted(m_room, &event);
|
||||||
case EventIdRole:
|
case EventIdRole:
|
||||||
return eventHandler.getId();
|
return EventHandler::id(&event);
|
||||||
case IsThreadedRole:
|
case IsThreadedRole:
|
||||||
return eventHandler.isThreaded();
|
return EventHandler::isThreaded(&event);
|
||||||
case ThreadRootRole:
|
case ThreadRootRole:
|
||||||
return eventHandler.threadRoot();
|
return EventHandler::threadRoot(&event);
|
||||||
case ContentModelRole: {
|
case ContentModelRole: {
|
||||||
if (!event.isStateEvent()) {
|
if (!event.isStateEvent()) {
|
||||||
return QVariant::fromValue<MessageContentModel *>(new MessageContentModel(m_room, &event));
|
return QVariant::fromValue<MessageContentModel *>(new MessageContentModel(m_room, &event));
|
||||||
|
|||||||
@@ -23,8 +23,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)) {
|
||||||
EventHandler eventHandler(dynamic_cast<NeoChatRoom *>(QObject::parent()), roomEvent);
|
if (EventHandler::isThreaded(roomEvent) && EventHandler::threadRoot(roomEvent) == m_threadRootId) {
|
||||||
if (eventHandler.isThreaded() && eventHandler.threadRoot() == m_threadRootId) {
|
|
||||||
addNewEvent(event);
|
addNewEvent(event);
|
||||||
clearModels();
|
clearModels();
|
||||||
addModels();
|
addModels();
|
||||||
@@ -34,8 +33,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)) {
|
||||||
EventHandler eventHandler(dynamic_cast<NeoChatRoom *>(QObject::parent()), roomEvent);
|
if (EventHandler::isThreaded(roomEvent) && EventHandler::threadRoot(roomEvent) == m_threadRootId) {
|
||||||
if (eventHandler.isThreaded() && eventHandler.threadRoot() == m_threadRootId) {
|
|
||||||
addNewEvent(roomEvent);
|
addNewEvent(roomEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -549,10 +549,8 @@ void NeoChatRoom::postHtmlMessage(const QString &text,
|
|||||||
bool isFallingBack = !fallbackId.isEmpty();
|
bool isFallingBack = !fallbackId.isEmpty();
|
||||||
QString replyEventId = isFallingBack ? fallbackId : QString();
|
QString replyEventId = isFallingBack ? fallbackId : QString();
|
||||||
if (isReply) {
|
if (isReply) {
|
||||||
EventHandler eventHandler(this, &**replyIt);
|
|
||||||
|
|
||||||
isFallingBack = false;
|
isFallingBack = false;
|
||||||
replyEventId = eventHandler.getId();
|
replyEventId = EventHandler::id(replyIt->get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
@@ -605,12 +603,10 @@ void NeoChatRoom::postHtmlMessage(const QString &text,
|
|||||||
if (isReply) {
|
if (isReply) {
|
||||||
const auto &replyEvt = **replyIt;
|
const auto &replyEvt = **replyIt;
|
||||||
|
|
||||||
EventHandler eventHandler(this, &**replyIt);
|
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
QJsonObject json{
|
QJsonObject json{
|
||||||
{"msgtype"_ls, msgTypeToString(type)},
|
{"msgtype"_ls, msgTypeToString(type)},
|
||||||
{"body"_ls, "> <%1> %2\n\n%3"_ls.arg(replyEvt.senderId(), eventHandler.getPlainBody(), text)},
|
{"body"_ls, "> <%1> %2\n\n%3"_ls.arg(replyEvt.senderId(), EventHandler::plainBody(this, &replyEvt), text)},
|
||||||
{"format"_ls, "org.matrix.custom.html"_ls},
|
{"format"_ls, "org.matrix.custom.html"_ls},
|
||||||
{"m.relates_to"_ls,
|
{"m.relates_to"_ls,
|
||||||
QJsonObject {
|
QJsonObject {
|
||||||
@@ -622,7 +618,7 @@ void NeoChatRoom::postHtmlMessage(const QString &text,
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"formatted_body"_ls,
|
{"formatted_body"_ls,
|
||||||
"<mx-reply><blockquote><a href=\"https://matrix.to/#/%1/%2\">In reply to</a> <a href=\"https://matrix.to/#/%3\">%4</a><br>%5</blockquote></mx-reply>%6"_ls.arg(id(), replyEventId, replyEvt.senderId(), replyEvt.senderId(), eventHandler.getRichBody(), html)
|
"<mx-reply><blockquote><a href=\"https://matrix.to/#/%1/%2\">In reply to</a> <a href=\"https://matrix.to/#/%3\">%4</a><br>%5</blockquote></mx-reply>%6"_ls.arg(id(), replyEventId, replyEvt.senderId(), replyEvt.senderId(), EventHandler::richBody(this, &replyEvt), html)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "chatbarcache.h"
|
#include "chatbarcache.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
|
#include "eventhandler.h"
|
||||||
#include "neochatconfig.h"
|
#include "neochatconfig.h"
|
||||||
#include "neochatconnection.h"
|
#include "neochatconnection.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
@@ -203,19 +204,23 @@ void RoomManager::viewEventSource(const QString &eventId)
|
|||||||
void RoomManager::viewEventMenu(const QString &eventId, NeoChatRoom *room, NeochatRoomMember *sender, const QString &selectedText)
|
void RoomManager::viewEventMenu(const QString &eventId, NeoChatRoom *room, NeochatRoomMember *sender, const QString &selectedText)
|
||||||
{
|
{
|
||||||
const auto &event = **room->findInTimeline(eventId);
|
const auto &event = **room->findInTimeline(eventId);
|
||||||
const auto eventHandler = EventHandler(room, &event);
|
|
||||||
|
|
||||||
if (eventHandler.getMediaInfo().contains("mimeType"_ls)) {
|
if (EventHandler::mediaInfo(room, &event).contains("mimeType"_ls)) {
|
||||||
Q_EMIT showFileMenu(eventId,
|
Q_EMIT showFileMenu(eventId,
|
||||||
sender,
|
sender,
|
||||||
eventHandler.messageComponentType(),
|
MessageComponentType::typeForEvent(event),
|
||||||
eventHandler.getPlainBody(),
|
EventHandler::plainBody(room, &event),
|
||||||
eventHandler.getMediaInfo()["mimeType"_ls].toString(),
|
EventHandler::mediaInfo(room, &event)["mimeType"_ls].toString(),
|
||||||
room->fileTransferInfo(eventId));
|
room->fileTransferInfo(eventId));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT showMessageMenu(eventId, sender, eventHandler.messageComponentType(), eventHandler.getPlainBody(), eventHandler.getRichBody(), selectedText);
|
Q_EMIT showMessageMenu(eventId,
|
||||||
|
sender,
|
||||||
|
MessageComponentType::typeForEvent(event),
|
||||||
|
EventHandler::plainBody(room, &event),
|
||||||
|
EventHandler::richBody(room, &event),
|
||||||
|
selectedText);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RoomManager::hasOpenRoom() const
|
bool RoomManager::hasOpenRoom() const
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
#include "chatdocumenthandler.h"
|
#include "chatdocumenthandler.h"
|
||||||
#include "enums/messagecomponenttype.h"
|
#include "enums/messagecomponenttype.h"
|
||||||
#include "eventhandler.h"
|
|
||||||
#include "models/mediamessagefiltermodel.h"
|
#include "models/mediamessagefiltermodel.h"
|
||||||
#include "models/messagefiltermodel.h"
|
#include "models/messagefiltermodel.h"
|
||||||
#include "models/roomlistmodel.h"
|
#include "models/roomlistmodel.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user