Skip to content

Commit

Permalink
Ensure chat continues to follow new messages even after pool overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Aldrog committed Oct 29, 2016
1 parent 5af8de9 commit d7593ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions sailfish-ui/pages/StreamPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,21 @@ Page {
}
}

// This makes sure individual messages don't get lost
onAtYEndChanged: {
if(atEnd && !atYEnd)
currentIndex = chat.count - 1
}

model: twitchChat.messages
delegate: Item {
height: lbl.height
width: chat.width

property bool viewed: false

// This is the main handler for chat autoscroll, though it only works when messages count's increased
// above there's additional handler covering this case
ListView.onAdd: {
if(!viewed && chat.atEnd) {
chat.currentIndex = chat.count - 1
Expand Down
7 changes: 5 additions & 2 deletions src/messagelistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ QVariant MessageListModel::data(const QModelIndex &index, int role) const {
}

void MessageListModel::appendMessage(Message &message) {
if(rowCount() > MAX_MESSAGE_POOL) {
beginRemoveRows(QModelIndex(), 0, 0);
// When message pool's overflowed, we remove two messages on every second received message
// this way we can be sure that at least every second message addition increases messages count (which makes handling on QML side easier)
if(rowCount() > MAX_MESSAGE_POOL && rowCount() % 2 == 0) {
beginRemoveRows(QModelIndex(), 0, 1);
messageList.removeFirst();
messageList.removeFirst();
endRemoveRows();
}
Expand Down

0 comments on commit d7593ae

Please sign in to comment.