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

Implement sending read notifications

parent 365efaa5
No related branches found
No related tags found
No related merge requests found
......@@ -63,12 +63,31 @@ Page {
console.log("at end")
atEnd = true
}
var lastIndex = maxIndex
for(var child in chatView.contentItem.children) {
if (chatView.contentItem.children[child].isFullyVisible && chatView.contentItem.children[child].index > maxIndex)
lastIndex = chatView.contentItem.children[child].index;
}
if (lastIndex > maxIndex) {
maxIndex = lastIndex
}
}
property int maxIndex: -1
onMaxIndexChanged: {
console.log("max index: " + maxIndex)
room.markRead(maxIndex)
}
delegate: ListItem {
id: messageItem
contentHeight: loader.item.height
property int yoff: Math.round(messageItem.y - chatView.contentY - 1)
property bool isFullyVisible: yoff + messageItem.height < chatView.height
property int index: model.index
Loader {
id: loader
source: switch(model.Type) {
......
......@@ -75,8 +75,8 @@ template <class T> auto eventUserId(const mtx::events::RoomEvent<T> &e) -> std::
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> auto eventEventId(const mtx::events::Event<T> &e) -> std::string { return ""; }
template <class T> auto eventEventId(const mtx::events::StateEvent<T> &e) -> std::string { return e.event_id; }
// template <class T> auto eventEventId(const mtx::events::Event<T> &e) -> std::string { return ""; }
template <class T> auto eventEventId(const mtx::events::RoomEvent<T> &e) -> std::string { return e.event_id; }
template <class T>::EventType::Type toRoomEventType(const Event<T> &e) {
using mtx::events::EventType;
......@@ -497,3 +497,16 @@ QColor Room::userColor(QString id, QColor background) {
return inputColor;
}
void Room::markRead(int index) {
if (index < 0 || index >= events.size())
return;
auto event_id = boost::apply_visitor([](const auto &e) -> std::string { return eventEventId(e); }, events[index]);
http::client().read_event(id, event_id, [](mtx::http::RequestErr e) {
if (e)
qDebug() << "Error marking event as read: " << *e;
});
qDebug() << "marked " << QString::fromStdString(event_id) << " as read";
}
......@@ -157,6 +157,7 @@ struct Room : public QAbstractListModel {
void setUnread(int unread) { this->unreadNotifications = unread; }
void fetchOlderMessages();
void sendTextMessage(QString message);
void markRead(int index);
private:
std::vector<mtx::events::collections::TimelineEvents> events;
......
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