Try to get pending message state into the chat

This commit is contained in:
Sebastian J. Wolf 2020-08-30 23:52:22 +02:00
parent a131aa739b
commit cff06cc32d
7 changed files with 105 additions and 4 deletions

View file

@ -482,23 +482,85 @@ Page {
running: true running: true
repeat: true repeat: true
onTriggered: { onTriggered: {
messageDateText.text = Functions.getDateTimeElapsed(display.date) + ( (chatPage.myUserId === display.sender_user_id) ? ( index <= chatView.lastReadSentIndex ? Emoji.emojify(" - ✅", Theme.fontSizeTiny) : Emoji.emojify(" - ☑️", Theme.fontSizeTiny) ) : "" ); 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;
} }
} }
Connections { Connections {
target: chatModel target: chatModel
onLastReadSentMessageUpdated: { onLastReadSentMessageUpdated: {
console.log("[ChatModel] Messages in this chat were read, new last read: " + lastReadSentIndex + ", updating description for index " + index + ", status: " + index <= lastReadSentIndex); console.log("[ChatModel] Messages in this chat were read, new last read: " + lastReadSentIndex + ", updating description for index " + index + ", status: " + (index <= lastReadSentIndex));
messageDateText.text = Functions.getDateTimeElapsed(display.date) + ( (chatPage.myUserId === display.sender_user_id) ? ( index <= lastReadSentIndex ? Emoji.emojify(" - ✅", Theme.fontSizeTiny) : Emoji.emojify(" - ☑️", Theme.fontSizeTiny) ) : "" ); 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;
} }
} }
Text { 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 width: parent.width
id: messageDateText id: messageDateText
text: Functions.getDateTimeElapsed(display.date) + ( (chatPage.myUserId === display.sender_user_id) ? ( index <= chatView.lastReadSentIndex ? Emoji.emojify(" - ✅", Theme.fontSizeTiny) : Emoji.emojify(" - ☑️", Theme.fontSizeTiny) ) : "" );
font.pixelSize: Theme.fontSizeTiny font.pixelSize: Theme.fontSizeTiny
color: (chatPage.myUserId === display.sender_user_id) ? Theme.secondaryHighlightColor : Theme.secondaryColor color: (chatPage.myUserId === display.sender_user_id) ? Theme.secondaryHighlightColor : Theme.secondaryColor
horizontalAlignment: (chatPage.myUserId === display.sender_user_id) ? Text.AlignRight : Text.AlignLeft horizontalAlignment: (chatPage.myUserId === display.sender_user_id) ? Text.AlignRight : Text.AlignLeft

View file

@ -13,6 +13,7 @@ ChatModel::ChatModel(TDLibWrapper *tdLibWrapper)
connect(this->tdLibWrapper, SIGNAL(newMessageReceived(QString, QVariantMap)), this, SLOT(handleNewMessageReceived(QString, QVariantMap))); 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, int)), this, SLOT(handleChatReadInboxUpdated(QString, int)));
connect(this->tdLibWrapper, SIGNAL(chatReadOutboxUpdated(QString, QString)), this, SLOT(handleChatReadOutboxUpdated(QString, QString))); 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)));
} }
ChatModel::~ChatModel() ChatModel::~ChatModel()
@ -161,6 +162,23 @@ void ChatModel::handleChatReadOutboxUpdated(const QString &chatId, const QString
} }
} }
void ChatModel::handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message)
{
qDebug() << "[ChatModel] Message send succeeded, new message ID " << messageId << "old message ID " << oldMessageId << ", chat ID" << message.value("chat_id").toString();
qDebug() << "[ChatModel] index map: " << this->messageIndexMap.contains(oldMessageId) << ", index count: " << this->messageIndexMap.size() << ", message count: " << this->messages.size();
if (this->messageIndexMap.contains(oldMessageId)) {
this->messagesMutex.lock();
qDebug() << "[ChatModel] Message was successfully sent " << oldMessageId;
int messageIndex = this->messageIndexMap.value(oldMessageId).toInt();
this->messages.replace(messageIndex, message);
this->calculateMessageIndexMap();
qDebug() << "[ChatModel] Message was replaced at index " << messageIndex;
this->messagesMutex.unlock();
emit lastReadSentMessageUpdated(calculateLastReadSentMessageId());
emit dataChanged(index(messageIndex), index(messageIndex));
}
}
void ChatModel::insertMessages() void ChatModel::insertMessages()
{ {
if (this->messages.isEmpty()) { if (this->messages.isEmpty()) {

View file

@ -32,6 +32,7 @@ public slots:
void handleNewMessageReceived(const QString &chatId, const QVariantMap &message); void handleNewMessageReceived(const QString &chatId, const QVariantMap &message);
void handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount); void handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount);
void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId); void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
private: private:

View file

@ -74,6 +74,7 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
if (objectTypeName == "messages") { this->processMessages(receivedInformation); } if (objectTypeName == "messages") { this->processMessages(receivedInformation); }
if (objectTypeName == "updateNewMessage") { this->processUpdateNewMessage(receivedInformation); } if (objectTypeName == "updateNewMessage") { this->processUpdateNewMessage(receivedInformation); }
if (objectTypeName == "message") { this->processMessage(receivedInformation); } if (objectTypeName == "message") { this->processMessage(receivedInformation); }
if (objectTypeName == "updateMessageSendSucceeded") { this->processMessageSendSucceeded(receivedInformation); }
} }
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation) void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
@ -228,3 +229,12 @@ void TDLibReceiver::processMessage(const QVariantMap &receivedInformation)
qDebug() << "[TDLibReceiver] Received message " << chatId << messageId; qDebug() << "[TDLibReceiver] Received message " << chatId << messageId;
emit messageInformation(messageId, receivedInformation); emit messageInformation(messageId, receivedInformation);
} }
void TDLibReceiver::processMessageSendSucceeded(const QVariantMap &receivedInformation)
{
QString oldMessageId = receivedInformation.value("old_message_id").toString();
QVariantMap message = receivedInformation.value("message").toMap();
QString messageId = message.value("id").toString();
qDebug() << "[TDLibReceiver] Message send succeeded " << messageId << oldMessageId;
emit messageSendSucceeded(messageId, oldMessageId, message);
}

