Skip to content
Snippets Groups Projects
Commit ff51895e authored by Nicolas Werner's avatar Nicolas Werner
Browse files

[konheko] Reverse timeline internally to make messages stick to the bottom properly

parent 406b32e4
No related branches found
No related tags found
No related merge requests found
......@@ -28,9 +28,6 @@ Page {
SilicaListView {
id: chatView
property bool atEnd: false
property int maxIndex: -1
height: parent.height - header.height
contentHeight: height
cacheBuffer: 1000
......@@ -39,18 +36,12 @@ Page {
boundsBehavior: Flickable.StopAtBounds
anchors.left: parent.left
anchors.right: parent.right
ListView.onAdd: {
console.log("atYEnd::" + atYEnd);
atEnd = atYEnd;
}
onCountChanged: {
console.log("atEnd::" + atEnd);
if (atEnd) {
scrollToBottom();
}
}
verticalLayoutDirection: ListView.BottomToTop
Component.onCompleted: positionViewAtIndex(room.lastRead(), ListView.Contain);
onMovementEnded: {
atEnd = false;
console.log("movement ended");
if (chatView.atYBeginning) {
console.log("load older messages");
......@@ -58,38 +49,19 @@ Page {
}
if (chatView.atYEnd) {
console.log("at end");
atEnd = true;
room.markRead(0)
} else {
console.log("not at end");
atEnd = false;
}
var lastIndex = maxIndex;
for (var child in chatView.contentItem.children) {
if (chatView.contentItem.children[child].isFullyVisible && chatView.contentItem.children[child].index > maxIndex)
lastIndex = chatView.contentItem.children[child].index;
}
if (lastIndex > maxIndex)
maxIndex = lastIndex;
}
onMaxIndexChanged: {
console.log("max index: " + maxIndex);
room.markRead(maxIndex);
}
Component.onCompleted: {
maxIndex = room.lastRead();
if (maxIndex = count - 1)
atEnd = true;
positionViewAtIndex(maxIndex, ListView.Contain);
}
ScrollDecorator {
flickable: chatView
}
footer: Row {
// reverse order, so this has to be the header instead of footer
header: Row {
anchors.left: parent.left
anchors.right: parent.right
height: messageText.height
......@@ -108,7 +80,7 @@ Page {
IconButton {
id: sendButton
anchors.top: parent.top
anchors.bottom: parent.bottom
icon.source: "image://theme/icon-m-send"
onClicked: {
if (messageText.text != "")
......
......@@ -274,8 +274,8 @@ void Room::addEvents(std::vector<mtx::events::collections::StateEvents> state,
}
if (!timeline.empty()) {
beginInsertRows(QModelIndex(), (int)0, (int)timeline.size() - 1);
this->events.insert(this->events.begin(), timeline.begin(), timeline.end());
beginInsertRows(QModelIndex(), (int)events.size(), (int)events.size() + timeline.size() - 1);
this->events.insert(this->events.end(), timeline.rbegin(), timeline.rend());
endInsertRows();
}
this->prev_batch = prev_batch;
......@@ -347,30 +347,16 @@ void Room::addEvents(std::vector<mtx::events::collections::StateEvents> state,
}
};
for (const mtx::events::collections::StateEvents &e : state)
for (const auto &e : state)
std::visit(applyEvent, e);
// applyEvent(e.subset<mtx::events::StateEvent<mtx::events::state::Aliases>,
// mtx::events::StateEvent<mtx::events::state::Avatar>,
// mtx::events::StateEvent<mtx::events::state::CanonicalAlias>,
// mtx::events::StateEvent<mtx::events::state::Create>,
// mtx::events::StateEvent<mtx::events::state::Encryption>,
// mtx::events::StateEvent<mtx::events::state::GuestAccess>,
// mtx::events::StateEvent<mtx::events::state::HistoryVisibility>,
// mtx::events::StateEvent<mtx::events::state::JoinRules>,
// mtx::events::StateEvent<mtx::events::state::Member>,
// mtx::events::StateEvent<mtx::events::state::Name>,
// mtx::events::StateEvent<mtx::events::state::PinnedEvents>,
// mtx::events::StateEvent<mtx::events::state::PowerLevels>,
// mtx::events::StateEvent<mtx::events::state::Tombstone>,
// mtx::events::StateEvent<mtx::events::state::Topic>>());
for (const mtx::events::collections::TimelineEvents &e : timeline)
for (const auto &e : timeline)
std::visit(applyEvent, e);
if (!timeline.empty()) {
qDebug() << "New events at end of timeline";
beginInsertRows(QModelIndex(), (int)this->events.size(), (int)this->events.size() + timeline.size() - 1);
this->events.insert(this->events.end(), timeline.begin(), timeline.end());
beginInsertRows(QModelIndex(), (int)0, (int)timeline.size() - 1);
this->events.insert(this->events.begin(), timeline.rbegin(), timeline.rend());
endInsertRows();
}
this->next_batch = next_batch;
......@@ -675,10 +661,10 @@ int Room::lastReadSlot() {
if (lastRead_.empty())
return 0;
for (size_t index = events.size(); index > 0; index--) {
auto event_id = std::visit([](const auto &e) -> std::string { return eventEventId(e); }, events[index - 1]);
for (size_t index = 0; index < events.size(); index--) {
auto event_id = std::visit([](const auto &e) -> std::string { return eventEventId(e); }, events[index]);
if (event_id == lastRead_)
return index - 1;
return index;
}
qWarning() << "Last read event " << QString::fromStdString(lastRead_) << " not found in events";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment