mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Dynamically update read receipts
This commit is contained in:
parent
3ce7fdd63f
commit
2fe010c04a
3 changed files with 25 additions and 4 deletions
|
@ -118,7 +118,6 @@ ApplicationWindow {
|
||||||
footer: DialogButtonBox {
|
footer: DialogButtonBox {
|
||||||
standardButtons: DialogButtonBox.Ok
|
standardButtons: DialogButtonBox.Ok
|
||||||
onAccepted: readReceiptsRoot.close()
|
onAccepted: readReceiptsRoot.close()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
|
#include "Cache_p.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
@ -16,10 +17,26 @@ ReadReceiptsModel::ReadReceiptsModel(QString event_id, QString room_id, QObject
|
||||||
, room_id_{room_id}
|
, room_id_{room_id}
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
addUsers(cache::readReceipts(event_id, room_id));
|
addUsers(cache::readReceipts(event_id_, room_id_));
|
||||||
} catch (const lmdb::error &) {
|
} catch (const lmdb::error &) {
|
||||||
nhlog::db()->warn("failed to retrieve read receipts for {} {}",
|
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());
|
room_id_.toStdString());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -59,7 +76,9 @@ void
|
||||||
ReadReceiptsModel::addUsers(
|
ReadReceiptsModel::addUsers(
|
||||||
const std::multimap<uint64_t, std::string, std::greater<uint64_t>> &users)
|
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();
|
readReceipts_.clear();
|
||||||
for (const auto &user : users) {
|
for (const auto &user : users) {
|
||||||
|
@ -74,6 +93,8 @@ ReadReceiptsModel::addUsers(
|
||||||
});
|
});
|
||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
|
emit dataChanged(index(0), index(oldLen - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addUsers(const std::multimap<uint64_t, std::string, std::greater<uint64_t>> &users);
|
void addUsers(const std::multimap<uint64_t, std::string, std::greater<uint64_t>> &users);
|
||||||
|
void update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString dateFormat(const QDateTime &then) const;
|
QString dateFormat(const QDateTime &then) const;
|
||||||
|
|
Loading…
Reference in a new issue