File messages (qml)

This commit is contained in:
Nicolas Werner 2019-10-04 01:10:46 +02:00
parent ea12c9f9bc
commit a8166462ad
5 changed files with 84 additions and 2 deletions

View file

@ -87,8 +87,9 @@ eventFormattedBody(const mtx::events::RoomEvent<T> &e)
if (pos != std::string::npos)
temp.erase(pos, std::string("</mx-reply>").size());
return QString::fromStdString(temp);
} else
return QString::fromStdString(e.content.body);
} else {
return QString::fromStdString(e.content.body).toHtmlEscaped().replace("\n", "<br>");
}
}
template<class T>
@ -138,6 +139,20 @@ eventFilename(const mtx::events::RoomEvent<mtx::events::msg::File> &e)
return QString::fromStdString(e.content.body);
}
template<class T>
auto
eventFilesize(const mtx::events::RoomEvent<T> &e) -> decltype(e.content.info.size)
{
return e.content.info.size;
}
template<class T>
int64_t
eventFilesize(const T &)
{
return 0;
}
template<class T>
QString
eventMimeType(const T &)
@ -341,6 +356,7 @@ TimelineModel::roleNames() const
{Timestamp, "timestamp"},
{Url, "url"},
{Filename, "filename"},
{Filesize, "filesize"},
{MimeType, "mimetype"},
{Height, "height"},
{Width, "width"},
@ -423,6 +439,12 @@ TimelineModel::data(const QModelIndex &index, int role) const
case Filename:
return QVariant(boost::apply_visitor(
[](const auto &e) -> QString { return eventFilename(e); }, event));
case Filesize:
return QVariant(boost::apply_visitor(
[](const auto &e) -> QString {
return utils::humanReadableFileSize(eventFilesize(e));
},
event));
case MimeType:
return QVariant(boost::apply_visitor(
[](const auto &e) -> QString { return eventMimeType(e); }, event));