Update the last sender from the initial pagination
This commit is contained in:
parent
f8505fe0bc
commit
9c28ba28a8
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
struct DescInfo {
|
struct DescInfo {
|
||||||
QString username;
|
QString username;
|
||||||
|
QString userid;
|
||||||
QString body;
|
QString body;
|
||||||
QString timestamp;
|
QString timestamp;
|
||||||
};
|
};
|
||||||
|
|
|
@ -109,8 +109,8 @@ private:
|
||||||
ScrollBar *scrollbar_;
|
ScrollBar *scrollbar_;
|
||||||
QWidget *scroll_widget_;
|
QWidget *scroll_widget_;
|
||||||
|
|
||||||
QString last_sender_;
|
QString lastSender_;
|
||||||
QString last_sender_backwards_;
|
QString firstSender_;
|
||||||
QString room_id_;
|
QString room_id_;
|
||||||
QString prev_batch_token_;
|
QString prev_batch_token_;
|
||||||
QString local_user_;
|
QString local_user_;
|
||||||
|
|
|
@ -72,7 +72,7 @@ TimelineItem::TimelineItem(const QString &userid, const QString &color, QString
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
descriptionMsg_ = {"You: ", body, descriptiveTime(QDateTime::currentDateTime())};
|
descriptionMsg_ = {"You: ", userid, body, descriptiveTime(QDateTime::currentDateTime())};
|
||||||
|
|
||||||
body.replace(URL_REGEX, URL_HTML);
|
body.replace(URL_REGEX, URL_HTML);
|
||||||
auto displayName = TimelineViewManager::displayName(userid);
|
auto displayName = TimelineViewManager::displayName(userid);
|
||||||
|
@ -94,8 +94,11 @@ TimelineItem::TimelineItem(const QString &userid, const QString &color, QString
|
||||||
TimelineItem::TimelineItem(QString body, QWidget *parent)
|
TimelineItem::TimelineItem(QString body, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
|
QSettings settings;
|
||||||
|
auto userid = settings.value("auth/user_id").toString();
|
||||||
|
|
||||||
init();
|
init();
|
||||||
descriptionMsg_ = {"You: ", body, descriptiveTime(QDateTime::currentDateTime())};
|
descriptionMsg_ = {"You: ", userid, body, descriptiveTime(QDateTime::currentDateTime())};
|
||||||
|
|
||||||
body.replace(URL_REGEX, URL_HTML);
|
body.replace(URL_REGEX, URL_HTML);
|
||||||
|
|
||||||
|
@ -122,7 +125,9 @@ TimelineItem::TimelineItem(ImageItem *image,
|
||||||
auto displayName = TimelineViewManager::displayName(event.sender());
|
auto displayName = TimelineViewManager::displayName(event.sender());
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
descriptionMsg_ = {event.sender() == settings.value("auth/user_id") ? "You" : displayName,
|
descriptionMsg_ = {
|
||||||
|
event.sender() == settings.value("auth/user_id") ? "You" : displayName,
|
||||||
|
event.sender(),
|
||||||
" sent an image",
|
" sent an image",
|
||||||
descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
|
descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
|
||||||
|
|
||||||
|
@ -152,7 +157,9 @@ TimelineItem::TimelineItem(ImageItem *image, const events::MessageEvent<msgs::Im
|
||||||
auto displayName = TimelineViewManager::displayName(event.sender());
|
auto displayName = TimelineViewManager::displayName(event.sender());
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
descriptionMsg_ = {event.sender() == settings.value("auth/user_id") ? "You" : displayName,
|
descriptionMsg_ = {
|
||||||
|
event.sender() == settings.value("auth/user_id") ? "You" : displayName,
|
||||||
|
event.sender(),
|
||||||
" sent an image",
|
" sent an image",
|
||||||
descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
|
descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
|
||||||
|
|
||||||
|
@ -178,6 +185,7 @@ TimelineItem::TimelineItem(const events::MessageEvent<msgs::Notice> &event, bool
|
||||||
init();
|
init();
|
||||||
descriptionMsg_ = {
|
descriptionMsg_ = {
|
||||||
TimelineViewManager::displayName(event.sender()),
|
TimelineViewManager::displayName(event.sender()),
|
||||||
|
event.sender(),
|
||||||
" sent a notification",
|
" sent a notification",
|
||||||
descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
|
descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
|
||||||
|
|
||||||
|
@ -219,7 +227,9 @@ TimelineItem::TimelineItem(const events::MessageEvent<msgs::Text> &event, bool w
|
||||||
auto displayName = TimelineViewManager::displayName(event.sender());
|
auto displayName = TimelineViewManager::displayName(event.sender());
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
descriptionMsg_ = {event.sender() == settings.value("auth/user_id") ? "You" : displayName,
|
descriptionMsg_ = {
|
||||||
|
event.sender() == settings.value("auth/user_id") ? "You" : displayName,
|
||||||
|
event.sender(),
|
||||||
QString(": %1").arg(body),
|
QString(": %1").arg(body),
|
||||||
descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
|
descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,6 @@ void TimelineView::addBackwardsEvents(const QString &room_id, const RoomMessages
|
||||||
}
|
}
|
||||||
|
|
||||||
isTimelineFinished = false;
|
isTimelineFinished = false;
|
||||||
last_sender_backwards_.clear();
|
|
||||||
QList<TimelineItem *> items;
|
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.
|
||||||
|
@ -183,6 +182,11 @@ void TimelineView::addBackwardsEvents(const QString &room_id, const RoomMessages
|
||||||
// Exclude the top stretch.
|
// Exclude the top stretch.
|
||||||
if (!msgs.chunk().isEmpty() && scroll_layout_->count() > 1)
|
if (!msgs.chunk().isEmpty() && scroll_layout_->count() > 1)
|
||||||
notifyForLastEvent();
|
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 (lastSender_.isEmpty() && !items.isEmpty())
|
||||||
|
lastSender_ = items.constFirst()->descriptionMessage().userid;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineItem *TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection direction)
|
TimelineItem *TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection direction)
|
||||||
|
@ -279,12 +283,11 @@ int TimelineView::addEvents(const Timeline &timeline)
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
if (item != nullptr) {
|
if (item != nullptr) {
|
||||||
addTimelineItem(item, TimelineDirection::Bottom);
|
addTimelineItem(item, TimelineDirection::Bottom);
|
||||||
|
|
||||||
if (sender != localUser)
|
if (localUser != event.toObject().value("sender").toString())
|
||||||
message_count += 1;
|
message_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,17 +345,17 @@ void TimelineView::init()
|
||||||
void TimelineView::updateLastSender(const QString &user_id, TimelineDirection direction)
|
void TimelineView::updateLastSender(const QString &user_id, TimelineDirection direction)
|
||||||
{
|
{
|
||||||
if (direction == TimelineDirection::Bottom)
|
if (direction == TimelineDirection::Bottom)
|
||||||
last_sender_ = user_id;
|
lastSender_ = user_id;
|
||||||
else
|
else
|
||||||
last_sender_backwards_ = user_id;
|
firstSender_ = user_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimelineView::isSenderRendered(const QString &user_id, TimelineDirection direction)
|
bool TimelineView::isSenderRendered(const QString &user_id, TimelineDirection direction)
|
||||||
{
|
{
|
||||||
if (direction == TimelineDirection::Bottom)
|
if (direction == TimelineDirection::Bottom)
|
||||||
return last_sender_ != user_id;
|
return lastSender_ != user_id;
|
||||||
else
|
else
|
||||||
return last_sender_backwards_ != user_id;
|
return firstSender_ != user_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineItem *TimelineView::createTimelineItem(const events::MessageEvent<msgs::Image> &event, const QString &color, bool with_sender)
|
TimelineItem *TimelineView::createTimelineItem(const events::MessageEvent<msgs::Image> &event, const QString &color, bool with_sender)
|
||||||
|
@ -428,7 +431,7 @@ void TimelineView::addUserTextMessage(const QString &body, int txn_id)
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
auto user_id = settings.value("auth/user_id").toString();
|
auto user_id = settings.value("auth/user_id").toString();
|
||||||
|
|
||||||
auto with_sender = last_sender_ != user_id;
|
auto with_sender = lastSender_ != user_id;
|
||||||
auto color = TimelineViewManager::getUserColor(user_id);
|
auto color = TimelineViewManager::getUserColor(user_id);
|
||||||
|
|
||||||
TimelineItem *view_item;
|
TimelineItem *view_item;
|
||||||
|
@ -440,7 +443,7 @@ void TimelineView::addUserTextMessage(const QString &body, int txn_id)
|
||||||
|
|
||||||
scroll_layout_->addWidget(view_item);
|
scroll_layout_->addWidget(view_item);
|
||||||
|
|
||||||
last_sender_ = user_id;
|
lastSender_ = user_id;
|
||||||
|
|
||||||
PendingMessage message(txn_id, body, "", view_item);
|
PendingMessage message(txn_id, body, "", view_item);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue