Display original message excerpt in replies

This commit is contained in:
Sebastian J. Wolf 2020-08-25 16:42:46 +02:00
parent b899d03660
commit a889c95899
5 changed files with 100 additions and 0 deletions

View file

@ -330,6 +330,76 @@ Page {
visible: ( chatPage.isBasicGroup || chatPage.isSuperGroup ) && !chatPage.isChannel visible: ( chatPage.isBasicGroup || chatPage.isSuperGroup ) && !chatPage.isChannel
} }
Row {
id: inReplyToRow
spacing: Theme.paddingSmall
visible: display.reply_to_message_id !== 0
width: parent.width
property variant inReplyToMessage;
Component.onCompleted: {
if (visible) {
tdLibWrapper.getMessage(chatInformation.id, display.reply_to_message_id);
}
}
Connections {
target: tdLibWrapper
onReceivedMessage: {
if (messageId === display.reply_to_message_id.toString()) {
inReplyToRow.inReplyToMessage = message;
inReplyToUserText.text = (inReplyToRow.inReplyToMessage.sender_user_id !== chatPage.myUserId) ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(inReplyToRow.inReplyToMessage.sender_user_id)), inReplyToUserText.font.pixelSize) : qsTr("You");
inReplyToMessageText.text = Emoji.emojify(Functions.getMessageText(inReplyToRow.inReplyToMessage, true), inReplyToMessageText.font.pixelSize);
}
}
}
Rectangle {
id: inReplyToMessageRectangle
height: inReplyToMessageColumn.height
width: Theme.paddingSmall
color: Theme.secondaryHighlightColor
border.width: 0
}
Column {
id: inReplyToMessageColumn
spacing: Theme.paddingSmall
width: parent.width - Theme.paddingSmall - inReplyToMessageRectangle.width
Text {
id: inReplyToUserText
width: parent.width
font.pixelSize: Theme.fontSizeExtraSmall
font.weight: Font.ExtraBold
color: Theme.primaryColor
maximumLineCount: 1
elide: Text.ElideRight
textFormat: Text.StyledText
horizontalAlignment: Text.AlignLeft
}
Text {
id: inReplyToMessageText
font.pixelSize: Theme.fontSizeExtraSmall
color: Theme.primaryColor
width: parent.width
elide: Text.ElideRight
textFormat: Text.StyledText
onTruncatedChanged: {
// There is obviously a bug in QML in truncating text with images.
// We simply remove Emojis then...
if (truncated) {
text = text.replace(/\<img [^>]+\/\>/g, "");
}
}
}
}
}
Text { Text {
id: messageText id: messageText

View file

@ -72,6 +72,7 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
if (objectTypeName == "updateChatOnlineMemberCount") { this->processChatOnlineMemberCountUpdated(receivedInformation); } if (objectTypeName == "updateChatOnlineMemberCount") { this->processChatOnlineMemberCountUpdated(receivedInformation); }
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); }
} }
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation) void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
@ -212,3 +213,11 @@ void TDLibReceiver::processUpdateNewMessage(const QVariantMap &receivedInformati
qDebug() << "[TDLibReceiver] Received new message for chat " << chatId; qDebug() << "[TDLibReceiver] Received new message for chat " << chatId;
emit newMessageReceived(chatId, receivedInformation.value("message").toMap()); emit newMessageReceived(chatId, receivedInformation.value("message").toMap());
} }
void TDLibReceiver::processMessage(const QVariantMap &receivedInformation)
{
QString chatId = receivedInformation.value("chat_id").toString();
QString messageId = receivedInformation.value("id").toString();
qDebug() << "[TDLibReceiver] Received message " << chatId << messageId;
emit messageInformation(messageId, receivedInformation);
}

View file

@ -54,6 +54,7 @@ signals:
void chatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount); void chatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount);
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);
private: private:
void *tdLibClient; void *tdLibClient;
@ -79,6 +80,7 @@ private:
void processChatOnlineMemberCountUpdated(const QVariantMap &receivedInformation); void processChatOnlineMemberCountUpdated(const QVariantMap &receivedInformation);
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);
}; };
#endif // TDLIBRECEIVER_H #endif // TDLIBRECEIVER_H

View file

@ -58,6 +58,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
connect(this->tdLibReceiver, SIGNAL(chatOnlineMemberCountUpdated(QString, int)), this, SLOT(handleChatOnlineMemberCountUpdated(QString, int))); connect(this->tdLibReceiver, SIGNAL(chatOnlineMemberCountUpdated(QString, int)), this, SLOT(handleChatOnlineMemberCountUpdated(QString, int)));
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)));
this->tdLibReceiver->start(); this->tdLibReceiver->start();
@ -200,6 +201,16 @@ void TDLibWrapper::sendTextMessage(const QString &chatId, const QString &message
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }
void TDLibWrapper::getMessage(const QString &chatId, const QString &messageId)
{
qDebug() << "[TDLibWrapper] Retrieving message " << chatId << messageId;
QVariantMap requestObject;
requestObject.insert("@type", "getMessage");
requestObject.insert("chat_id", chatId);
requestObject.insert("message_id", messageId);
this->sendRequest(requestObject);
}
QVariantMap TDLibWrapper::getUserInformation() QVariantMap TDLibWrapper::getUserInformation()
{ {
return this->userInformation; return this->userInformation;
@ -446,6 +457,11 @@ void TDLibWrapper::handleNewMessageReceived(const QString &chatId, const QVarian
emit newMessageReceived(chatId, message); emit newMessageReceived(chatId, message);
} }
void TDLibWrapper::handleMessageInformation(const QString &messageId, const QVariantMap &message)
{
emit receivedMessage(messageId, 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

@ -81,6 +81,7 @@ public:
Q_INVOKABLE void getChatHistory(const QString &chatId, const qlonglong &fromMessageId = 0, const int &offset = 0, const int &limit = 50, const bool &onlyLocal = false); Q_INVOKABLE void getChatHistory(const QString &chatId, const qlonglong &fromMessageId = 0, const int &offset = 0, const int &limit = 50, const bool &onlyLocal = false);
Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId); Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId);
Q_INVOKABLE void sendTextMessage(const QString &chatId, const QString &message); Q_INVOKABLE void sendTextMessage(const QString &chatId, const QString &message);
Q_INVOKABLE void getMessage(const QString &chatId, const QString &messageId);
signals: signals:
void versionDetected(const QString &version); void versionDetected(const QString &version);
@ -103,6 +104,7 @@ signals:
void newMessageReceived(const QString &chatId, const QVariantMap &message); void newMessageReceived(const QString &chatId, const QVariantMap &message);
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);
public slots: public slots:
void handleVersionDetected(const QString &version); void handleVersionDetected(const QString &version);
@ -123,6 +125,7 @@ public slots:
void handleChatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount); void handleChatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount);
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);
private: private:
void *tdLibClient; void *tdLibClient;