Skip to content
Snippets Groups Projects
Commit f54ed448 authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Html format messages, where supported

parent 19e3036c
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ Rectangle {
Text {
id: messageText
text: modelData.Body
text: modelData.FormattedBody
color: Theme.primaryColor
wrapMode: Text.Wrap
width: chatView.width
......
......@@ -12,10 +12,17 @@ Q_DECLARE_METATYPE(QSharedPointer<Room>);
using mtx::events::Event;
template <class T> std::string eventBody(const Event<T> &) { return ""; }
template <class T> auto eventBody(const mtx::events::RoomEvent<T> &e) -> decltype(e.content.body) {
return e.content.body;
}
template <class T> std::string eventFormattedBody(const Event<T> &) { return ""; }
template <class T> auto eventFormattedBody(const mtx::events::RoomEvent<T> &e) -> decltype(e.content.formatted_body) {
auto temp = e.content.formatted_body;
if (!temp.empty())
return temp;
else
return e.content.body;
}
template <class T> auto eventUserId(const mtx::events::Event<T> &e) -> std::string { return ""; }
template <class T> auto eventUserId(const mtx::events::RoomEvent<T> &e) -> std::string { return e.sender; }
......@@ -180,6 +187,7 @@ QHash<int, QByteArray> Room::roleNames() const {
QHash<int, QByteArray> roles;
roles[Type] = "Type";
roles[Body] = "Body";
roles[FormattedBody] = "FormattedBody";
roles[UserId] = "UserId";
roles[UserName] = "UserName";
roles[Timestamp] = "Timestamp";
......@@ -200,6 +208,9 @@ QVariant Room::data(const QModelIndex &index, int role) const {
case Body:
return QString::fromStdString(
boost::apply_visitor([](const auto &e) -> std::string { return eventBody(e); }, event.data));
case FormattedBody:
return QString::fromStdString(
boost::apply_visitor([](const auto &e) -> std::string { return eventFormattedBody(e); }, event.data));
case UserId:
return QString::fromStdString(
boost::apply_visitor([](const auto &e) -> std::string { return eventUserId(e); }, event.data));
......
......@@ -91,6 +91,7 @@ struct Room : public QAbstractListModel {
enum Roles {
Type,
Body,
FormattedBody,
UserId,
UserName,
Timestamp,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment