Skip to content
Snippets Groups Projects
Commit 2fe010c0 authored by Loren Burkholder's avatar Loren Burkholder
Browse files

Dynamically update read receipts

parent 3ce7fdd6
No related branches found
No related tags found
No related merge requests found
......@@ -118,7 +118,6 @@ ApplicationWindow {
footer: DialogButtonBox {
standardButtons: DialogButtonBox.Ok
onAccepted: readReceiptsRoot.close()
}
}
......@@ -7,6 +7,7 @@
#include <QLocale>
#include "Cache.h"
#include "Cache_p.h"
#include "Logging.h"
#include "Utils.h"
......@@ -16,10 +17,26 @@ ReadReceiptsModel::ReadReceiptsModel(QString event_id, QString room_id, QObject
, room_id_{room_id}
{
try {
addUsers(cache::readReceipts(event_id, room_id));
addUsers(cache::readReceipts(event_id_, room_id_));
} catch (const lmdb::error &) {
nhlog::db()->warn("failed to retrieve read receipts for {} {}",
event_id.toStdString(),
event_id_.toStdString(),
room_id_.toStdString());
return;
}
connect(cache::client(), &Cache::newReadReceipts, this, &ReadReceiptsModel::update);
}
void
ReadReceiptsModel::update()
{
try {
addUsers(cache::readReceipts(event_id_, room_id_));
} catch (const lmdb::error &) {
nhlog::db()->warn("failed to retrieve read receipts for {} {}",
event_id_.toStdString(),
room_id_.toStdString());
return;
......@@ -59,7 +76,9 @@ void
ReadReceiptsModel::addUsers(
const std::multimap<uint64_t, std::string, std::greater<uint64_t>> &users)
{
beginInsertRows(QModelIndex{}, readReceipts_.length(), users.size() - 1);
auto oldLen = readReceipts_.length();
beginInsertRows(QModelIndex{}, oldLen, users.size() - 1);
readReceipts_.clear();
for (const auto &user : users) {
......@@ -74,6 +93,8 @@ ReadReceiptsModel::addUsers(
});
endInsertRows();
emit dataChanged(index(0), index(oldLen - 1));
}
QString
......
......@@ -41,6 +41,7 @@ public:
public slots:
void addUsers(const std::multimap<uint64_t, std::string, std::greater<uint64_t>> &users);
void update();
private:
QString dateFormat(const QDateTime &then) const;
......
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