Handle some more edge cases in timeline

pull/1/head
Konstantinos Sideris 6 years ago
parent d608950bea
commit 641364c105
  1. 10
      src/ChatPage.cpp
  2. 30
      src/timeline/TimelineView.cpp
  3. 2
      src/timeline/TimelineView.h

@ -1110,9 +1110,15 @@ ChatPage::createRoom(const mtx::requests::CreateRoom &req)
http::client()->create_room(
req, [this](const mtx::responses::CreateRoom &res, mtx::http::RequestErr err) {
if (err) {
const auto err_code = mtx::errors::to_string(err->matrix_error.errcode);
const auto error = err->matrix_error.error;
const int status_code = static_cast<int>(err->status_code);
nhlog::net()->warn(
"failed to create room: {} {} ({})", error, err_code, status_code);
emit showNotification(
tr("Room creation failed: %1")
.arg(QString::fromStdString(err->matrix_error.error)));
tr("Room creation failed: %1").arg(QString::fromStdString(error)));
return;
}

@ -164,11 +164,19 @@ TimelineView::sliderMoved(int position)
}
}
bool
TimelineView::isStartOfTimeline(const mtx::responses::Messages &msgs)
{
return (msgs.chunk.size() == 0 && (msgs.end.empty() || msgs.end == msgs.start));
}
void
TimelineView::addBackwardsEvents(const mtx::responses::Messages &msgs)
{
// We've reached the start of the timline and there're no more messages.
if (msgs.end.empty() || ((msgs.end == msgs.start) && msgs.chunk.size() == 0)) {
if (isStartOfTimeline(msgs)) {
nhlog::ui()->info("[{}] start of timeline reached, no more messages to fetch",
room_id_.toStdString());
isTimelineFinished = true;
return;
}
@ -562,6 +570,13 @@ TimelineView::init()
void
TimelineView::getMessages()
{
if (prev_batch_token_.isEmpty()) {
nhlog::ui()->info("[{}] start of timeline reached, prev_batch token is empty",
room_id_.toStdString());
isTimelineFinished = true;
return;
}
mtx::http::MessagesOpts opts;
opts.room_id = room_id_.toStdString();
opts.from = prev_batch_token_.toStdString();
@ -829,13 +844,22 @@ TimelineView::sendNextPendingMessage()
void
TimelineView::notifyForLastEvent()
{
auto lastItem = scroll_layout_->itemAt(scroll_layout_->count() - 1);
if (scroll_layout_->count() == 0) {
nhlog::ui()->error("notifyForLastEvent called with empty timeline");
return;
}
auto lastItem = scroll_layout_->itemAt(scroll_layout_->count() - 1);
if (!lastItem)
return;
auto *lastTimelineItem = qobject_cast<TimelineItem *>(lastItem->widget());
if (lastTimelineItem)
emit updateLastTimelineMessage(room_id_, lastTimelineItem->descriptionMessage());
else
nhlog::ui()->warn("cast to TimelineView failed: {}", room_id_.toStdString());
nhlog::ui()->warn("cast to TimelineItem failed: {}", room_id_.toStdString());
}
void

@ -169,6 +169,8 @@ private:
//! Mark our own widgets as read if they have more than one receipt.
void displayReadReceipts(std::vector<TimelineEvent> events);
//! Determine if the start of the timeline is reached from the response of /messages.
bool isStartOfTimeline(const mtx::responses::Messages &msgs);
QWidget *relativeWidget(QWidget *item, int dt) const;

Loading…
Cancel
Save