Merge remote-tracking branch 'origin/master'

This commit is contained in:
RiotTranslate 2017-06-06 14:13:02 +00:00
commit 13861fa34e
8 changed files with 40 additions and 20 deletions

View File

@ -44,7 +44,7 @@ public:
void fetchUserAvatar(const QString &userId, const QUrl &avatarUrl); void fetchUserAvatar(const QString &userId, const QUrl &avatarUrl);
void fetchOwnAvatar(const QUrl &avatar_url); void fetchOwnAvatar(const QUrl &avatar_url);
void downloadImage(const QString &event_id, const QUrl &url); void downloadImage(const QString &event_id, const QUrl &url);
void messages(const QString &room_id, const QString &from_token) noexcept; void messages(const QString &room_id, const QString &from_token, int limit = 20) noexcept;
inline QUrl getHomeServer(); inline QUrl getHomeServer();
inline int transactionId(); inline int transactionId();

View File

@ -104,4 +104,5 @@ inline RoomState RoomInfoListItem::state() const
inline void RoomInfoListItem::setAvatar(const QImage &img) inline void RoomInfoListItem::setAvatar(const QImage &img)
{ {
roomAvatar_ = QPixmap::fromImage(img.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); roomAvatar_ = QPixmap::fromImage(img.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
update();
} }

View File

@ -111,12 +111,16 @@ private:
bool isInitialized = false; bool isInitialized = false;
bool isTimelineFinished = false; bool isTimelineFinished = false;
bool isInitialSync = true; bool isInitialSync = true;
bool isPaginationScrollPending_ = false;
const int SCROLL_BAR_GAP = 300; const int SCROLL_BAR_GAP = 400;
int scroll_height_ = 0; int scroll_height_ = 0;
int previous_max_height_ = 0; int previous_max_height_ = 0;
int oldPosition_;
int oldHeight_;
QList<PendingMessage> pending_msgs_; QList<PendingMessage> pending_msgs_;
QSharedPointer<MatrixClient> client_; QSharedPointer<MatrixClient> client_;
}; };

View File

