diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp
index 1e0b4c23..972f061d 100644
--- a/src/timeline/RoomlistModel.cpp
+++ b/src/timeline/RoomlistModel.cpp
@@ -121,7 +121,7 @@ RoomlistModel::data(const QModelIndex &index, int role) const
case Roles::Time:
return room->lastMessage().descriptiveTime;
case Roles::Timestamp:
- return QVariant{static_cast<quint64>(room->lastMessage().timestamp)};
+ return QVariant{static_cast<quint64>(room->lastMessageTimestamp())};
case Roles::HasUnreadMessages:
return this->roomReadStatus.count(roomid) && this->roomReadStatus.at(roomid);
case Roles::HasLoudNotification:
@@ -333,7 +333,7 @@ RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification)
emit totalUnreadMessageCountUpdated(total_unread_msgs);
});
- newRoom->updateLastMessage();
+ // newRoom->updateLastMessage();
std::vector<QString> previewsToAdd;
if (newRoom->isSpace()) {
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 142ca793..578d63b7 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -353,14 +353,13 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
, manager_(manager)
, permissions_{room_id_}
{
- lastMessage_.timestamp = 0;
-
this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
auto roomInfo = cache::singleRoomInfo(room_id_.toStdString());
this->isSpace_ = roomInfo.is_space;
this->notification_count = roomInfo.notification_count;
this->highlight_count = roomInfo.highlight_count;
+ lastMessage_.timestamp = roomInfo.approximate_last_modification_ts;
// this connection will simplify adding the plainRoomNameChanged() signal everywhere that it
// needs to be
@@ -1025,10 +1024,21 @@ isYourJoin(const mtx::events::Event<T> &)
return false;
}
+DescInfo
+TimelineModel::lastMessage() const
+{
+ if (lastMessage_.event_id.isEmpty())
+ QTimer::singleShot(0, this, &TimelineModel::updateLastMessage);
+
+ return lastMessage_;
+}
+
void
TimelineModel::updateLastMessage()
{
- for (auto it = events.size() - 1; it >= 0; --it) {
+ // only try to generate a preview for the last 1000 messages
+ auto end = std::max(events.size() - 1001, 0);
+ for (auto it = events.size() - 1; it >= end; --it) {
auto event = events.get(it, decryptDescription);
if (!event)
continue;
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index dae64094..ec9a34f1 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -311,7 +311,9 @@ public:
void sendMessageEvent(const T &content, mtx::events::EventType eventType);
RelatedInfo relatedInfo(const QString &id);
- DescInfo lastMessage() const { return lastMessage_; }
+ DescInfo lastMessage() const;
+ uint64_t lastMessageTimestamp() const { return lastMessage_.timestamp; }
+
bool isSpace() const { return isSpace_; }
bool isEncrypted() const { return isEncrypted_; }
crypto::Trust trustlevel() const;
|