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;
}
std::map<QString, mtx::responses::Timeline>
Cache::roomMessages()
std::vector<QString>
Cache::roomIds()
{
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;
auto roomsCursor = lmdb::cursor::open(txn, roomsDb_);
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();
txn.commit();
return msgs;
return rooms;
}
QMap<QString, mtx::responses::Notifications>
@ -3967,10 +3967,10 @@ setCurrentFormat()
instance_->setCurrentFormat();
}
std::map<QString, mtx::responses::Timeline>
roomMessages()
std::vector<QString>
roomIds()
{
return instance_->roomMessages();
return instance_->roomIds();
}
QMap<QString, mtx::responses::Notifications>

View file

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

View file

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

View file

@ -158,7 +158,7 @@ signals:
void initializeRoomList(QMap<QString, RoomInfo>);
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 syncUI(const mtx::responses::Rooms &rooms);
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
TimelineViewManager::initWithMessages(const std::map<QString, mtx::responses::Timeline> &msgs)
TimelineViewManager::initWithMessages(const std::vector<QString> &roomIds)
{
for (const auto &e : msgs) {
addRoom(e.first);
models.value(e.first)->addEvents(e.second);
}
for (const auto &roomId : roomIds)
addRoom(roomId);
}
void

View file

@ -94,7 +94,7 @@ signals:
public slots:
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 initWithMessages(const std::map<QString, mtx::responses::Timeline> &msgs);
void initWithMessages(const std::vector<QString> &roomIds);
void setHistoryView(const QString &room_id);
void updateColorPalette();