Edit message seems to work
This commit is contained in:
parent
c2492efa0f
commit
b78a0f8731
9 changed files with 88 additions and 3 deletions
|
@ -109,6 +109,11 @@ Page {
|
||||||
|
|
||||||
function getMessageStatusText(message, listItemIndex, lastReadSentIndex) {
|
function getMessageStatusText(message, listItemIndex, lastReadSentIndex) {
|
||||||
var messageStatusSuffix = "";
|
var messageStatusSuffix = "";
|
||||||
|
|
||||||
|
if (message.edit_date > 0) {
|
||||||
|
messageStatusSuffix += " - " + qsTr("edited");
|
||||||
|
}
|
||||||
|
|
||||||
if (chatPage.myUserId === message.sender_user_id) {
|
if (chatPage.myUserId === message.sender_user_id) {
|
||||||
messageStatusSuffix += " "
|
messageStatusSuffix += " "
|
||||||
if (listItemIndex <= lastReadSentIndex) {
|
if (listItemIndex <= lastReadSentIndex) {
|
||||||
|
@ -582,6 +587,13 @@ Page {
|
||||||
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 = getMessageStatusText(display, index, lastReadSentIndex);
|
messageDateText.text = getMessageStatusText(display, index, lastReadSentIndex);
|
||||||
}
|
}
|
||||||
|
onMessageUpdated: {
|
||||||
|
if (index === modelIndex) {
|
||||||
|
console.log("[ChatModel] This message was updated, index " + index + ", updating content...");
|
||||||
|
messageDateText.text = getMessageStatusText(display, index, chatView.lastReadSentIndex);
|
||||||
|
messageText.text = Emoji.emojify(Functions.getMessageText(display, false), font.pixelSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
|
@ -721,7 +733,11 @@ Page {
|
||||||
}
|
}
|
||||||
EnterKey.onClicked: {
|
EnterKey.onClicked: {
|
||||||
if (tdLibWrapper.getSendByEnter()) {
|
if (tdLibWrapper.getSendByEnter()) {
|
||||||
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
|
if (newMessageColumn.editMessageId !== "0") {
|
||||||
|
tdLibWrapper.editMessageText(chatInformation.id, newMessageColumn.editMessageId, newMessageTextField.text);
|
||||||
|
} else {
|
||||||
|
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
|
||||||
|
}
|
||||||
newMessageTextField.text = "";
|
newMessageTextField.text = "";
|
||||||
newMessageTextField.focus = false;
|
newMessageTextField.focus = false;
|
||||||
}
|
}
|
||||||
|
@ -760,7 +776,11 @@ Page {
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
enabled: false
|
enabled: false
|
||||||
onClicked: {
|
onClicked: {
|
||||||
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
|
if (newMessageColumn.editMessageId !== "0") {
|
||||||
|
tdLibWrapper.editMessageText(chatInformation.id, newMessageColumn.editMessageId, newMessageTextField.text);
|
||||||
|
} else {
|
||||||
|
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
|
||||||
|
}
|
||||||
newMessageTextField.text = "";
|
newMessageTextField.text = "";
|
||||||
newMessageTextField.focus = false;
|
newMessageTextField.focus = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ ChatModel::ChatModel(TDLibWrapper *tdLibWrapper)
|
||||||
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)));
|
connect(this->tdLibWrapper, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap)));
|
||||||
connect(this->tdLibWrapper, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap)));
|
connect(this->tdLibWrapper, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap)));
|
||||||
|
connect(this->tdLibWrapper, SIGNAL(messageContentUpdated(QString, QString, QVariantMap)), this, SLOT(handleMessageContentUpdated(QString, QString, QVariantMap)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatModel::~ChatModel()
|
ChatModel::~ChatModel()
|
||||||
|
@ -223,6 +224,24 @@ void ChatModel::handleChatNotificationSettingsUpdated(const QString &chatId, con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatModel::handleMessageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent)
|
||||||
|
{
|
||||||
|
qDebug() << "[ChatModel] Message content updated" << chatId << messageId;
|
||||||
|
if (chatId == this->chatId && this->messageIndexMap.contains(messageId)) {
|
||||||
|
this->messagesMutex.lock();
|
||||||
|
qDebug() << "[ChatModel] We know the message that was updated " << messageId;
|
||||||
|
int messageIndex = this->messageIndexMap.value(messageId).toInt();
|
||||||
|
QVariantMap messageToBeUpdated = this->messages.at(messageIndex).toMap();
|
||||||
|
messageToBeUpdated.insert("content", newContent);
|
||||||
|
this->messages.replace(messageIndex, messageToBeUpdated);
|
||||||
|
this->calculateMessageIndexMap();
|
||||||
|
qDebug() << "[ChatModel] Message was replaced at index " << messageIndex;
|
||||||
|
this->messagesMutex.unlock();
|
||||||
|
emit messageUpdated(messageIndex);
|
||||||
|
emit dataChanged(index(messageIndex), index(messageIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ChatModel::insertMessages()
|
void ChatModel::insertMessages()
|
||||||
{
|
{
|
||||||
if (this->messages.isEmpty()) {
|
if (this->messages.isEmpty()) {
|
||||||
|
|
|
@ -48,6 +48,7 @@ signals:
|
||||||
void unreadCountUpdated(const int &unreadCount, const QString &lastReadInboxMessageId);
|
void unreadCountUpdated(const int &unreadCount, const QString &lastReadInboxMessageId);
|
||||||
void lastReadSentMessageUpdated(const int &lastReadSentIndex);
|
void lastReadSentMessageUpdated(const int &lastReadSentIndex);
|
||||||
void notificationSettingsUpdated();
|
void notificationSettingsUpdated();
|
||||||
|
void messageUpdated(const int &modelIndex);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void handleMessagesReceived(const QVariantList &messages);
|
void handleMessagesReceived(const QVariantList &messages);
|
||||||
|
@ -56,6 +57,7 @@ public slots:
|
||||||
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);
|
void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
|
||||||
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
|
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
|
||||||
|
void handleMessageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
|
||||||
if (objectTypeName == "updateActiveNotifications") { this->processUpdateActiveNotifications(receivedInformation); }
|
if (objectTypeName == "updateActiveNotifications") { this->processUpdateActiveNotifications(receivedInformation); }
|
||||||
if (objectTypeName == "updateNotificationGroup") { this->processUpdateNotificationGroup(receivedInformation); }
|
if (objectTypeName == "updateNotificationGroup") { this->processUpdateNotificationGroup(receivedInformation); }
|
||||||
if (objectTypeName == "updateChatNotificationSettings") { this->processUpdateChatNotificationSettings(receivedInformation); }
|
if (objectTypeName == "updateChatNotificationSettings") { this->processUpdateChatNotificationSettings(receivedInformation); }
|
||||||
|
if (objectTypeName == "updateMessageContent") { this->processUpdateMessageContent(receivedInformation); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
|
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
|
||||||
|
@ -266,3 +267,11 @@ void TDLibReceiver::processUpdateChatNotificationSettings(const QVariantMap &rec
|
||||||
qDebug() << "[TDLibReceiver] Received new notification settings for chat " << chatId;
|
qDebug() << "[TDLibReceiver] Received new notification settings for chat " << chatId;
|
||||||
emit chatNotificationSettingsUpdated(chatId, receivedInformation.value("notification_settings").toMap());
|
emit chatNotificationSettingsUpdated(chatId, receivedInformation.value("notification_settings").toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TDLibReceiver::processUpdateMessageContent(const QVariantMap &receivedInformation)
|
||||||
|
{
|
||||||
|
QString chatId = receivedInformation.value("chat_id").toString();
|
||||||
|
QString messageId = receivedInformation.value("message_id").toString();
|
||||||
|
qDebug() << "[TDLibReceiver] Message content updated " << chatId << messageId;
|
||||||
|
emit messageContentUpdated(chatId, messageId, receivedInformation.value("new_content").toMap());
|
||||||
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ signals:
|
||||||
void notificationGroupUpdated(const QVariantMap notificationGroupUpdate);
|
void notificationGroupUpdated(const QVariantMap notificationGroupUpdate);
|
||||||
void notificationUpdated(const QVariantMap updatedNotification);
|
void notificationUpdated(const QVariantMap updatedNotification);
|
||||||
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap updatedChatNotificationSettings);
|
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap updatedChatNotificationSettings);
|
||||||
|
void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *tdLibClient;
|
void *tdLibClient;
|
||||||
|
@ -93,6 +94,7 @@ private:
|
||||||
void processUpdateNotificationGroup(const QVariantMap &receivedInformation);
|
void processUpdateNotificationGroup(const QVariantMap &receivedInformation);
|
||||||
void processUpdateNotification(const QVariantMap &receivedInformation);
|
void processUpdateNotification(const QVariantMap &receivedInformation);
|
||||||
void processUpdateChatNotificationSettings(const QVariantMap &receivedInformation);
|
void processUpdateChatNotificationSettings(const QVariantMap &receivedInformation);
|
||||||
|
void processUpdateMessageContent(const QVariantMap &receivedInformation);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TDLIBRECEIVER_H
|
#endif // TDLIBRECEIVER_H
|
||||||
|
|
|
@ -70,6 +70,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent), settings("harbour
|
||||||
connect(this->tdLibReceiver, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SLOT(handleUpdateNotificationGroup(QVariantMap)));
|
connect(this->tdLibReceiver, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SLOT(handleUpdateNotificationGroup(QVariantMap)));
|
||||||
connect(this->tdLibReceiver, SIGNAL(notificationUpdated(QVariantMap)), this, SLOT(handleUpdateNotification(QVariantMap)));
|
connect(this->tdLibReceiver, SIGNAL(notificationUpdated(QVariantMap)), this, SLOT(handleUpdateNotification(QVariantMap)));
|
||||||
connect(this->tdLibReceiver, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap)));
|
connect(this->tdLibReceiver, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap)));
|
||||||
|
connect(this->tdLibReceiver, SIGNAL(messageContentUpdated(QString, QString, QVariantMap)), this, SLOT(handleMessageContentUpdated(QString, QString, QVariantMap)));
|
||||||
|
|
||||||
this->tdLibReceiver->start();
|
this->tdLibReceiver->start();
|
||||||
|
|
||||||
|
@ -259,6 +260,22 @@ void TDLibWrapper::setChatNotificationSettings(const QString &chatId, const QVar
|
||||||
this->sendRequest(requestObject);
|
this->sendRequest(requestObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TDLibWrapper::editMessageText(const QString &chatId, const QString &messageId, const QString &message)
|
||||||
|
{
|
||||||
|
qDebug() << "[TDLibWrapper] Editiing message text " << chatId << messageId;
|
||||||
|
QVariantMap requestObject;
|
||||||
|
requestObject.insert("@type", "editMessageText");
|
||||||
|
requestObject.insert("chat_id", chatId);
|
||||||
|
requestObject.insert("message_id", messageId);
|
||||||
|
QVariantMap inputMessageContent;
|
||||||
|
inputMessageContent.insert("@type", "inputMessageText");
|
||||||
|
QVariantMap formattedText;
|
||||||
|
formattedText.insert("text", message);
|
||||||
|
inputMessageContent.insert("text", formattedText);
|
||||||
|
requestObject.insert("input_message_content", inputMessageContent);
|
||||||
|
this->sendRequest(requestObject);
|
||||||
|
}
|
||||||
|
|
||||||
QVariantMap TDLibWrapper::getUserInformation()
|
QVariantMap TDLibWrapper::getUserInformation()
|
||||||
{
|
{
|
||||||
return this->userInformation;
|
return this->userInformation;
|
||||||
|
@ -575,6 +592,11 @@ void TDLibWrapper::handleChatNotificationSettingsUpdated(const QString &chatId,
|
||||||
emit chatNotificationSettingsUpdated(chatId, chatNotificationSettings);
|
emit chatNotificationSettingsUpdated(chatId, chatNotificationSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TDLibWrapper::handleMessageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent)
|
||||||
|
{
|
||||||
|
emit messageContentUpdated(chatId, messageId, newContent);
|
||||||
|
}
|
||||||
|
|
||||||
void TDLibWrapper::setInitialParameters()
|
void TDLibWrapper::setInitialParameters()
|
||||||
{
|
{
|
||||||
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";
|
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";
|
||||||
|
|
|
@ -94,6 +94,7 @@ public:
|
||||||
Q_INVOKABLE void getMessage(const QString &chatId, const QString &messageId);
|
Q_INVOKABLE void getMessage(const QString &chatId, const QString &messageId);
|
||||||
Q_INVOKABLE void setOptionInteger(const QString &optionName, const int &optionValue);
|
Q_INVOKABLE void setOptionInteger(const QString &optionName, const int &optionValue);
|
||||||
Q_INVOKABLE void setChatNotificationSettings(const QString &chatId, const QVariantMap ¬ificationSettings);
|
Q_INVOKABLE void setChatNotificationSettings(const QString &chatId, const QVariantMap ¬ificationSettings);
|
||||||
|
Q_INVOKABLE void editMessageText(const QString &chatId, const QString &messageId, const QString &message);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void versionDetected(const QString &version);
|
void versionDetected(const QString &version);
|
||||||
|
@ -123,6 +124,7 @@ signals:
|
||||||
void notificationGroupUpdated(const QVariantMap notificationGroupUpdate);
|
void notificationGroupUpdated(const QVariantMap notificationGroupUpdate);
|
||||||
void notificationUpdated(const QVariantMap updatedNotification);
|
void notificationUpdated(const QVariantMap updatedNotification);
|
||||||
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap chatNotificationSettings);
|
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap chatNotificationSettings);
|
||||||
|
void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void handleVersionDetected(const QString &version);
|
void handleVersionDetected(const QString &version);
|
||||||
|
@ -150,6 +152,7 @@ public slots:
|
||||||
void handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate);
|
void handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate);
|
||||||
void handleUpdateNotification(const QVariantMap updatedNotification);
|
void handleUpdateNotification(const QVariantMap updatedNotification);
|
||||||
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
|
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
|
||||||
|
void handleMessageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *tdLibClient;
|
void *tdLibClient;
|
||||||
|
|
|
@ -163,7 +163,11 @@
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Edit Message</source>
|
<source>Edit Message</source>
|
||||||
<translation>Nachricht ändern</translation>
|
<translation>Nachricht editieren</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>edited</source>
|
||||||
|
<translation>editiert</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
|
|
|
@ -165,6 +165,10 @@
|
||||||
<source>Edit Message</source>
|
<source>Edit Message</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>edited</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>CoverPage</name>
|
<name>CoverPage</name>
|
||||||
|
|
Loading…
Reference in a new issue