Deleting messages seems to work...

This commit is contained in:
Sebastian J. Wolf 2020-09-20 00:13:42 +02:00
parent b78a0f8731
commit 64b6c8607e
11 changed files with 95 additions and 4 deletions

View file

@ -111,7 +111,7 @@ Page {
var messageStatusSuffix = "";
if (message.edit_date > 0) {
messageStatusSuffix += " - " + qsTr("edited");
messageStatusSuffix += " - " + qsTr("edited");
}
if (chatPage.myUserId === message.sender_user_id) {
@ -409,6 +409,13 @@ Page {
text: qsTr("Edit Message")
visible: display.can_be_edited
}
MenuItem {
onClicked: {
deleteMessageRemorseItem.execute(messageListItem, qsTr("Deleting message"), function() { tdLibWrapper.deleteMessages(chatInformation.id, [ display.id ]); } );
}
text: qsTr("Delete Message")
visible: display.can_be_deleted_for_all_users
}
}
Connections {
@ -423,6 +430,10 @@ Page {
}
}
RemorseItem {
id: deleteMessageRemorseItem
}
Row {
id: messageTextRow
spacing: Theme.paddingSmall

View file

@ -69,6 +69,12 @@ void ChatListModel::enableDeltaUpdates()
this->deltaUpdates = true;
}
void ChatListModel::redrawModel()
{
qDebug() << "[ChatListModel] Enforcing UI redraw...";
layoutChanged();
}
bool compareChats(const QVariant &chat1, const QVariant &chat2)
{
QVariantMap chatMap1 = chat1.toMap();

View file

@ -37,6 +37,7 @@ public:
virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
Q_INVOKABLE void enableDeltaUpdates();
Q_INVOKABLE void redrawModel();
signals:
void chatChanged(const QString &chatId);

View file

@ -35,6 +35,7 @@ ChatModel::ChatModel(TDLibWrapper *tdLibWrapper)
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(messageContentUpdated(QString, QString, QVariantMap)), this, SLOT(handleMessageContentUpdated(QString, QString, QVariantMap)));
connect(this->tdLibWrapper, SIGNAL(messagesDeleted(QString, QVariantList)), this, SLOT(handleMessagesDeleted(QString, QVariantList)));
}
ChatModel::~ChatModel()
@ -242,6 +243,29 @@ void ChatModel::handleMessageContentUpdated(const QString &chatId, const QString
}
}
void ChatModel::handleMessagesDeleted(const QString &chatId, const QVariantList &messageIds)
{
qDebug() << "[ChatModel] Messages were deleted in a chat" << chatId;
if (chatId == this->chatId) {
this->messagesMutex.lock();
qDebug() << "[ChatModel] Messages in this chat were deleted...";
QListIterator<QVariant> messageIdIterator(messageIds);
while (messageIdIterator.hasNext()) {
QString messageId = messageIdIterator.next().toString();
if (this->messageIndexMap.contains(messageId)) {
int messageIndex = this->messageIndexMap.value(messageId).toInt();
beginRemoveRows(QModelIndex(), messageIndex, messageIndex);
qDebug() << "[ChatModel] ...and we even know this message!" << messageId << messageIndex;
this->messages.removeAt(messageIndex);
this->calculateMessageIndexMap();
endRemoveRows();
}
}
this->messagesMutex.unlock();
emit messagesDeleted();
}
}
void ChatModel::insertMessages()
{
if (this->messages.isEmpty()) {

View file

@ -49,6 +49,7 @@ signals:
void lastReadSentMessageUpdated(const int &lastReadSentIndex);
void notificationSettingsUpdated();
void messageUpdated(const int &modelIndex);
void messagesDeleted();
public slots:
void handleMessagesReceived(const QVariantList &messages);
@ -58,6 +59,7 @@ public slots:
void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
void handleMessageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
void handleMessagesDeleted(const QString &chatId, const QVariantList &messageIds);
private:

View file

@ -79,6 +79,7 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
if (objectTypeName == "updateNotificationGroup") { this->processUpdateNotificationGroup(receivedInformation); }
if (objectTypeName == "updateChatNotificationSettings") { this->processUpdateChatNotificationSettings(receivedInformation); }
if (objectTypeName == "updateMessageContent") { this->processUpdateMessageContent(receivedInformation); }
if (objectTypeName == "updateDeleteMessages") { this->processUpdateDeleteMessages(receivedInformation); }
}
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
@ -275,3 +276,11 @@ void TDLibReceiver::processUpdateMessageContent(const QVariantMap &receivedInfor
qDebug() << "[TDLibReceiver] Message content updated " << chatId << messageId;
emit messageContentUpdated(chatId, messageId, receivedInformation.value("new_content").toMap());
}
void TDLibReceiver::processUpdateDeleteMessages(const QVariantMap &receivedInformation)
{
QString chatId = receivedInformation.value("chat_id").toString();
QVariantList messageIds = receivedInformation.value("message_ids").toList();
qDebug() << "[TDLibReceiver] Some messages were deleted " << chatId << messageIds;
emit messagesDeleted(chatId, messageIds);
}

View file

@ -62,6 +62,7 @@ signals:
void notificationUpdated(const QVariantMap updatedNotification);
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap updatedChatNotificationSettings);
void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
void messagesDeleted(const QString &chatId, const QVariantList &messageIds);
private:
void *tdLibClient;
@ -95,6 +96,7 @@ private:
void processUpdateNotification(const QVariantMap &receivedInformation);
void processUpdateChatNotificationSettings(const QVariantMap &receivedInformation);
void processUpdateMessageContent(const QVariantMap &receivedInformation);
void processUpdateDeleteMessages(const QVariantMap &receivedInformation);
};
#endif // TDLIBRECEIVER_H

