mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Keep fetching history until the scrollbar gets activated
This commit is contained in:
parent
748eb949a7
commit
af0f22fc91
5 changed files with 28 additions and 10 deletions
|
@ -56,13 +56,14 @@ public slots:
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString notificationText();
|
QString notificationText();
|
||||||
|
|
||||||
const int Padding = 7;
|
const int Padding = 7;
|
||||||
const int IconSize = 46;
|
const int IconSize = 48;
|
||||||
|
|
||||||
RippleOverlay *ripple_overlay_;
|
RippleOverlay *ripple_overlay_;
|
||||||
|
|
||||||
|
|
|
@ -73,12 +73,12 @@ public:
|
||||||
int addEvents(const Timeline &timeline);
|
int addEvents(const Timeline &timeline);
|
||||||
void addUserTextMessage(const QString &msg, int txn_id);
|
void addUserTextMessage(const QString &msg, int txn_id);
|
||||||
void updatePendingMessage(int txn_id, QString event_id);
|
void updatePendingMessage(int txn_id, QString event_id);
|
||||||
void fetchHistory();
|
|
||||||
void scrollDown();
|
void scrollDown();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void sliderRangeChanged(int min, int max);
|
void sliderRangeChanged(int min, int max);
|
||||||
void sliderMoved(int position);
|
void sliderMoved(int position);
|
||||||
|
void fetchHistory();
|
||||||
|
|
||||||
// Add old events at the top of the timeline.
|
// Add old events at the top of the timeline.
|
||||||
void addBackwardsEvents(const QString &room_id, const RoomMessages &msgs);
|
void addBackwardsEvents(const QString &room_id, const RoomMessages &msgs);
|
||||||
|
@ -118,6 +118,8 @@ private:
|
||||||
|
|
||||||
const int SCROLL_BAR_GAP = 400;
|
const int SCROLL_BAR_GAP = 400;
|
||||||
|
|
||||||
|
QTimer *paginationTimer_;
|
||||||
|
|
||||||
int scroll_height_ = 0;
|
int scroll_height_ = 0;
|
||||||
int previous_max_height_ = 0;
|
int previous_max_height_ = 0;
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
splitter->addWidget(sideBar_);
|
splitter->addWidget(sideBar_);
|
||||||
splitter->addWidget(content_);
|
splitter->addWidget(content_);
|
||||||
|
|
||||||
room_list_ = new RoomList(client, this);
|
room_list_ = new RoomList(client, sideBar_);
|
||||||
sideBarMainLayout_->addWidget(room_list_);
|
sideBarMainLayout_->addWidget(room_list_);
|
||||||
|
|
||||||
top_bar_ = new TopRoomBar(this);
|
top_bar_ = new TopRoomBar(this);
|
||||||
|
|
|
@ -69,6 +69,16 @@ QString RoomInfoListItem::notificationText()
|
||||||
return tr("Enable notifications");
|
return tr("Enable notifications");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RoomInfoListItem::resizeEvent(QResizeEvent *)
|
||||||
|
{
|
||||||
|
// Update ripple's clipping path.
|
||||||
|
QPainterPath path;
|
||||||
|
path.addRect(0, 0, width(), height());
|
||||||
|
|
||||||
|
ripple_overlay_->setClipPath(path);
|
||||||
|
ripple_overlay_->setClipping(true);
|
||||||
|
}
|
||||||
|
|
||||||
void RoomInfoListItem::paintEvent(QPaintEvent *event)
|
void RoomInfoListItem::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
|
|
|
@ -65,8 +65,10 @@ void TimelineView::sliderRangeChanged(int min, int max)
|
||||||
{
|
{
|
||||||
Q_UNUSED(min);
|
Q_UNUSED(min);
|
||||||
|
|
||||||
if (!scroll_area_->verticalScrollBar()->isVisible())
|
if (!scroll_area_->verticalScrollBar()->isVisible()) {
|
||||||
|
scroll_area_->verticalScrollBar()->setValue(max);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (max - scroll_area_->verticalScrollBar()->value() < SCROLL_BAR_GAP)
|
if (max - scroll_area_->verticalScrollBar()->value() < SCROLL_BAR_GAP)
|
||||||
scroll_area_->verticalScrollBar()->setValue(max);
|
scroll_area_->verticalScrollBar()->setValue(max);
|
||||||
|
@ -84,7 +86,6 @@ void TimelineView::sliderRangeChanged(int min, int max)
|
||||||
newPosition = max;
|
newPosition = max;
|
||||||
|
|
||||||
scroll_area_->verticalScrollBar()->setValue(newPosition);
|
scroll_area_->verticalScrollBar()->setValue(newPosition);
|
||||||
fetchHistory();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,11 +93,14 @@ void TimelineView::fetchHistory()
|
||||||
{
|
{
|
||||||
bool hasEnoughMessages = scroll_area_->verticalScrollBar()->value() != 0;
|
bool hasEnoughMessages = scroll_area_->verticalScrollBar()->value() != 0;
|
||||||
|
|
||||||
if (!hasEnoughMessages && !isTimelineFinished && !isPaginationInProgress_) {
|
if (!hasEnoughMessages && !isTimelineFinished) {
|
||||||
isPaginationInProgress_ = true;
|
isPaginationInProgress_ = true;
|
||||||
client_->messages(room_id_, prev_batch_token_);
|
client_->messages(room_id_, prev_batch_token_);
|
||||||
scroll_area_->verticalScrollBar()->setValue(scroll_area_->verticalScrollBar()->maximum());
|
paginationTimer_->start(500);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paginationTimer_->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineView::scrollDown()
|
void TimelineView::scrollDown()
|
||||||
|
@ -169,10 +173,8 @@ void TimelineView::addBackwardsEvents(const QString &room_id, const RoomMessages
|
||||||
oldPosition_ = scroll_area_->verticalScrollBar()->value();
|
oldPosition_ = scroll_area_->verticalScrollBar()->value();
|
||||||
oldHeight_ = scroll_widget_->size().height();
|
oldHeight_ = scroll_widget_->size().height();
|
||||||
|
|
||||||
for (const auto &item : items) {
|
for (const auto &item : items)
|
||||||
item->adjustSize();
|
|
||||||
addTimelineItem(item, TimelineDirection::Top);
|
addTimelineItem(item, TimelineDirection::Top);
|
||||||
}
|
|
||||||
|
|
||||||
prev_batch_token_ = msgs.end();
|
prev_batch_token_ = msgs.end();
|
||||||
isPaginationInProgress_ = false;
|
isPaginationInProgress_ = false;
|
||||||
|
@ -323,6 +325,9 @@ void TimelineView::init()
|
||||||
|
|
||||||
setLayout(top_layout_);
|
setLayout(top_layout_);
|
||||||
|
|
||||||
|
paginationTimer_ = new QTimer(this);
|
||||||
|
connect(paginationTimer_, &QTimer::timeout, this, &TimelineView::fetchHistory);
|
||||||
|
|
||||||
connect(client_.data(), &MatrixClient::messagesRetrieved, this, &TimelineView::addBackwardsEvents);
|
connect(client_.data(), &MatrixClient::messagesRetrieved, this, &TimelineView::addBackwardsEvents);
|
||||||
|
|
||||||
connect(scroll_area_->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sliderMoved(int)));
|
connect(scroll_area_->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sliderMoved(int)));
|
||||||
|
|
Loading…
Reference in a new issue