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:
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 = "");
|
||||
|
||||
Reference in New Issue
Block a user