Fix chat positioning and sent/read indicator

This commit is contained in:
Sebastian J. Wolf 2020-08-31 21:51:52 +02:00
parent cff06cc32d
commit a04332d4b6
9 changed files with 78 additions and 82 deletions

View file

@ -107,6 +107,30 @@ Page {
}
}
function getMessageStatusText(message, listItemIndex, lastReadSentIndex) {
var messageStatusSuffix = "";
if (chatPage.myUserId === message.sender_user_id) {
messageStatusSuffix += "  "
if (listItemIndex <= lastReadSentIndex) {
// Read by other party
messageStatusSuffix += Emoji.emojify("✅", Theme.fontSizeTiny);
} else {
// Not yet read by other party
if (message.sending_state) {
if (message.sending_state['@type'] === "messageSendingStatePending") {
messageStatusSuffix += Emoji.emojify("🕙", Theme.fontSizeTiny);
} else {
// Sending failed...
messageStatusSuffix += Emoji.emojify("❌", Theme.fontSizeTiny);
}
} else {
messageStatusSuffix += Emoji.emojify("☑️", Theme.fontSizeTiny);
}
}
}
return Functions.getDateTimeElapsed(message.date) + messageStatusSuffix;
}
Component.onCompleted: {
initializePage();
}
@ -482,26 +506,7 @@ Page {
running: true
repeat: true
onTriggered: {
var messageStatusSuffix = "";
if (chatPage.myUserId === display.sender_user_id) {
if (index <= chatView.lastReadSentIndex) {
// Read by other party
messageStatusSuffix += Emoji.emojify("✅", Theme.fontSizeTiny);
} else {
// Not yet read by other party
if (display.sending_state) {
if (display.sending_state['@type'] === "messageSendingStatePending") {
messageStatusSuffix += Emoji.emojify("🕙", Theme.fontSizeTiny);
} else {
// Sending failed...
messageStatusSuffix += Emoji.emojify("❌", Theme.fontSizeTiny);
}
} else {
messageStatusSuffix += Emoji.emojify("☑️", Theme.fontSizeTiny);
}
}
}
messageDateText.text = Functions.getDateTimeElapsed(display.date) + messageStatusSuffix;
messageDateText.text = getMessageStatusText(display, index, chatView.lastReadSentIndex);
}
}
@ -509,61 +514,18 @@ Page {
target: chatModel
onLastReadSentMessageUpdated: {
console.log("[ChatModel] Messages in this chat were read, new last read: " + lastReadSentIndex + ", updating description for index " + index + ", status: " + (index <= lastReadSentIndex));
var messageStatusSuffix = "";
if (chatPage.myUserId === display.sender_user_id) {
if (index <= lastReadSentIndex) {
// Read by other party
messageStatusSuffix += Emoji.emojify("✅", Theme.fontSizeTiny);
} else {
// Not yet read by other party
if (display.sending_state) {
if (display.sending_state['@type'] === "messageSendingStatePending") {
messageStatusSuffix += Emoji.emojify("🕙", Theme.fontSizeTiny);
} else {
// Sending failed...
messageStatusSuffix += Emoji.emojify("❌", Theme.fontSizeTiny);
}
} else {
messageStatusSuffix += Emoji.emojify("☑️", Theme.fontSizeTiny);
}
}
}
messageDateText.text = Functions.getDateTimeElapsed(display.date) + messageStatusSuffix;
messageDateText.text = getMessageStatusText(display, index, lastReadSentIndex);
}
}
Text {
Component.onCompleted: {
var messageStatusSuffix = "";
if (chatPage.myUserId === display.sender_user_id) {
messageStatusSuffix += " - "
if (index <= chatView.lastReadSentIndex) {
// Read by other party
messageStatusSuffix += Emoji.emojify("✅", Theme.fontSizeTiny);
} else {
// Not yet read by other party
if (display.sending_state) {
if (display.sending_state['@type'] === "messageSendingStatePending") {
messageStatusSuffix += Emoji.emojify("🕙", Theme.fontSizeTiny);
} else {
// Sending failed...
messageStatusSuffix += Emoji.emojify("❌", Theme.fontSizeTiny);
}
} else {
messageStatusSuffix += Emoji.emojify("☑️", Theme.fontSizeTiny);
}
}
}
text = Functions.getDateTimeElapsed(display.date) + messageStatusSuffix;
}
width: parent.width
id: messageDateText
font.pixelSize: Theme.fontSizeTiny
color: (chatPage.myUserId === display.sender_user_id) ? Theme.secondaryHighlightColor : Theme.secondaryColor
horizontalAlignment: (chatPage.myUserId === display.sender_user_id) ? Text.AlignRight : Text.AlignLeft
text: getMessageStatusText(display, index, chatView.lastReadSentIndex)
}
}

View file

@ -8,7 +8,9 @@ ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper)
connect(this->tdLibWrapper, SIGNAL(newChatDiscovered(QString, QVariantMap)), this, SLOT(handleChatDiscovered(QString, QVariantMap)));
connect(this->tdLibWrapper, SIGNAL(chatLastMessageUpdated(QString, QString, QVariantMap)), this, SLOT(handleChatLastMessageUpdated(QString, QString, QVariantMap)));
connect(this->tdLibWrapper, SIGNAL(chatOrderUpdated(QString, QString)), this, SLOT(handleChatOrderUpdated(QString, QString)));
connect(this->tdLibWrapper, SIGNAL(chatReadInboxUpdated(QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, int)));
connect(this->tdLibWrapper, SIGNAL(chatReadInboxUpdated(QString, QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, QString, int)));
connect(this->tdLibWrapper, SIGNAL(chatReadOutboxUpdated(QString, QString)), this, SLOT(handleChatReadOutboxUpdated(QString, QString)));
connect(this->tdLibWrapper, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap)));
}
ChatListModel::~ChatListModel()
@ -106,19 +108,48 @@ void ChatListModel::handleChatOrderUpdated(const QString &chatId, const QString
this->chatListMutex.unlock();
}
void ChatListModel::handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount)
void ChatListModel::handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount)
{
this->chatListMutex.lock();
qDebug() << "[ChatListModel] Updating chat unread count for " << chatId << " unread messages " << unreadCount;
qDebug() << "[ChatListModel] Updating chat unread count for " << chatId << " unread messages " << unreadCount << ", last read message ID: " << lastReadInboxMessageId;
int chatIndex = this->chatIndexMap.value(chatId).toInt();
QVariantMap currentChat = this->chatList.at(chatIndex).toMap();
currentChat.insert("unread_count", unreadCount);
currentChat.insert("last_read_inbox_message_id", lastReadInboxMessageId);
this->chatList.replace(chatIndex, currentChat);
emit dataChanged(this->index(chatIndex), this->index(chatIndex));
emit chatChanged(chatId);
this->chatListMutex.unlock();
}
void ChatListModel::handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId)
{
this->chatListMutex.lock();
qDebug() << "[ChatListModel] Updating last read message for " << chatId << " last ID " << lastReadOutboxMessageId;
int chatIndex = this->chatIndexMap.value(chatId).toInt();
QVariantMap currentChat = this->chatList.at(chatIndex).toMap();
currentChat.insert("last_read_outbox_message_id", lastReadOutboxMessageId);
this->chatList.replace(chatIndex, currentChat);
emit dataChanged(this->index(chatIndex), this->index(chatIndex));
emit chatChanged(chatId);
this->chatListMutex.unlock();
}
void ChatListModel::handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message)
{
this->chatListMutex.lock();
QString chatId = message.value("chat_id").toString();
int chatIndex = this->chatIndexMap.value(chatId).toInt();
qDebug() << "[ChatListModel] Updating last message for chat " << chatId << " at index " << chatIndex << ", as message was sent, old ID: " << oldMessageId << ", new ID: " << messageId;
QVariantMap currentChat = this->chatList.value(chatIndex).toMap();
currentChat.insert("last_message", message);
this->chatList.replace(chatIndex, currentChat);
emit dataChanged(this->index(chatIndex), this->index(chatIndex));
emit chatChanged(chatId);
this->chatListMutex.unlock();
}
void ChatListModel::updateChatOrder(const int &currentChatIndex, const QVariantMap &updatedChat)
{
// Finding the new position manually as information is needed by beginMoveRows()

View file

@ -26,7 +26,9 @@ public slots:
void handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation);
void handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);
void handleChatOrderUpdated(const QString &chatId, const QString &order);
void handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount);
void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount);
void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
private:
TDLibWrapper *tdLibWrapper;

View file

@ -11,7 +11,7 @@ ChatModel::ChatModel(TDLibWrapper *tdLibWrapper)
this->inIncrementalUpdate = false;
connect(this->tdLibWrapper, SIGNAL(messagesReceived(QVariantList)), this, SLOT(handleMessagesReceived(QVariantList)));
connect(this->tdLibWrapper, SIGNAL(newMessageReceived(QString, QVariantMap)), this, SLOT(handleNewMessageReceived(QString, QVariantMap)));
connect(this->tdLibWrapper, SIGNAL(chatReadInboxUpdated(QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, int)));
connect(this->tdLibWrapper, SIGNAL(chatReadInboxUpdated(QString, QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, QString, int)));
connect(this->tdLibWrapper, SIGNAL(chatReadOutboxUpdated(QString, QString)), this, SLOT(handleChatReadOutboxUpdated(QString, QString)));
connect(this->tdLibWrapper, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap)));
}
@ -143,12 +143,13 @@ void ChatModel::handleNewMessageReceived(const QString &chatId, const QVariantMa
}
}
void ChatModel::handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount)
void ChatModel::handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount)
{
if (chatId == this->chatId) {
qDebug() << "[ChatModel] Updating chat unread count, unread messages " << unreadCount;
qDebug() << "[ChatModel] Updating chat unread count, unread messages " << unreadCount << ", last read message ID: " << lastReadInboxMessageId;
this->chatInformation.insert("unread_count", unreadCount);
emit unreadCountUpdated(unreadCount);
this->chatInformation.insert("last_read_inbox_message_id", lastReadInboxMessageId);
emit unreadCountUpdated(unreadCount, lastReadInboxMessageId);
}
}