View file

@ -56,6 +56,7 @@ signals:
void messagesReceived(const QVariantList &messages); void messagesReceived(const QVariantList &messages);
void newMessageReceived(const QString &chatId, const QVariantMap &message); void newMessageReceived(const QString &chatId, const QVariantMap &message);
void messageInformation(const QString &messageId, const QVariantMap &message); void messageInformation(const QString &messageId, const QVariantMap &message);
void messageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
private: private:
void *tdLibClient; void *tdLibClient;
@ -83,6 +84,7 @@ private:
void processMessages(const QVariantMap &receivedInformation); void processMessages(const QVariantMap &receivedInformation);
void processUpdateNewMessage(const QVariantMap &receivedInformation); void processUpdateNewMessage(const QVariantMap &receivedInformation);
void processMessage(const QVariantMap &receivedInformation); void processMessage(const QVariantMap &receivedInformation);
void processMessageSendSucceeded(const QVariantMap &receivedInformation);
}; };
#endif // TDLIBRECEIVER_H #endif // TDLIBRECEIVER_H

View file

@ -62,6 +62,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
connect(this->tdLibReceiver, SIGNAL(messagesReceived(QVariantList)), this, SLOT(handleMessagesReceived(QVariantList))); connect(this->tdLibReceiver, SIGNAL(messagesReceived(QVariantList)), this, SLOT(handleMessagesReceived(QVariantList)));
connect(this->tdLibReceiver, SIGNAL(newMessageReceived(QString, QVariantMap)), this, SLOT(handleNewMessageReceived(QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(newMessageReceived(QString, QVariantMap)), this, SLOT(handleNewMessageReceived(QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageInformation(QString, QVariantMap)), this, SLOT(handleMessageInformation(QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(messageInformation(QString, QVariantMap)), this, SLOT(handleMessageInformation(QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap)));
this->tdLibReceiver->start(); this->tdLibReceiver->start();
@ -487,6 +488,11 @@ void TDLibWrapper::handleMessageInformation(const QString &messageId, const QVar
emit receivedMessage(messageId, message); emit receivedMessage(messageId, message);
} }
void TDLibWrapper::handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message)
{
emit messageSendSucceeded(messageId, oldMessageId, message);
}
void TDLibWrapper::setInitialParameters() void TDLibWrapper::setInitialParameters()
{ {
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib"; qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";

View file

@ -107,6 +107,7 @@ signals:
void copyToDownloadsSuccessful(const QString &fileName, const QString &filePath); void copyToDownloadsSuccessful(const QString &fileName, const QString &filePath);
void copyToDownloadsError(const QString &fileName, const QString &filePath); void copyToDownloadsError(const QString &fileName, const QString &filePath);
void receivedMessage(const QString &messageId, const QVariantMap &message); void receivedMessage(const QString &messageId, const QVariantMap &message);
void messageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
public slots: public slots:
void handleVersionDetected(const QString &version); void handleVersionDetected(const QString &version);
@ -129,6 +130,7 @@ public slots:
void handleMessagesReceived(const QVariantList &messages); void handleMessagesReceived(const QVariantList &messages);
void handleNewMessageReceived(const QString &chatId, const QVariantMap &message); void handleNewMessageReceived(const QString &chatId, const QVariantMap &message);
void handleMessageInformation(const QString &messageId, const QVariantMap &message); void handleMessageInformation(const QString &messageId, const QVariantMap &message);
void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
private: private:
void *tdLibClient; void *tdLibClient;