Improve the 'jump to last read message' button

When loading a room, automatically load messages until the last read
message is loaded #35
Don't show the button if the message is not loaded
This commit is contained in:
Tobias Fella
2020-11-25 22:09:04 +01:00
parent 48521d8c8e
commit 49881f809d
4 changed files with 26 additions and 1 deletions

View File

@@ -329,7 +329,7 @@ Kirigami.ScrollablePage {
id: goReadMarkerFab
visible: currentRoom && currentRoom.hasUnreadMessages || !messageListView.atYEnd
visible: currentRoom && currentRoom.hasUnreadMessages && currentRoom.readMarkerLoaded || !messageListView.atYEnd
action: Kirigami.Action {
onTriggered: {
if (currentRoom && currentRoom.hasUnreadMessages) {

View File

@@ -55,6 +55,19 @@ MessageEventModel::MessageEventModel(QObject *parent)
qmlRegisterAnonymousType<FileTransferInfo>("org.kde.neochat", 1);
qRegisterMetaType<FileTransferInfo>();
qmlRegisterUncreatableType<EventStatus>("org.kde.neochat", 1, 0, "EventStatus", "EventStatus is not an creatable type");
QTimer::singleShot(0, this, [=]() {
m_currentRoom->getPreviousContent(50);
connect(this, &QAbstractListModel::rowsInserted, this, [=](){
if(m_currentRoom->readMarkerEventId().isEmpty()) {
return;
}
const auto it = m_currentRoom->findInTimeline(m_currentRoom->readMarkerEventId());
if (it == m_currentRoom->timelineEdge()) {
m_currentRoom->getPreviousContent(50);
}
});
});
}
MessageEventModel::~MessageEventModel()

View File

@@ -56,6 +56,8 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
NotificationsManager::instance().postNotification(id(), lastEvent->id(), displayName(), sender->displayname(this), eventToString(*lastEvent), avatar(128));
});
connect(this, &Room::aboutToAddHistoricalMessages, this, &NeoChatRoom::readMarkerLoadedChanged);
}
void NeoChatRoom::uploadFile(const QUrl &url, const QString &body)
@@ -613,3 +615,9 @@ bool NeoChatRoom::canSendState(const QString &eventType) const
return currentPl >= pl;
}
bool NeoChatRoom::readMarkerLoaded() const
{
const auto it = findInTimeline(readMarkerEventId());
return it != timelineEdge();
}

View File

@@ -30,6 +30,7 @@ class NeoChatRoom : public Room
Q_PROPERTY(bool hasFileUploading READ hasFileUploading WRITE setHasFileUploading NOTIFY hasFileUploadingChanged)
Q_PROPERTY(int fileUploadingProgress READ fileUploadingProgress NOTIFY fileUploadingProgressChanged)
Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged STORED false)
Q_PROPERTY(bool readMarkerLoaded READ readMarkerLoaded NOTIFY readMarkerLoadedChanged)
public:
explicit NeoChatRoom(Connection *connection, QString roomId, JoinState joinState = {});
@@ -67,6 +68,8 @@ public:
Q_EMIT fileUploadingProgressChanged();
}
bool readMarkerLoaded() const;
Q_INVOKABLE int savedTopVisibleIndex() const;
Q_INVOKABLE int savedBottomVisibleIndex() const;
Q_INVOKABLE void saveViewport(int topIndex, int bottomIndex);
@@ -108,6 +111,7 @@ Q_SIGNALS:
void hasFileUploadingChanged();
void fileUploadingProgressChanged();
void backgroundChanged();
void readMarkerLoadedChanged();
public Q_SLOTS:
void uploadFile(const QUrl &url, const QString &body = "");