summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-22 11:27:00 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-22 11:27:00 +0300
commit6d0bc0c05ee5e8ac9146ffa4808f6a013d1c7438 (patch)
tree104e4697dce16695e374429ae7e8629d91a7e381 /src
parentInitialize views before room list (diff)
downloadnheko-6d0bc0c05ee5e8ac9146ffa4808f6a013d1c7438.tar.xz
Strip whitespace from room names for QuickSwitcher
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cc45
-rw-r--r--src/ChatPage.cc19
2 files changed, 24 insertions, 40 deletions
diff --git a/src/Cache.cc b/src/Cache.cc

index 1155a40a..4dadff06 100644 --- a/src/Cache.cc +++ b/src/Cache.cc
@@ -390,32 +390,12 @@ Cache::saveState(const mtx::responses::Sync &res) saveInvites(txn, res.rooms.invite); - std::map<std::string, bool> invites; - for (const auto &invite : res.rooms.invite) - invites.emplace(std::move(invite.first), true); - - // removeStaleInvites(txn, invites); - removeLeftRooms(txn, res.rooms.leave); txn.commit(); } void -Cache::removeStaleInvites(lmdb::txn &txn, const std::map<std::string, bool> &curr) -{ - auto invitesCursor = lmdb::cursor::open(txn, invitesDb_); - - std::string room_id, room_data; - while (invitesCursor.get(room_id, room_data, MDB_NEXT)) { - if (curr.find(room_id) == curr.end()) - lmdb::cursor_del(invitesCursor); - } - - invitesCursor.close(); -} - -void Cache::saveInvites(lmdb::txn &txn, const std::map<std::string, mtx::responses::InvitedRoom> &rooms) { for (const auto &room : rooms) { @@ -554,32 +534,33 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms) } QMap<QString, RoomInfo> -Cache::roomInfo() +Cache::roomInfo(bool withInvites) { QMap<QString, RoomInfo> result; - auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY); - auto roomsCursor = lmdb::cursor::open(txn, roomsDb_); - auto invitesCursor = lmdb::cursor::open(txn, invitesDb_); + auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY); std::string room_id; std::string room_data; // Gather info about the joined rooms. + auto roomsCursor = lmdb::cursor::open(txn, roomsDb_); while (roomsCursor.get(room_id, room_data, MDB_NEXT)) { - RoomInfo tmp = json::parse(room_data); + RoomInfo tmp = json::parse(std::move(room_data)); result.insert(QString::fromStdString(std::move(room_id)), std::move(tmp)); } + roomsCursor.close(); - // Gather info about the invites. - while (invitesCursor.get(room_id, room_data, MDB_NEXT)) { - RoomInfo tmp = json::parse(room_data); - result.insert(QString::fromStdString(std::move(room_id)), std::move(tmp)); + if (withInvites) { + // Gather info about the invites. + auto invitesCursor = lmdb::cursor::open(txn, invitesDb_); + while (invitesCursor.get(room_id, room_data, MDB_NEXT)) { + RoomInfo tmp = json::parse(room_data); + result.insert(QString::fromStdString(std::move(room_id)), std::move(tmp)); + } + invitesCursor.close(); } - invitesCursor.close(); - roomsCursor.close(); - txn.commit(); return result; diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index ff59471f..ae3079a3 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc
@@ -624,6 +624,11 @@ ChatPage::updateOwnCommunitiesInfo(const QList<QString> &own_communities) void ChatPage::changeTopRoomInfo(const QString &room_id) { + if (room_id.isEmpty()) { + qWarning() << "can't switch to empty room_id"; + return; + } + try { auto room_info = cache_->getRoomInfo({room_id.toStdString()}); @@ -640,12 +645,11 @@ ChatPage::changeTopRoomInfo(const QString &room_id) top_bar_->updateRoomAvatar(roomAvatars_[room_id].toImage()); else top_bar_->updateRoomAvatarFromName(name); + + current_room_ = room_id; } catch (const lmdb::error &e) { - qWarning() << "failed to change top bar room info" - << QString::fromStdString(e.what()); + qWarning() << "failed to change top bar room info" << e.what(); } - - current_room_ = room_id; } void @@ -712,12 +716,11 @@ ChatPage::showQuickSwitcher() quickSwitcherModal_->setColor(QColor(30, 30, 30, 170)); } - std::map<QString, QString> rooms; - try { - auto info = cache_->roomInfo(); + std::map<QString, QString> rooms; + auto info = cache_->roomInfo(false); for (auto it = info.begin(); it != info.end(); ++it) - rooms.emplace(QString::fromStdString(it.value().name), it.key()); + rooms.emplace(QString::fromStdString(it.value().name).trimmed(), it.key()); quickSwitcher_->setRoomList(rooms); quickSwitcherModal_->show(); } catch (const lmdb::error &e) {