View file

@ -71,6 +71,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent), settings("harbour
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(messageContentUpdated(QString, QString, QVariantMap)), this, SLOT(handleMessageContentUpdated(QString, QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messagesDeleted(QString, QVariantList)), this, SLOT(handleMessagesDeleted(QString, QVariantList)));
this->tdLibReceiver->start();
@ -262,7 +263,7 @@ void TDLibWrapper::setChatNotificationSettings(const QString &chatId, const QVar
void TDLibWrapper::editMessageText(const QString &chatId, const QString &messageId, const QString &message)
{
qDebug() << "[TDLibWrapper] Editiing message text " << chatId << messageId;
qDebug() << "[TDLibWrapper] Editing message text " << chatId << messageId;
QVariantMap requestObject;
requestObject.insert("@type", "editMessageText");
requestObject.insert("chat_id", chatId);
@ -276,6 +277,17 @@ void TDLibWrapper::editMessageText(const QString &chatId, const QString &message
this->sendRequest(requestObject);
}
void TDLibWrapper::deleteMessages(const QString &chatId, const QVariantList messageIds)
{
qDebug() << "[TDLibWrapper] Deleting some messages " << chatId << messageIds;
QVariantMap requestObject;
requestObject.insert("@type", "deleteMessages");
requestObject.insert("chat_id", chatId);
requestObject.insert("message_ids", messageIds);
requestObject.insert("revoke", true);
this->sendRequest(requestObject);
}
QVariantMap TDLibWrapper::getUserInformation()
{
return this->userInformation;
@ -597,6 +609,11 @@ void TDLibWrapper::handleMessageContentUpdated(const QString &chatId, const QStr
emit messageContentUpdated(chatId, messageId, newContent);
}
void TDLibWrapper::handleMessagesDeleted(const QString &chatId, const QVariantList &messageIds)
{
emit messagesDeleted(chatId, messageIds);
}
void TDLibWrapper::setInitialParameters()
{
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";

View file

@ -95,6 +95,7 @@ public:
Q_INVOKABLE void setOptionInteger(const QString &optionName, const int &optionValue);
Q_INVOKABLE void setChatNotificationSettings(const QString &chatId, const QVariantMap &notificationSettings);
Q_INVOKABLE void editMessageText(const QString &chatId, const QString &messageId, const QString &message);
Q_INVOKABLE void deleteMessages(const QString &chatId, const QVariantList messageIds);
signals:
void versionDetected(const QString &version);
@ -125,6 +126,7 @@ signals:
void notificationUpdated(const QVariantMap updatedNotification);
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap chatNotificationSettings);
void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
void messagesDeleted(const QString &chatId, const QVariantList &messageIds);
public slots:
void handleVersionDetected(const QString &version);
@ -153,6 +155,7 @@ public slots:
void handleUpdateNotification(const QVariantMap updatedNotification);
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
void handleMessageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
void handleMessagesDeleted(const QString &chatId, const QVariantList &messageIds);
private:
void *tdLibClient;

View file

@ -163,11 +163,19 @@
</message>
<message>
<source>Edit Message</source>
<translation>Nachricht editieren</translation>
<translation>Nachricht bearbeiten</translation>
</message>
<message>
<source>edited</source>
<translation>editiert</translation>
<translation>bearbeitet</translation>
</message>
<message>
<source>Deleting message</source>
<translation>Lösche Nachricht</translation>
</message>
<message>
<source>Delete Message</source>
<translation>Nachricht löschen</translation>
</message>
</context>
<context>

View file

@ -169,6 +169,14 @@
<source>edited</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Deleting message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Delete Message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CoverPage</name>