summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2019-09-18 23:37:30 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2019-11-23 20:06:14 +0100
commitd34067a25792b5d69b2ce3192486189f0db12abb (patch)
treedf9f7f10a8a860f43442192334ee2c02a741b3f5 /src
parentAdd send/received indicator (diff)
downloadnheko-d34067a25792b5d69b2ce3192486189f0db12abb.tar.xz
Enable read receipts action and sync read receipts from cache
Diffstat (limited to 'src')
-rw-r--r--src/timeline2/TimelineModel.cpp25
-rw-r--r--src/timeline2/TimelineModel.h5
-rw-r--r--src/timeline2/TimelineViewManager.cpp10
-rw-r--r--src/timeline2/TimelineViewManager.h2
4 files changed, 38 insertions, 4 deletions
diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp

index 13429c3e..d0daae25 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp
@@ -7,6 +7,7 @@ #include "ChatPage.h" #include "Logging.h" +#include "MainWindow.h" #include "Olm.h" #include "Utils.h" #include "dialogs/RawMessage.h" @@ -376,6 +377,8 @@ TimelineModel::data(const QModelIndex &index, int role) const return qml_mtx_events::Failed; else if (pending.contains(id)) return qml_mtx_events::Sent; + else if (read.contains(id)) + return qml_mtx_events::Read; else return qml_mtx_events::Received; default: @@ -664,7 +667,13 @@ TimelineModel::replyAction(QString id) if (related.quoted_body.isEmpty()) return; - emit ChatPage::instance()->messageReply(related); + ChatPage::instance()->messageReply(related); +} + +void +TimelineModel::readReceiptsAction(QString id) const +{ + MainWindow::instance()->openReadReceiptsDialog(id); } int @@ -685,3 +694,17 @@ TimelineModel::indexToId(int index) const return ""; return eventOrder[index]; } + +void +TimelineModel::markEventsAsRead(const std::vector<QString> &event_ids) +{ + for (const auto &id : event_ids) { + read.insert(id); + int idx = idToIndex(id); + if (idx < 0) { + nhlog::ui()->warn("Read index out of range"); + return; + } + emit dataChanged(index(idx, 0), index(idx, 0)); + } +} diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h
index b651708d..2cd22661 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h
@@ -131,6 +131,7 @@ public: Q_INVOKABLE QString escapeEmoji(QString str) const; Q_INVOKABLE void viewRawMessage(QString id) const; Q_INVOKABLE void replyAction(QString id); + Q_INVOKABLE void readReceiptsAction(QString id) const; Q_INVOKABLE int idToIndex(QString id) const; Q_INVOKABLE QString indexToId(int index) const; @@ -146,10 +147,10 @@ public slots: emit currentIndexChanged(index); } int currentIndex() const { return idToIndex(currentId); } + void markEventsAsRead(const std::vector<QString> &event_ids); private slots: // Add old events at the top of the timeline. - void addBackwardsEvents(const mtx::responses::Messages &msgs); signals: @@ -165,7 +166,7 @@ private: const std::vector<mtx::events::collections::TimelineEvents> &timeline); QHash<QString, mtx::events::collections::TimelineEvents> events; - QSet<QString> pending, failed; + QSet<QString> pending, failed, read; std::vector<QString> eventOrder; QString room_id_; diff --git a/src/timeline2/TimelineViewManager.cpp b/src/timeline2/TimelineViewManager.cpp
index 8233d33e..18297370 100644 --- a/src/timeline2/TimelineViewManager.cpp +++ b/src/timeline2/TimelineViewManager.cpp
@@ -53,6 +53,16 @@ TimelineViewManager::setHistoryView(const QString &room_id) } void +TimelineViewManager::updateReadReceipts(const QString &room_id, + const std::vector<QString> &event_ids) +{ + auto room = models.find(room_id); + if (room != models.end()) { + room.value()->markEventsAsRead(event_ids); + } +} + +void TimelineViewManager::initWithMessages(const std::map<QString, mtx::responses::Timeline> &msgs) { for (const auto &e : msgs) { diff --git a/src/timeline2/TimelineViewManager.h b/src/timeline2/TimelineViewManager.h
index c2d1a8c0..52070b97 100644 --- a/src/timeline2/TimelineViewManager.h +++ b/src/timeline2/TimelineViewManager.h
@@ -40,7 +40,7 @@ signals: void activeTimelineChanged(TimelineModel *timeline); public slots: - void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids) {} + void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids); void removeTimelineEvent(const QString &room_id, const QString &event_id) {} void initWithMessages(const std::map<QString, mtx::responses::Timeline> &msgs);