summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-08-14 00:26:57 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-08-14 00:26:57 +0300
commit9c28ba28a8738cea5b6a79e60d124c4728b7abc5 (patch)
treeb398c4d2f1d6de77a2508d404e3f067b1ccc14d0 /src
parentDon't overwrite last user (diff)
downloadnheko-9c28ba28a8738cea5b6a79e60d124c4728b7abc5.tar.xz
Update the last sender from the initial pagination
Diffstat (limited to 'src')
-rw-r--r--src/TimelineItem.cc32
-rw-r--r--src/TimelineView.cc21
2 files changed, 33 insertions, 20 deletions
diff --git a/src/TimelineItem.cc b/src/TimelineItem.cc
index cc7f03a3..5a3b3f23 100644
--- a/src/TimelineItem.cc
+++ b/src/TimelineItem.cc
@@ -72,7 +72,7 @@ TimelineItem::TimelineItem(const QString &userid, const QString &color, QString
     : QWidget(parent)
 {
 	init();
-	descriptionMsg_ = {"You: ", body, descriptiveTime(QDateTime::currentDateTime())};
+	descriptionMsg_ = {"You: ", userid, body, descriptiveTime(QDateTime::currentDateTime())};
 
 	body.replace(URL_REGEX, URL_HTML);
 	auto displayName = TimelineViewManager::displayName(userid);
@@ -94,8 +94,11 @@ TimelineItem::TimelineItem(const QString &userid, const QString &color, QString
 TimelineItem::TimelineItem(QString body, QWidget *parent)
     : QWidget(parent)
 {
+	QSettings settings;
+	auto userid = settings.value("auth/user_id").toString();
+
 	init();
-	descriptionMsg_ = {"You: ", body, descriptiveTime(QDateTime::currentDateTime())};
+	descriptionMsg_ = {"You: ", userid, body, descriptiveTime(QDateTime::currentDateTime())};
 
 	body.replace(URL_REGEX, URL_HTML);
 
@@ -122,9 +125,11 @@ TimelineItem::TimelineItem(ImageItem *image,
 	auto displayName = TimelineViewManager::displayName(event.sender());
 
 	QSettings settings;
-	descriptionMsg_ = {event.sender() == settings.value("auth/user_id") ? "You" : displayName,
-			   " sent an image",
-			   descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
+	descriptionMsg_ = {
+		event.sender() == settings.value("auth/user_id") ? "You" : displayName,
+		event.sender(),
+		" sent an image",
+		descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
 
 	generateTimestamp(timestamp);
 	generateBody(displayName, color, "");
@@ -152,9 +157,11 @@ TimelineItem::TimelineItem(ImageItem *image, const events::MessageEvent<msgs::Im
 	auto displayName = TimelineViewManager::displayName(event.sender());
 
 	QSettings settings;
-	descriptionMsg_ = {event.sender() == settings.value("auth/user_id") ? "You" : displayName,
-			   " sent an image",
-			   descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
+	descriptionMsg_ = {
+		event.sender() == settings.value("auth/user_id") ? "You" : displayName,
+		event.sender(),
+		" sent an image",
+		descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
 
 	auto timestamp = QDateTime::fromMSecsSinceEpoch(event.timestamp());
 	generateTimestamp(timestamp);
@@ -178,6 +185,7 @@ TimelineItem::TimelineItem(const events::MessageEvent<msgs::Notice> &event, bool
 	init();
 	descriptionMsg_ = {
 		TimelineViewManager::displayName(event.sender()),
+		event.sender(),
 		" sent a notification",
 		descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
 
@@ -219,9 +227,11 @@ TimelineItem::TimelineItem(const events::MessageEvent<msgs::Text> &event, bool w
 	auto displayName = TimelineViewManager::displayName(event.sender());
 
 	QSettings settings;
-	descriptionMsg_ = {event.sender() == settings.value("auth/user_id") ? "You" : displayName,
-			   QString(": %1").arg(body),
-			   descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
+	descriptionMsg_ = {
+		event.sender() == settings.value("auth/user_id") ? "You" : displayName,
+		event.sender(),
+		QString(": %1").arg(body),
+		descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp()))};
 
 	generateTimestamp(timestamp);
 
diff --git a/src/TimelineView.cc b/src/TimelineView.cc
index 0b6c09eb..1d6dd59a 100644
--- a/src/TimelineView.cc
+++ b/src/TimelineView.cc
@@ -153,7 +153,6 @@ void TimelineView::addBackwardsEvents(const QString &room_id, const RoomMessages
 	}
 
 	isTimelineFinished = false;
-	last_sender_backwards_.clear();
 	QList<TimelineItem *> items;
 
 	// 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.
 	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 (lastSender_.isEmpty() && !items.isEmpty())
+		lastSender_ = items.constFirst()->descriptionMessage().userid;
 }
 
 TimelineItem *TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection direction)
@@ -279,12 +283,11 @@ int TimelineView::addEvents(const Timeline &timeline)
 
 	for (const auto &event : timeline.events()) {
 		TimelineItem *item = parseMessageEvent(event.toObject(), TimelineDirection::Bottom);
-		auto sender = event.toObject().value("sender").toString();
 
 		if (item != nullptr) {
 			addTimelineItem(item, TimelineDirection::Bottom);
 
-			if (sender != localUser)
+			if (localUser != event.toObject().value("sender").toString())
 				message_count += 1;
 		}
 	}
@@ -342,17 +345,17 @@ void TimelineView::init()
 void TimelineView::updateLastSender(const QString &user_id, TimelineDirection direction)
 {
 	if (direction == TimelineDirection::Bottom)
-		last_sender_ = user_id;
+		lastSender_ = user_id;
 	else
-		last_sender_backwards_ = user_id;
+		firstSender_ = user_id;
 }
 
 bool TimelineView::isSenderRendered(const QString &user_id, TimelineDirection direction)
 {
 	if (direction == TimelineDirection::Bottom)
-		return last_sender_ != user_id;
+		return lastSender_ != user_id;
 	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)
@@ -428,7 +431,7 @@ void TimelineView::addUserTextMessage(const QString &body, int txn_id)
 	QSettings settings;
 	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);
 
 	TimelineItem *view_item;
@@ -440,7 +443,7 @@ void TimelineView::addUserTextMessage(const QString &body, int txn_id)
 
 	scroll_layout_->addWidget(view_item);
 
-	last_sender_ = user_id;
+	lastSender_ = user_id;
 
 	PendingMessage message(txn_id, body, "", view_item);