Improve read marker
- Update from deprecated readMarkerEventId to lastFullyReadEventId for quotient 0.7. - Removed duplicate code for marking read from the read marker delegate. - Make sure that mark as read only trigger at the end of the timeline - Allow the read marker to be highlighted when jumped to
This commit is contained in:
@@ -102,7 +102,11 @@ void MessageEventModel::setRoom(NeoChatRoom *room)
|
|||||||
if (m_currentRoom->timelineSize() < 10 && !room->allHistoryLoaded()) {
|
if (m_currentRoom->timelineSize() < 10 && !room->allHistoryLoaded()) {
|
||||||
room->getPreviousContent(50);
|
room->getPreviousContent(50);
|
||||||
}
|
}
|
||||||
|
#ifdef QUOTIENT_07
|
||||||
|
lastReadEventId = room->lastFullyReadEventId();
|
||||||
|
#else
|
||||||
lastReadEventId = room->readMarkerEventId();
|
lastReadEventId = room->readMarkerEventId();
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
connect(m_currentRoom, &Room::aboutToAddNewMessages, this, [this](RoomEventsRange events) {
|
connect(m_currentRoom, &Room::aboutToAddNewMessages, this, [this](RoomEventsRange events) {
|
||||||
@@ -151,7 +155,11 @@ void MessageEventModel::setRoom(NeoChatRoom *room)
|
|||||||
endInsertRows();
|
endInsertRows();
|
||||||
if (!m_lastReadEventIndex.isValid()) {
|
if (!m_lastReadEventIndex.isValid()) {
|
||||||
// no read marker, so see if we need to create one.
|
// no read marker, so see if we need to create one.
|
||||||
|
#ifdef QUOTIENT_07
|
||||||
|
moveReadMarker(m_currentRoom->lastFullyReadEventId());
|
||||||
|
#else
|
||||||
moveReadMarker(m_currentRoom->readMarkerEventId());
|
moveReadMarker(m_currentRoom->readMarkerEventId());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (biggest < m_currentRoom->maxTimelineIndex()) {
|
if (biggest < m_currentRoom->maxTimelineIndex()) {
|
||||||
auto rowBelowInserted = m_currentRoom->maxTimelineIndex() - biggest + timelineBaseIndex() - 1;
|
auto rowBelowInserted = m_currentRoom->maxTimelineIndex() - biggest + timelineBaseIndex() - 1;
|
||||||
|
|||||||
@@ -851,7 +851,11 @@ bool NeoChatRoom::canSendState(const QString &eventType) const
|
|||||||
|
|
||||||
bool NeoChatRoom::readMarkerLoaded() const
|
bool NeoChatRoom::readMarkerLoaded() const
|
||||||
{
|
{
|
||||||
|
#ifdef QUOTIENT_07
|
||||||
|
const auto it = findInTimeline(lastFullyReadEventId());
|
||||||
|
#else
|
||||||
const auto it = findInTimeline(readMarkerEventId());
|
const auto it = findInTimeline(readMarkerEventId());
|
||||||
|
#endif
|
||||||
return it != historyEdge();
|
return it != historyEdge();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,17 @@ QQC2.ItemDelegate {
|
|||||||
readonly property int extraWidth: messageListView.width >= Kirigami.Units.gridUnit * 46 ? Math.min((messageListView.width - Kirigami.Units.gridUnit * 46), Kirigami.Units.gridUnit * 20) : 0
|
readonly property int extraWidth: messageListView.width >= Kirigami.Units.gridUnit * 46 ? Math.min((messageListView.width - Kirigami.Units.gridUnit * 46), Kirigami.Units.gridUnit * 20) : 0
|
||||||
readonly property int delegateMaxWidth: Config.compactLayout ? messageListView.width - Kirigami.Units.largeSpacing * 2 : Math.min(messageListView.width - Kirigami.Units.largeSpacing * 2, Kirigami.Units.gridUnit * 40 + extraWidth)
|
readonly property int delegateMaxWidth: Config.compactLayout ? messageListView.width - Kirigami.Units.largeSpacing * 2 : Math.min(messageListView.width - Kirigami.Units.largeSpacing * 2, Kirigami.Units.gridUnit * 40 + extraWidth)
|
||||||
|
|
||||||
|
property bool isTemporaryHighlighted: false
|
||||||
|
|
||||||
|
onIsTemporaryHighlightedChanged: if (isTemporaryHighlighted) temporaryHighlightTimer.start()
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: temporaryHighlightTimer
|
||||||
|
|
||||||
|
interval: 1500
|
||||||
|
onTriggered: isTemporaryHighlighted = false
|
||||||
|
}
|
||||||
|
|
||||||
width: delegateMaxWidth
|
width: delegateMaxWidth
|
||||||
anchors.leftMargin: Kirigami.Units.largeSpacing
|
anchors.leftMargin: Kirigami.Units.largeSpacing
|
||||||
anchors.rightMargin: Kirigami.Units.largeSpacing
|
anchors.rightMargin: Kirigami.Units.largeSpacing
|
||||||
@@ -59,58 +70,22 @@ QQC2.ItemDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
background: Kirigami.ShadowedRectangle {
|
background: Kirigami.ShadowedRectangle {
|
||||||
color: Kirigami.Theme.backgroundColor
|
color: {
|
||||||
opacity: 0.6
|
if (readMarkerDelegate.isTemporaryHighlighted) {
|
||||||
|
return Kirigami.Theme.positiveBackgroundColor
|
||||||
|
} else {
|
||||||
|
return Kirigami.Theme.backgroundColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
opacity: readMarkerDelegate.isTemporaryHighlighted ? 1 : 0.6
|
||||||
radius: Kirigami.Units.smallSpacing
|
radius: Kirigami.Units.smallSpacing
|
||||||
shadow.size: Kirigami.Units.smallSpacing
|
shadow.size: Kirigami.Units.smallSpacing
|
||||||
shadow.color: Qt.rgba(0.0, 0.0, 0.0, 0.10)
|
shadow.color: Qt.rgba(0.0, 0.0, 0.0, 0.10)
|
||||||
border.color: Kirigami.ColorUtils.tintWithAlpha(color, Kirigami.Theme.textColor, 0.15)
|
border.color: Kirigami.ColorUtils.tintWithAlpha(color, Kirigami.Theme.textColor, 0.15)
|
||||||
border.width: 1
|
border.width: 1
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
Behavior on color {
|
||||||
id: makeMeDisapearTimer
|
ColorAnimation {target: bubbleBackground; duration: Kirigami.Units.veryLongDuration; easing.type: Easing.InOutCubic}
|
||||||
interval: Kirigami.Units.humanMoment * 2
|
|
||||||
onTriggered: if (QQC2.ApplicationWindow.window.visibility !== QQC2.ApplicationWindow.Hidden) {
|
|
||||||
currentRoom.markAllMessagesAsRead();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ListView.onPooled: makeMeDisapearTimer.stop()
|
|
||||||
|
|
||||||
ListView.onAdd: {
|
|
||||||
const view = ListView.view;
|
|
||||||
if (view.atYEnd) {
|
|
||||||
makeMeDisapearTimer.start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the read marker is visible and we are at the end of the list,
|
|
||||||
// start the makeMeDisapearTimer
|
|
||||||
Connections {
|
|
||||||
target: ListView.view
|
|
||||||
function onAtYEndChanged() {
|
|
||||||
makeMeDisapearTimer.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ListView.onRemove: {
|
|
||||||
const view = ListView.view;
|
|
||||||
|
|
||||||
if (view.atYEnd) {
|
|
||||||
// easy case just mark everything as read
|
|
||||||
if (QQC2.ApplicationWindow.window.visibility !== QQC2.ApplicationWindow.Hidden) {
|
|
||||||
currentRoom.markAllMessagesAsRead();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// mark the last visible index
|
|
||||||
const lastVisibleIdx = lastVisibleIndex();
|
|
||||||
|
|
||||||
if (lastVisibleIdx < index) {
|
|
||||||
currentRoom.readMarkerEventId = sortedMessageEventModel.data(sortedMessageEventModel.index(lastVisibleIdx, 0), MessageEventModel.EventIdRole)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -649,7 +649,7 @@ Kirigami.ScrollablePage {
|
|||||||
// Mark all messages as read if all unread messages are visible to the user
|
// Mark all messages as read if all unread messages are visible to the user
|
||||||
function markReadIfVisible() {
|
function markReadIfVisible() {
|
||||||
let readMarkerRow = eventToIndex(currentRoom.readMarkerEventId)
|
let readMarkerRow = eventToIndex(currentRoom.readMarkerEventId)
|
||||||
if (readMarkerRow > 0 && readMarkerRow < firstVisibleIndex()) {
|
if (readMarkerRow > 0 && readMarkerRow < firstVisibleIndex() && messageListView.atYEnd) {
|
||||||
currentRoom.markAllMessagesAsRead()
|
currentRoom.markAllMessagesAsRead()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user