@ -541,7 +541,7 @@ void MatrixClient::initialSync() noexcept
}; };
QJsonObject filter{{"room", QJsonObject filter{{"room",
QJsonObject{{"timeline", QJsonObject{{"limit", 70}}}, QJsonObject{{"timeline", QJsonObject{{"limit", 20}}},
{"ephemeral", QJsonObject{{"limit", 0}}}}}, {"ephemeral", QJsonObject{{"limit", 0}}}}},
{"presence", QJsonObject{{"not_types", excluded_presence}}}}; {"presence", QJsonObject{{"not_types", excluded_presence}}}};
@ -677,12 +677,13 @@ void MatrixClient::fetchOwnAvatar(const QUrl &avatar_url)
reply->setProperty("endpoint", static_cast<int>(Endpoint::GetOwnAvatar)); reply->setProperty("endpoint", static_cast<int>(Endpoint::GetOwnAvatar));
} }
void MatrixClient::messages(const QString &room_id, const QString &from_token) noexcept void MatrixClient::messages(const QString &room_id, const QString &from_token, int limit) noexcept
{ {
QUrlQuery query; QUrlQuery query;
query.addQueryItem("access_token", token_); query.addQueryItem("access_token", token_);
query.addQueryItem("from", from_token); query.addQueryItem("from", from_token);
query.addQueryItem("dir", "b"); query.addQueryItem("dir", "b");
query.addQueryItem("limit", QString::number(limit));
QUrl endpoint(server_); QUrl endpoint(server_);
endpoint.setPath(api_url_ + QString("/rooms/%1/messages").arg(room_id)); endpoint.setPath(api_url_ + QString("/rooms/%1/messages").arg(room_id));

View File

@ -189,13 +189,13 @@ void RoomInfoListItem::paintEvent(QPaintEvent *event)
void RoomInfoListItem::updateUnreadMessageCount(int count) void RoomInfoListItem::updateUnreadMessageCount(int count)
{ {
unreadMsgCount_ += count; unreadMsgCount_ += count;
repaint(); update();
} }
void RoomInfoListItem::clearUnreadMessageCount() void RoomInfoListItem::clearUnreadMessageCount()
{ {
unreadMsgCount_ = 0; unreadMsgCount_ = 0;
repaint(); update();
} }
void RoomInfoListItem::setPressedState(bool state) void RoomInfoListItem::setPressedState(bool state)
@ -212,7 +212,7 @@ void RoomInfoListItem::setPressedState(bool state)
void RoomInfoListItem::setState(const RoomState &new_state) void RoomInfoListItem::setState(const RoomState &new_state)
{ {
state_ = new_state; state_ = new_state;
repaint(); update();
} }
void RoomInfoListItem::contextMenuEvent(QContextMenuEvent *event) void RoomInfoListItem::contextMenuEvent(QContextMenuEvent *event)

View File

@ -24,6 +24,7 @@ Splitter::Splitter(QWidget *parent)
: QSplitter(parent) : QSplitter(parent)
{ {
connect(this, &QSplitter::splitterMoved, this, &Splitter::onSplitterMoved); connect(this, &QSplitter::splitterMoved, this, &Splitter::onSplitterMoved);
setChildrenCollapsible(false);
} }
void Splitter::onSplitterMoved(int pos, int index) void Splitter::onSplitterMoved(int pos, int index)

View File

@ -58,6 +58,15 @@ void TimelineView::sliderRangeChanged(int min, int max)
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);
if (isPaginationScrollPending_) {
isPaginationScrollPending_ = false;
int currentHeight = scroll_widget_->size().height();
int diff = currentHeight - oldHeight_;
scroll_area_->verticalScrollBar()->setValue(oldPosition_ + diff);
}
} }
void TimelineView::scrollDown() void TimelineView::scrollDown()
@ -67,7 +76,7 @@ void TimelineView::scrollDown()
// The first time we enter the room move the scroll bar to the bottom. // The first time we enter the room move the scroll bar to the bottom.
if (!isInitialized) { if (!isInitialized) {
scroll_area_->ensureVisible(0, scroll_widget_->size().height(), 0, 0); scroll_area_->verticalScrollBar()->setValue(max);
isInitialized = true; isInitialized = true;
return; return;
} }
@ -88,17 +97,14 @@ void TimelineView::sliderMoved(int position)
return; return;
// Prevent user from moving up when there is pagination in progress. // Prevent user from moving up when there is pagination in progress.
if (isPaginationInProgress_) { // TODO: Keep a map of the event ids to filter out duplicates.
scroll_area_->verticalScrollBar()->setValue(SCROLL_BAR_GAP); if (isPaginationInProgress_)
return; return;
}
isPaginationInProgress_ = true; isPaginationInProgress_ = true;
scroll_height_ = scroll_area_->verticalScrollBar()->value();
previous_max_height_ = scroll_area_->verticalScrollBar()->maximum();
// FIXME: Maybe move this to TimelineViewManager to remove the extra calls? // FIXME: Maybe move this to TimelineViewManager to remove the extra calls?
client_.data()->messages(room_id_, prev_batch_token_); client_->messages(room_id_, prev_batch_token_);
} }
} }
@ -130,11 +136,15 @@ void TimelineView::addBackwardsEvents(const QString &room_id, const RoomMessages
// Reverse again to render them. // Reverse again to render them.
std::reverse(items.begin(), items.end()); std::reverse(items.begin(), items.end());
oldPosition_ = scroll_area_->verticalScrollBar()->value();
oldHeight_ = scroll_widget_->size().height();
for (const auto &item : items) for (const auto &item : items)
addTimelineItem(item, TimelineDirection::Top); addTimelineItem(item, TimelineDirection::Top);
prev_batch_token_ = msgs.end(); prev_batch_token_ = msgs.end();
isPaginationInProgress_ = false; isPaginationInProgress_ = false;
isPaginationScrollPending_ = true;
} }
TimelineItem *TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection direction) TimelineItem *TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection direction)
@ -216,11 +226,6 @@ int TimelineView::addEvents(const Timeline &timeline)
QSettings settings; QSettings settings;
QString localUser = settings.value("auth/user_id").toString(); QString localUser = settings.value("auth/user_id").toString();
if (isInitialSync) {
prev_batch_token_ = timeline.previousBatch();
isInitialSync = false;
}
for (const auto &event : timeline.events()) { for (const auto &event : timeline.events()) {
TimelineItem *item = parseMessageEvent(event.toObject(), TimelineDirection::Bottom); TimelineItem *item = parseMessageEvent(event.toObject(), TimelineDirection::Bottom);
auto sender = event.toObject().value("sender").toString(); auto sender = event.toObject().value("sender").toString();
@ -233,6 +238,13 @@ int TimelineView::addEvents(const Timeline &timeline)
} }
} }
if (isInitialSync) {
prev_batch_token_ = timeline.previousBatch();
isInitialSync = false;
client_->messages(room_id_, prev_batch_token_);
}
return message_count; return message_count;
} }

View File

@ -119,9 +119,10 @@ void TimelineViewManager::setHistoryView(const QString &room_id)
active_room_ = room_id; active_room_ = room_id;
auto widget = views_.value(room_id); auto widget = views_.value(room_id);
widget->scrollDown();
setCurrentWidget(widget.data()); setCurrentWidget(widget.data());
widget->scrollDown();
} }
QMap<QString, QString> TimelineViewManager::NICK_COLORS; QMap<QString, QString> TimelineViewManager::NICK_COLORS;