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

Add timestamp

parent 1a62bfb8
No related branches found
No related tags found
No related merge requests found
......@@ -2,12 +2,23 @@ import QtQuick 2.0
import Sailfish.Silica 1.0
Rectangle {
height: messageText.contentHeight
Text {
id: messageText
text: modelData.Body
color: Theme.primaryColor
wrapMode: Text.Wrap
width: chatView.width
height: col.height
Column {
id: col
Text {
id: messageText
text: modelData.Body
color: Theme.primaryColor
wrapMode: Text.Wrap
width: chatView.width
}
Text {
anchors.right: col.right
text: modelData.Timestamp.toLocaleTimeString()
color: Theme.highlightColor
font.pixelSize: Theme.fontSizeTiny
horizontalAlignment: Text.AlignRight
}
}
}
......@@ -19,6 +19,8 @@ template <class T> auto eventBody(const mtx::events::RoomEvent<T> &e) -> decltyp
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; }
template <class T> auto eventTimestamp(const mtx::events::Event<T> &e) -> uint64_t { return 0; }
template <class T> auto eventTimestamp(const mtx::events::RoomEvent<T> &e) -> uint64_t { return e.origin_server_ts; }
template <class T>::EventType::Type toRoomEventType(const Event<T> &e) {
using mtx::events::EventType;
......@@ -180,6 +182,7 @@ QHash<int, QByteArray> Room::roleNames() const {
roles[Body] = "Body";
roles[UserId] = "UserId";
roles[UserName] = "UserName";
roles[Timestamp] = "Timestamp";
return roles;
}
......@@ -210,6 +213,9 @@ QVariant Room::data(const QModelIndex &index, int role) const {
}
},
event.data));
case Timestamp:
return QDateTime::fromMSecsSinceEpoch(
boost::apply_visitor([](const auto &e) -> uint64_t { return eventTimestamp(e); }, event.data));
default:
return QVariant();
}
......
......@@ -93,6 +93,7 @@ struct Room : public QAbstractListModel {
Body,
UserId,
UserName,
Timestamp,
};
QHash<int, QByteArray> roleNames() const override;
......
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