|
|
|
@ -49,7 +49,9 @@ TimelineView::TimelineView(const Timeline &timeline, |
|
|
|
|
addEvents(timeline); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TimelineView::TimelineView(QSharedPointer<MatrixClient> client, const QString &room_id, QWidget *parent) |
|
|
|
|
TimelineView::TimelineView(QSharedPointer<MatrixClient> client, |
|
|
|
|
const QString &room_id, |
|
|
|
|
QWidget *parent) |
|
|
|
|
: QWidget(parent) |
|
|
|
|
, room_id_{ room_id } |
|
|
|
|
, client_{ client } |
|
|
|
@ -118,7 +120,8 @@ TimelineView::scrollDown() |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// If the gap is small enough move the scroll bar down. e.g when a new message appears.
|
|
|
|
|
// If the gap is small enough move the scroll bar down. e.g when a new
|
|
|
|
|
// message appears.
|
|
|
|
|
if (max - current < SCROLL_BAR_GAP) |
|
|
|
|
scroll_area_->verticalScrollBar()->setValue(max); |
|
|
|
|
} |
|
|
|
@ -134,14 +137,16 @@ TimelineView::sliderMoved(int position) |
|
|
|
|
if (isTimelineFinished) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
// Prevent user from moving up when there is pagination in progress.
|
|
|
|
|
// Prevent user from moving up when there is pagination in
|
|
|
|
|
// progress.
|
|
|
|
|
// TODO: Keep a map of the event ids to filter out duplicates.
|
|
|
|
|
if (isPaginationInProgress_) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
isPaginationInProgress_ = true; |
|
|
|
|
|
|
|
|
|
// FIXME: Maybe move this to TimelineViewManager to remove the extra calls?
|
|
|
|
|
// FIXME: Maybe move this to TimelineViewManager to remove the
|
|
|
|
|
// extra calls?
|
|
|
|
|
client_->messages(room_id_, prev_batch_token_); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -160,7 +165,8 @@ TimelineView::addBackwardsEvents(const QString &room_id, const RoomMessages &msg |
|
|
|
|
isTimelineFinished = false; |
|
|
|
|
QList<TimelineItem *> items; |
|
|
|
|
|
|
|
|
|
// Parse in reverse order to determine where we should not show sender's name.
|
|
|
|
|
// Parse in reverse order to determine where we should not show sender's
|
|
|
|
|
// name.
|
|
|
|
|
auto it = msgs.chunk().constEnd(); |
|
|
|
|
while (it != msgs.chunk().constBegin()) { |
|
|
|
|
--it; |
|
|
|
@ -188,8 +194,8 @@ TimelineView::addBackwardsEvents(const QString &room_id, const RoomMessages &msg |
|
|
|
|
if (!msgs.chunk().isEmpty() && scroll_layout_->count() > 1) |
|
|
|
|
notifyForLastEvent(); |
|
|
|
|
|
|
|
|
|
// If this batch is the first being rendered (i.e the first and the last events
|
|
|
|
|
// originate from this batch), set the last sender.
|
|
|
|
|
// If this batch is the first being rendered (i.e the first and the last
|
|
|
|
|
// events originate from this batch), set the last sender.
|
|
|
|
|
if (lastSender_.isEmpty() && !items.isEmpty()) |
|
|
|
|
lastSender_ = items.constFirst()->descriptionMessage().userid; |
|
|
|
|
} |
|
|
|
@ -223,11 +229,10 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto with_sender = isSenderRendered(text.sender(), direction); |
|
|
|
|
auto color = TimelineViewManager::getUserColor(text.sender()); |
|
|
|
|
|
|
|
|
|
updateLastSender(text.sender(), direction); |
|
|
|
|
|
|
|
|
|
return createTimelineItem(text, color, with_sender); |
|
|
|
|
return createTimelineItem(text, with_sender); |
|
|
|
|
} else if (msg_type == events::MessageEventType::Notice) { |
|
|
|
|
events::MessageEvent<msgs::Notice> notice; |
|
|
|
|
|
|
|
|
@ -245,11 +250,10 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire |
|
|
|
|
eventIds_[notice.eventId()] = true; |
|
|
|
|
|
|
|
|
|
auto with_sender = isSenderRendered(notice.sender(), direction); |
|
|
|
|
auto color = TimelineViewManager::getUserColor(notice.sender()); |
|
|
|
|
|
|
|
|
|
updateLastSender(notice.sender(), direction); |
|
|
|
|
|
|
|
|
|
return createTimelineItem(notice, color, with_sender); |
|
|
|
|
return createTimelineItem(notice, with_sender); |
|
|
|
|
} else if (msg_type == events::MessageEventType::Image) { |
|
|
|
|
events::MessageEvent<msgs::Image> img; |
|
|
|
|
|
|
|
|
@ -266,11 +270,10 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire |
|
|
|
|
eventIds_[img.eventId()] = true; |
|
|
|
|
|
|
|
|
|
auto with_sender = isSenderRendered(img.sender(), direction); |
|
|
|
|
auto color = TimelineViewManager::getUserColor(img.sender()); |
|
|
|
|
|
|
|
|
|
updateLastSender(img.sender(), direction); |
|
|
|
|
|
|
|
|
|
return createTimelineItem(img, color, with_sender); |
|
|
|
|
return createTimelineItem(img, with_sender); |
|
|
|
|
} else if (msg_type == events::MessageEventType::Unknown) { |
|
|
|
|
qWarning() << "Unknown message type" << event; |
|
|
|
|
return nullptr; |
|
|
|
@ -344,9 +347,15 @@ TimelineView::init() |
|
|
|
|
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))); |
|
|
|
|
connect(scroll_area_->verticalScrollBar(), |
|
|
|
|
SIGNAL(rangeChanged(int, int)), |
|
|
|
|
this, |
|
|
|
@ -372,32 +381,25 @@ TimelineView::isSenderRendered(const QString &user_id, TimelineDirection directi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TimelineItem * |
|
|
|
|
TimelineView::createTimelineItem(const events::MessageEvent<msgs::Image> &event, const QString &color, bool with_sender) |
|
|
|
|
TimelineView::createTimelineItem(const events::MessageEvent<msgs::Image> &event, bool with_sender) |
|
|
|
|
{ |
|
|
|
|
auto image = new ImageItem(client_, event); |
|
|
|
|
auto item = new TimelineItem(image, event, with_sender, scroll_widget_); |
|
|
|
|
|
|
|
|
|
if (with_sender) { |
|
|
|
|
auto item = new TimelineItem(image, event, color, scroll_widget_); |
|
|
|
|
return item; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto item = new TimelineItem(image, event, scroll_widget_); |
|
|
|
|
return item; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TimelineItem * |
|
|
|
|
TimelineView::createTimelineItem(const events::MessageEvent<msgs::Notice> &event, |
|
|
|
|
const QString &color, |
|
|
|
|
bool with_sender) |
|
|
|
|
TimelineView::createTimelineItem(const events::MessageEvent<msgs::Notice> &event, bool with_sender) |
|
|
|
|
{ |
|
|
|
|
TimelineItem *item = new TimelineItem(event, with_sender, color, scroll_widget_); |
|
|
|
|
TimelineItem *item = new TimelineItem(event, with_sender, scroll_widget_); |
|
|
|
|
return item; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TimelineItem * |
|
|
|
|
TimelineView::createTimelineItem(const events::MessageEvent<msgs::Text> &event, const QString &color, bool with_sender) |
|
|
|
|
TimelineView::createTimelineItem(const events::MessageEvent<msgs::Text> &event, bool with_sender) |
|
|
|
|
{ |
|
|
|
|
TimelineItem *item = new TimelineItem(event, with_sender, color, scroll_widget_); |
|
|
|
|
TimelineItem *item = new TimelineItem(event, with_sender, scroll_widget_); |
|
|
|
|
return item; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -422,7 +424,8 @@ TimelineView::updatePendingMessage(int txn_id, QString event_id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
TimelineView::isPendingMessage(const events::MessageEvent<msgs::Text> &e, const QString &local_userid) |
|
|
|
|
TimelineView::isPendingMessage(const events::MessageEvent<msgs::Text> &e, |
|
|
|
|
const QString &local_userid) |
|
|
|
|
{ |
|
|
|
|
if (e.sender() != local_userid) |
|
|
|
|
return false; |
|
|
|
@ -455,12 +458,11 @@ TimelineView::addUserTextMessage(const QString &body, int txn_id) |
|
|
|
|
auto user_id = settings.value("auth/user_id").toString(); |
|
|
|
|
|
|
|
|
|
auto with_sender = lastSender_ != user_id; |
|
|
|
|
auto color = TimelineViewManager::getUserColor(user_id); |
|
|
|
|
|
|
|
|
|
TimelineItem *view_item; |
|
|
|
|
|
|
|
|
|
if (with_sender) |
|
|
|
|
view_item = new TimelineItem(user_id, color, body, scroll_widget_); |
|
|
|
|
view_item = new TimelineItem(user_id, body, scroll_widget_); |
|
|
|
|
else |
|
|
|
|
view_item = new TimelineItem(body, scroll_widget_); |
|
|
|
|
|
|
|
|
|