View file

@ -24,13 +24,13 @@ signals:
void messagesReceived(const int &modelIndex, const int &lastReadSentIndex);
void messagesIncrementalUpdate(const int &modelIndex, const int &lastReadSentIndex);
void newMessageReceived();
void unreadCountUpdated(const int &unreadCount);
void unreadCountUpdated(const int &unreadCount, const QString &lastReadInboxMessageId);
void lastReadSentMessageUpdated(const int &lastReadSentIndex);
public slots:
void handleMessagesReceived(const QVariantList &messages);
void handleNewMessageReceived(const QString &chatId, const QVariantMap &message);
void handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount);
void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount);
void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);

View file

@ -179,7 +179,7 @@ void TDLibReceiver::processUpdateChatOrder(const QVariantMap &receivedInformatio
void TDLibReceiver::processUpdateChatReadInbox(const QVariantMap &receivedInformation)
{
qDebug() << "[TDLibReceiver] Chat read information updated for " << receivedInformation.value("chat_id").toString() << " unread count: " << receivedInformation.value("unread_count").toString();
emit chatReadInboxUpdated(receivedInformation.value("chat_id").toString(), receivedInformation.value("unread_count").toInt());
emit chatReadInboxUpdated(receivedInformation.value("chat_id").toString(), receivedInformation.value("last_read_inbox_message_id").toString(), receivedInformation.value("unread_count").toInt());
}
void TDLibReceiver::processUpdateChatReadOutbox(const QVariantMap &receivedInformation)

View file

@ -48,7 +48,7 @@ signals:
void unreadChatCountUpdated(const QVariantMap &chatCountInformation);
void chatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);
void chatOrderUpdated(const QString &chatId, const QString &order);
void chatReadInboxUpdated(const QString &chatId, const int &unreadCount);
void chatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount);
void chatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
void basicGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);
void superGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);

View file

@ -54,7 +54,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
connect(this->tdLibReceiver, SIGNAL(unreadChatCountUpdated(QVariantMap)), this, SLOT(handleUnreadChatCountUpdated(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(chatLastMessageUpdated(QString, QString, QVariantMap)), this, SLOT(handleChatLastMessageUpdated(QString, QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(chatOrderUpdated(QString, QString)), this, SLOT(handleChatOrderUpdated(QString, QString)));
connect(this->tdLibReceiver, SIGNAL(chatReadInboxUpdated(QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, int)));
connect(this->tdLibReceiver, SIGNAL(chatReadInboxUpdated(QString, QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, QString, int)));
connect(this->tdLibReceiver, SIGNAL(chatReadOutboxUpdated(QString, QString)), this, SLOT(handleChatReadOutboxUpdated(QString, QString)));
connect(this->tdLibReceiver, SIGNAL(basicGroupUpdated(QString, QVariantMap)), this, SLOT(handleBasicGroupUpdated(QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(superGroupUpdated(QString, QVariantMap)), this, SLOT(handleSuperGroupUpdated(QString, QVariantMap)));
@ -446,9 +446,9 @@ void TDLibWrapper::handleChatOrderUpdated(const QString &chatId, const QString &
emit chatOrderUpdated(chatId, order);
}
void TDLibWrapper::handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount)
void TDLibWrapper::handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount)
{
emit chatReadInboxUpdated(chatId, unreadCount);
emit chatReadInboxUpdated(chatId, lastReadInboxMessageId, unreadCount);
}
void TDLibWrapper::handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId)

View file

@ -96,7 +96,7 @@ signals:
void unreadChatCountUpdated(const QVariantMap &chatCountInformation);
void chatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);
void chatOrderUpdated(const QString &chatId, const QString &order);
void chatReadInboxUpdated(const QString &chatId, const int &unreadCount);
void chatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount);
void chatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
void userUpdated(const QString &userId, const QVariantMap &userInformation);
void basicGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);
@ -122,7 +122,7 @@ public slots:
void handleUnreadChatCountUpdated(const QVariantMap &chatCountInformation);
void handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);
void handleChatOrderUpdated(const QString &chatId, const QString &order);
void handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount);
void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount);
void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
void handleBasicGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);
void handleSuperGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);