From 18e88a84122281c921b6dc92f6252149004f9c48 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Mon, 16 Nov 2020 00:08:55 +0100 Subject: [PATCH] If last message was an own one, it was of course read... --- src/chatmodel.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index cead6cf..4b745b7 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -31,6 +31,7 @@ namespace { const QString PHOTO("photo"); const QString SMALL("small"); const QString LAST_READ_INBOX_MESSAGE_ID("last_read_inbox_message_id"); + const QString SENDER_USER_ID("sender_user_id"); } ChatModel::ChatModel(TDLibWrapper *tdLibWrapper) : @@ -128,7 +129,11 @@ QVariantMap ChatModel::getMessage(int index) int ChatModel::getLastReadMessageIndex() { - return this->messageIndexMap.value(this->chatInformation.value(LAST_READ_INBOX_MESSAGE_ID).toString()).toInt(); + if (this->messages.isEmpty()) { + return 0; + } else { + return (this->messages.last().toMap().value(SENDER_USER_ID).toString() == tdLibWrapper->getUserInformation().value(ID).toString()) ? (this->messages.size() - 1) : this->messageIndexMap.value(this->chatInformation.value(LAST_READ_INBOX_MESSAGE_ID).toString()).toInt(); + } } QVariantMap ChatModel::smallPhoto() const