diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 4bb7b497..9596d561 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -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(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; } diff --git a/src/timeline/TimelineView.cpp b/src/timeline/TimelineView.cpp index 6eb553e8..a77bae6a 100644 --- a/src/timeline/TimelineView.cpp +++ b/src/timeline/TimelineView.cpp @@ -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(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 diff --git a/src/timeline/TimelineView.h b/src/timeline/TimelineView.h index 0d18c7fe..46facd7e 100644 --- a/src/timeline/TimelineView.h +++ b/src/timeline/TimelineView.h @@ -169,6 +169,8 @@ private: //! Mark our own widgets as read if they have more than one receipt. void displayReadReceipts(std::vector 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;