Don't pass around empty timeline

This commit is contained in:
Nicolas Werner 2020-10-28 13:06:28 +01:00
parent 2bac6d6c75
commit 70f35de449
6 changed files with 15 additions and 19 deletions

View File

@ -1469,22 +1469,22 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms)
return room_info; return room_info;
} }
std::map<QString, mtx::responses::Timeline> std::vector<QString>
Cache::roomMessages() Cache::roomIds()
{ {
auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY); auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY);
std::map<QString, mtx::responses::Timeline> msgs; std::vector<QString> rooms;
std::string room_id, unused; std::string room_id, unused;
auto roomsCursor = lmdb::cursor::open(txn, roomsDb_); auto roomsCursor = lmdb::cursor::open(txn, roomsDb_);
while (roomsCursor.get(room_id, unused, MDB_NEXT)) while (roomsCursor.get(room_id, unused, MDB_NEXT))
msgs.emplace(QString::fromStdString(room_id), mtx::responses::Timeline()); rooms.push_back(QString::fromStdString(room_id));
roomsCursor.close(); roomsCursor.close();
txn.commit(); txn.commit();
return msgs; return rooms;
} }
QMap<QString, mtx::responses::Notifications> QMap<QString, mtx::responses::Notifications>
@ -3967,10 +3967,10 @@ setCurrentFormat()
instance_->setCurrentFormat(); instance_->setCurrentFormat();
} }
std::map<QString, mtx::responses::Timeline> std::vector<QString>
roomMessages() roomIds()
{ {
return instance_->roomMessages(); return instance_->roomIds();
} }
QMap<QString, mtx::responses::Notifications> QMap<QString, mtx::responses::Notifications>

View File

@ -118,8 +118,7 @@ public:
void setCurrentFormat(); void setCurrentFormat();
bool runMigrations(); bool runMigrations();
std::map<QString, mtx::responses::Timeline> roomMessages(); std::vector<QString> roomIds();
QMap<QString, mtx::responses::Notifications> getTimelineMentions(); QMap<QString, mtx::responses::Notifications> getTimelineMentions();
//! Retrieve all the user ids from a room. //! Retrieve all the user ids from a room.

View File

@ -765,7 +765,7 @@ ChatPage::loadStateFromCache()
cache::restoreSessions(); cache::restoreSessions();
olm::client()->load(cache::restoreOlmAccount(), STORAGE_SECRET_KEY); olm::client()->load(cache::restoreOlmAccount(), STORAGE_SECRET_KEY);
emit initializeEmptyViews(cache::client()->roomMessages()); emit initializeEmptyViews(cache::client()->roomIds());
emit initializeRoomList(cache::roomInfo()); emit initializeRoomList(cache::roomInfo());
emit initializeMentions(cache::getTimelineMentions()); emit initializeMentions(cache::getTimelineMentions());
emit syncTags(cache::roomInfo().toStdMap()); emit syncTags(cache::roomInfo().toStdMap());

View File

@ -158,7 +158,7 @@ signals:
void initializeRoomList(QMap<QString, RoomInfo>); void initializeRoomList(QMap<QString, RoomInfo>);
void initializeViews(const mtx::responses::Rooms &rooms); void initializeViews(const mtx::responses::Rooms &rooms);
void initializeEmptyViews(const std::map<QString, mtx::responses::Timeline> &msgs); void initializeEmptyViews(const std::vector<QString> &roomIds);
void initializeMentions(const QMap<QString, mtx::responses::Notifications> &notifs); void initializeMentions(const QMap<QString, mtx::responses::Notifications> &notifs);
void syncUI(const mtx::responses::Rooms &rooms); void syncUI(const mtx::responses::Rooms &rooms);
void syncRoomlist(const std::map<QString, RoomInfo> &updates); void syncRoomlist(const std::map<QString, RoomInfo> &updates);

View File

@ -451,13 +451,10 @@ TimelineViewManager::receivedSessionKey(const std::string &room_id, const std::s
} }
void void
TimelineViewManager::initWithMessages(const std::map<QString, mtx::responses::Timeline> &msgs) TimelineViewManager::initWithMessages(const std::vector<QString> &roomIds)
{ {
for (const auto &e : msgs) { for (const auto &roomId : roomIds)
addRoom(e.first); addRoom(roomId);
models.value(e.first)->addEvents(e.second);
}
} }
void void

View File

@ -94,7 +94,7 @@ signals:
public slots: public slots:
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids); void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
void receivedSessionKey(const std::string &room_id, const std::string &session_id); void receivedSessionKey(const std::string &room_id, const std::string &session_id);
void initWithMessages(const std::map<QString, mtx::responses::Timeline> &msgs); void initWithMessages(const std::vector<QString> &roomIds);
void setHistoryView(const QString &room_id); void setHistoryView(const QString &room_id);
void updateColorPalette(); void updateColorPalette();