From 9d90467e6a91cd647643c35a90cb18f9666bc5a3 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 4 Feb 2020 21:16:04 +0100 Subject: [PATCH] Select first room on startup --- src/RoomList.cpp | 15 ++++++++++----- src/popups/SuggestionsPopup.h | 3 ++- src/timeline/TimelineModel.h | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/RoomList.cpp b/src/RoomList.cpp index b90c8fa4..a80e0757 100644 --- a/src/RoomList.cpp +++ b/src/RoomList.cpp @@ -158,6 +158,8 @@ RoomList::initialize(const QMap &info) if (rooms_.empty()) return; + sortRoomsByLastMessage(); + auto room = firstRoom(); if (room.second.isNull()) return; @@ -479,13 +481,16 @@ RoomList::addInvitedRoom(const QString &room_id, const RoomInfo &info) std::pair> RoomList::firstRoom() const { - auto firstRoom = rooms_.begin(); + for (int i = 0; i < contentsLayout_->count(); i++) { + auto item = qobject_cast(contentsLayout_->itemAt(i)->widget()); - while (firstRoom->second.isNull() && firstRoom != rooms_.end()) - firstRoom++; + if (item) { + return std::pair>( + item->roomId(), rooms_.at(item->roomId())); + } + } - return std::pair>(firstRoom->first, - firstRoom->second); + return {}; } void diff --git a/src/popups/SuggestionsPopup.h b/src/popups/SuggestionsPopup.h index f84870e7..63c44538 100644 --- a/src/popups/SuggestionsPopup.h +++ b/src/popups/SuggestionsPopup.h @@ -59,7 +59,8 @@ private: size_t posToRemove = layout_->count() - 1; QLayoutItem *item; - while (startingPos <= posToRemove && (item = layout_->takeAt(posToRemove)) != nullptr) { + while (startingPos <= posToRemove && + (item = layout_->takeAt(posToRemove)) != nullptr) { delete item->widget(); delete item; diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 2d0e9627..642e9bbc 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -126,7 +126,9 @@ class TimelineModel : public QAbstractListModel typingUsersChanged) public: - explicit TimelineModel(TimelineViewManager *manager, QString room_id, QObject *parent = nullptr); + explicit TimelineModel(TimelineViewManager *manager, + QString room_id, + QObject *parent = nullptr); enum Roles {