|
|
|
@ -1,5 +1,7 @@ |
|
|
|
|
#include "TimelineModel.h" |
|
|
|
|
|
|
|
|
|
#include <type_traits> |
|
|
|
|
|
|
|
|
|
#include <QRegularExpression> |
|
|
|
|
|
|
|
|
|
#include "Logging.h" |
|
|
|
@ -31,6 +33,119 @@ eventTimestamp(const T &event) |
|
|
|
|
{ |
|
|
|
|
return QDateTime::fromMSecsSinceEpoch(event.origin_server_ts); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
QString |
|
|
|
|
eventFormattedBody(const mtx::events::Event<T> &) |
|
|
|
|
{ |
|
|
|
|
return QString(""); |
|
|
|
|
} |
|
|
|
|
template<class T> |
|
|
|
|
auto |
|
|
|
|
eventFormattedBody(const mtx::events::RoomEvent<T> &e) |
|
|
|
|
-> std::enable_if_t<std::is_same<decltype(e.content.formatted_body), std::string>::value, QString> |
|
|
|
|
{ |
|
|
|
|
auto temp = e.content.formatted_body; |
|
|
|
|
if (!temp.empty()) { |
|
|
|
|
auto pos = temp.find("<mx-reply>"); |
|
|
|
|
if (pos != std::string::npos) |
|
|
|
|
temp.erase(pos, std::string("<mx-reply>").size()); |
|
|
|
|
pos = temp.find("</mx-reply>"); |
|
|
|
|
if (pos != std::string::npos) |
|
|
|
|
temp.erase(pos, std::string("</mx-reply>").size()); |
|
|
|
|
return QString::fromStdString(temp); |
|
|
|
|
} else |
|
|
|
|
return QString::fromStdString(e.content.body); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
qml_mtx_events::EventType |
|
|
|
|
toRoomEventType(const mtx::events::Event<T> &e) |
|
|
|
|
{ |
|
|
|
|
using mtx::events::EventType; |
|
|
|
|
switch (e.type) { |
|
|
|
|
case EventType::RoomKeyRequest: |
|
|
|
|
return qml_mtx_events::EventType::KeyRequest; |
|
|
|
|
case EventType::RoomAliases: |
|
|
|
|
return qml_mtx_events::EventType::Aliases; |
|
|
|
|
case EventType::RoomAvatar: |
|
|
|
|
return qml_mtx_events::EventType::Avatar; |
|
|
|
|
case EventType::RoomCanonicalAlias: |
|
|
|
|
return qml_mtx_events::EventType::CanonicalAlias; |
|
|
|
|
case EventType::RoomCreate: |
|
|
|
|
return qml_mtx_events::EventType::Create; |
|
|
|
|
case EventType::RoomEncrypted: |
|
|
|
|
return qml_mtx_events::EventType::Encrypted; |
|
|
|
|
case EventType::RoomEncryption: |
|
|
|
|
return qml_mtx_events::EventType::Encryption; |
|
|
|
|
case EventType::RoomGuestAccess: |
|
|
|
|
return qml_mtx_events::EventType::GuestAccess; |
|
|
|
|
case EventType::RoomHistoryVisibility: |
|
|
|
|
return qml_mtx_events::EventType::HistoryVisibility; |
|
|
|
|
case EventType::RoomJoinRules: |
|
|
|
|
return qml_mtx_events::EventType::JoinRules; |
|
|
|
|
case EventType::RoomMember: |
|
|
|
|
return qml_mtx_events::EventType::Member; |
|
|
|
|
case EventType::RoomMessage: |
|
|
|
|
return qml_mtx_events::EventType::UnknownMessage; |
|
|
|
|
case EventType::RoomName: |
|
|
|
|
return qml_mtx_events::EventType::Name; |
|
|
|
|
case EventType::RoomPowerLevels: |
|
|
|
|
return qml_mtx_events::EventType::PowerLevels; |
|
|
|
|
case EventType::RoomTopic: |
|
|
|
|
return qml_mtx_events::EventType::Topic; |
|
|
|
|
case EventType::RoomTombstone: |
|
|
|
|
return qml_mtx_events::EventType::Tombstone; |
|
|
|
|
case EventType::RoomRedaction: |
|
|
|
|
return qml_mtx_events::EventType::Redaction; |
|
|
|
|
case EventType::RoomPinnedEvents: |
|
|
|
|
return qml_mtx_events::EventType::PinnedEvents; |
|
|
|
|
case EventType::Sticker: |
|
|
|
|
return qml_mtx_events::EventType::Sticker; |
|
|
|
|
case EventType::Tag: |
|
|
|
|
return qml_mtx_events::EventType::Tag; |
|
|
|
|
case EventType::Unsupported: |
|
|
|
|
default: |
|
|
|
|
return qml_mtx_events::EventType::Unsupported; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
qml_mtx_events::EventType |
|
|
|
|
toRoomEventType(const mtx::events::Event<mtx::events::msg::Audio> &) |
|
|
|
|
{ |
|
|
|
|
return qml_mtx_events::EventType::AudioMessage; |
|
|
|
|
} |
|
|
|
|
qml_mtx_events::EventType |
|
|
|
|
toRoomEventType(const mtx::events::Event<mtx::events::msg::Emote> &) |
|
|
|
|
{ |
|
|
|
|
return qml_mtx_events::EventType::EmoteMessage; |
|
|
|
|
} |
|
|
|
|
qml_mtx_events::EventType |
|
|
|
|
toRoomEventType(const mtx::events::Event<mtx::events::msg::File> &) |
|
|
|
|
{ |
|
|
|
|
return qml_mtx_events::EventType::FileMessage; |
|
|
|
|
} |
|
|
|
|
qml_mtx_events::EventType |
|
|
|
|
toRoomEventType(const mtx::events::Event<mtx::events::msg::Image> &) |
|
|
|
|
{ |
|
|
|
|
return qml_mtx_events::EventType::ImageMessage; |
|
|
|
|
} |
|
|
|
|
qml_mtx_events::EventType |
|
|
|
|
toRoomEventType(const mtx::events::Event<mtx::events::msg::Notice> &) |
|
|
|
|
{ |
|
|
|
|
return qml_mtx_events::EventType::NoticeMessage; |
|
|
|
|
} |
|
|
|
|
qml_mtx_events::EventType |
|
|
|
|
toRoomEventType(const mtx::events::Event<mtx::events::msg::Text> &) |
|
|
|
|
{ |
|
|
|
|
return qml_mtx_events::EventType::TextMessage; |
|
|
|
|
} |
|
|
|
|
qml_mtx_events::EventType |
|
|
|
|
toRoomEventType(const mtx::events::Event<mtx::events::msg::Video> &) |
|
|
|
|
{ |
|
|
|
|
return qml_mtx_events::EventType::VideoMessage; |
|
|
|
|
} |
|
|
|
|
// ::EventType::Type toRoomEventType(const Event<mtx::events::msg::Location> &e) { return
|
|
|
|
|
// ::EventType::LocationMessage; }
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TimelineModel::TimelineModel(QString room_id, QObject *parent) |
|
|
|
@ -105,6 +220,14 @@ TimelineModel::data(const QModelIndex &index, int role) const |
|
|
|
|
case Timestamp: |
|
|
|
|
return QVariant(boost::apply_visitor( |
|
|
|
|
[](const auto &e) -> QDateTime { return eventTimestamp(e); }, events.value(id))); |
|
|
|
|
case Type: |
|
|
|
|
return QVariant(boost::apply_visitor( |
|
|
|
|
[](const auto &e) -> qml_mtx_events::EventType { return toRoomEventType(e); }, |
|
|
|
|
events.value(id))); |
|
|
|
|
case FormattedBody: |
|
|
|
|
return QVariant(utils::replaceEmoji(boost::apply_visitor( |
|
|
|
|
[](const auto &e) -> QString { return eventFormattedBody(e); }, |
|
|
|
|
events.value(id)))); |
|
|
|
|
default: |
|
|
|
|
return QVariant(); |
|
|
|
|
} |
|
|
|
|