Dynamically update read receipts
This commit is contained in:
parent
3ce7fdd63f
commit
2fe010c04a
3 changed files with 25 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue