mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +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 {
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue