Scroll to the bottom of the conversation when receive new messages.

This commit is contained in:
Pierre HUBERT 2019-01-10 03:06:39 +01:00
parent aa334d0110
commit 22eec97796
3 changed files with 17 additions and 1 deletions

View File

@ -17,7 +17,7 @@ public:
ConversationMessagesList();
/**
* Get the ID of the oldest message of
* Get the ID of the newest message of
* the conversation
*
* @return The ID of the message / -1 in case of failure

View File

@ -2,6 +2,7 @@
#include <algorithm>
#include <QTimer>
#include <QFileDialog>
#include <QScrollBar>
#include "conversationwidget.h"
#include "ui_conversationwidget.h"
@ -136,6 +137,16 @@ void ConversationWidget::getMessagesCallback(bool success, QList<ConversationMes
it++;
}
//Scroll to the end of the widget if required
if(list.at(list.count()-1).iD() == mMessages.getLastMessageID())
QTimer::singleShot(1000, this, &ConversationWidget::scrollToBottom);
}
void ConversationWidget::scrollToBottom()
{
ui->scrollArea->verticalScrollBar()->setValue(
ui->scrollArea->verticalScrollBar()->maximum());
}
void ConversationWidget::sendMessageCallback(bool success)

View File

@ -59,6 +59,11 @@ private slots:
*/
void getMessagesCallback(bool success, QList<ConversationMessage> list);
/**
* Scroll to the bottom of the conversation
*/
void scrollToBottom();
/**
* Method called once the server replied to a send conversation
* message request