Line to indicate first unread message (#1147)

* First draft of unread line feature.

* Minor visual fix.

* Removed unnecessary ternary operator.

* Extended unread line functionality to work on minimised window or focusing another window.

* Fix for unread line not showing when last read message is hidden.

* Minor performance improvement. Fix for misbehaving event2order DB at application start.

* Fix for possible performance issues when user has joined a large number of rooms.

* Fix for breaking macos and clazy builds.

* Changed on windows focus function to refresh unread line if room is unread.

* Unread line is removed when user sends a message.

* Linting.

* Fixed unread line to work in standalone room windows.

* Switch isRoomUnread for index 0.

* Merged try/catch blocks.

* Fix for crash on opening a room invite.

* Call fullyReadEventId function when used instead of storing it and passing it through.

* Function that was meant to sync the unread line was relying on an async function, oops.

* Linting again.

* More linting...

* Minor changes.
This commit is contained in:
Hiers 2022-09-11 23:05:20 +00:00 committed by GitHub
parent 02adcfdc38
commit 8071b192b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 172 additions and 20 deletions

View file

@ -427,6 +427,7 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
setPaginationInProgress(false);
updateLastMessage();
});
connect(&events, &EventStore::fetchedMore, this, &TimelineModel::checkAfterFetch);
connect(&events,
&EventStore::startDMVerification,
this,
@ -977,6 +978,7 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
emit encryptionChanged();
}
}
updateLastMessage();
}
@ -1370,6 +1372,48 @@ TimelineModel::markEventsAsRead(const std::vector<QString> &event_ids)
}
}
void
TimelineModel::updateLastReadId(QString currentRoomId)
{
if (currentRoomId == room_id_) {
last_event_id = cache::getFullyReadEventId(room_id_.toStdString());
auto lastVisibleEventIndexAndId =
cache::lastVisibleEvent(room_id_.toStdString(), last_event_id);
if (lastVisibleEventIndexAndId) {
fullyReadEventId_ = lastVisibleEventIndexAndId->second;
emit fullyReadEventIdChanged();
}
}
}
void
TimelineModel::lastReadIdOnWindowFocus()
{
/* this stops it from removing the line when focusing another window
* and from removing the line when refocusing nheko */
if (ChatPage::instance()->isRoomActive(room_id_) &&
cache::calculateRoomReadStatus(room_id_.toStdString())) {
updateLastReadId(room_id_);
}
}
/*
* if the event2order db didn't have the messages we needed when the room was opened
* try again after these new messages were fetched
*/
void
TimelineModel::checkAfterFetch()
{
if (fullyReadEventId_.empty()) {
auto lastVisibleEventIndexAndId =
cache::lastVisibleEvent(room_id_.toStdString(), last_event_id);
if (lastVisibleEventIndexAndId) {
fullyReadEventId_ = lastVisibleEventIndexAndId->second;
emit fullyReadEventIdChanged();
}
}
}
template<typename T>
void
TimelineModel::sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::EventType eventType)
@ -1550,6 +1594,9 @@ TimelineModel::addPendingMessage(mtx::events::collections::TimelineEvents event)
event);
std::visit(SendMessageVisitor{this}, event);
fullyReadEventId_ = this->EventId;
emit fullyReadEventIdChanged();
}
void