Update invites in the UI after sync

This commit is contained in:
Konstantinos Sideris 2018-04-22 14:19:05 +03:00
parent c0e355f485
commit 1642f3cf40
6 changed files with 44 additions and 1 deletions

View file

@ -137,6 +137,7 @@ public:
std::vector<std::string> joinedRooms(); std::vector<std::string> joinedRooms();
QMap<QString, RoomInfo> roomInfo(bool withInvites = true); QMap<QString, RoomInfo> roomInfo(bool withInvites = true);
std::map<QString, bool> invites();
//! Calculate & return the name of the room. //! Calculate & return the name of the room.
QString getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb); QString getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb);

View file

@ -129,6 +129,8 @@ public:
roomType_ = RoomType::Joined; roomType_ = RoomType::Joined;
} }
bool isInvite() { return roomType_ == RoomType::Invited; }
signals: signals:
void clicked(const QString &room_id); void clicked(const QString &room_id);
void leaveRoom(const QString &room_id); void leaveRoom(const QString &room_id);

View file

@ -56,6 +56,7 @@ public:
void setFilterRooms(bool filterRooms); void setFilterRooms(bool filterRooms);
void setRoomFilter(std::vector<QString> room_ids); void setRoomFilter(std::vector<QString> room_ids);
void updateRoom(const QString &room_id, const RoomInfo &info); void updateRoom(const QString &room_id, const RoomInfo &info);
void cleanupInvites(const std::map<QString, bool> &invites);
signals: signals:
void roomChanged(const QString &room_id); void roomChanged(const QString &room_id);

View file

@ -579,6 +579,25 @@ Cache::roomInfo(bool withInvites)
return result; return result;
} }
std::map<QString, bool>
Cache::invites()
{
std::map<QString, bool> result;
auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY);
auto cursor = lmdb::cursor::open(txn, invitesDb_);
std::string room_id, unused;
while (cursor.get(room_id, unused, MDB_NEXT))
result.emplace(QString::fromStdString(std::move(room_id)), true);
cursor.close();
txn.commit();
return result;
}
QString QString
Cache::getRoomAvatarUrl(lmdb::txn &txn, Cache::getRoomAvatarUrl(lmdb::txn &txn,
lmdb::dbi &statesdb, lmdb::dbi &statesdb,

View file

@ -420,6 +420,12 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
this, this,
[this](const std::vector<std::string> &rooms) { view_manager_->initialize(rooms); }); [this](const std::vector<std::string> &rooms) { view_manager_->initialize(rooms); });
connect(this, &ChatPage::syncUI, this, [this](const mtx::responses::Rooms &rooms) { connect(this, &ChatPage::syncUI, this, [this](const mtx::responses::Rooms &rooms) {
try {
room_list_->cleanupInvites(cache_->invites());
} catch (const lmdb::error &e) {
qWarning() << "failed to retrieve invites" << e.what();
}
view_manager_->initialize(rooms); view_manager_->initialize(rooms);
removeLeftRooms(rooms.leave); removeLeftRooms(rooms.leave);
@ -528,6 +534,7 @@ ChatPage::syncCompleted(const mtx::responses::Sync &response)
auto promise = QtConcurrent::run([this, res = std::move(response)]() { auto promise = QtConcurrent::run([this, res = std::move(response)]() {
try { try {
cache_->saveState(res); cache_->saveState(res);
emit syncUI(res.rooms);
emit syncRoomlist(cache_->roomUpdates(res)); emit syncRoomlist(cache_->roomUpdates(res));
} catch (const lmdb::error &e) { } catch (const lmdb::error &e) {
std::cout << "save cache error:" << e.what() << '\n'; std::cout << "save cache error:" << e.what() << '\n';
@ -535,7 +542,6 @@ ChatPage::syncCompleted(const mtx::responses::Sync &response)
return; return;
} }
emit syncUI(std::move(res.rooms));
emit continueSync(cache_->nextBatchToken()); emit continueSync(cache_->nextBatchToken());
}); });
} }

View file

@ -180,6 +180,20 @@ RoomList::initialize(const QMap<QString, RoomInfo> &info)
emit roomChanged(room.first); emit roomChanged(room.first);
} }
void
RoomList::cleanupInvites(const std::map<QString, bool> &invites)
{
if (invites.empty())
return;
for (auto it = rooms_.begin(); it != rooms_.end();) {
if (it->second->isInvite() && (invites.find(it->first) == invites.end()))
it = rooms_.erase(it);
else
++it;
}
}
void void
RoomList::sync(const std::map<QString, RoomInfo> &info) RoomList::sync(const std::map<QString, RoomInfo> &info)