TDLib 1.7: Bring back pinned messages (nobody noticed so far?)

This commit is contained in:
Sebastian Wolf 2020-12-25 22:38:13 +01:00
parent 4e680a9a3f
commit fe0b390a87
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
20 changed files with 170 additions and 12 deletions

View file

@ -118,9 +118,14 @@ ListItem {
}
MenuItem {
onClicked: {
tdLibWrapper.pinMessage(page.chatInformation.id, messageId)
if (myMessage.is_pinned) {
Remorse.popupAction(page, qsTr("Message unpinned"), function() { tdLibWrapper.unpinMessage(page.chatInformation.id, messageId);
pinnedMessageItem.requestCloseMessage(); } );
} else {
tdLibWrapper.pinMessage(page.chatInformation.id, messageId);
}
}
text: qsTr("Pin Message")
text: myMessage.is_pinned ? qsTr("Unpin Message") : qsTr("Pin Message")
visible: canPinMessages()
}
MenuItem {

View file

@ -123,7 +123,7 @@ Item {
id: unpinMessageIconButton
icon.source: "image://theme/icon-m-remove"
onClicked: {
Remorse.itemAction(pinnedMessageRow, qsTr("Message unpinned"), function() { tdLibWrapper.unpinMessage(chatPage.chatInformation.id);
Remorse.itemAction(pinnedMessageRow, qsTr("Message unpinned"), function() { tdLibWrapper.unpinMessage(chatPage.chatInformation.id, pinnedMessage.id);
pinnedMessageItem.requestCloseMessage(); });
}

View file

@ -170,10 +170,7 @@ Page {
tdLibWrapper.getInstalledStickerSets();
stickerManager.setNeedsReload(false);
}
if (chatInformation.pinned_message_id.toString() !== "0") {
Debug.log("[ChatPage] Loading pinned message ", chatInformation.pinned_message_id);
tdLibWrapper.getMessage(chatInformation.id, chatInformation.pinned_message_id);
}
tdLibWrapper.getChatPinnedMessage(chatInformation.id);
}
function getMessageStatusText(message, listItemIndex, lastReadSentIndex, useElapsed) {
@ -422,7 +419,7 @@ Page {
Functions.handleErrorMessage(code, message);
}
onReceivedMessage: {
if (messageId === chatInformation.pinned_message_id.toString()) {
if (message.is_pinned) {
Debug.log("[ChatPage] Received pinned message");
pinnedMessageItem.pinnedMessage = message;
}

View file

@ -104,6 +104,7 @@ ChatModel::ChatModel(TDLibWrapper *tdLibWrapper) :
this->tdLibWrapper = tdLibWrapper;
connect(this->tdLibWrapper, SIGNAL(messagesReceived(QVariantList, int)), this, SLOT(handleMessagesReceived(QVariantList, int)));
connect(this->tdLibWrapper, SIGNAL(newMessageReceived(qlonglong, QVariantMap)), this, SLOT(handleNewMessageReceived(qlonglong, QVariantMap)));
connect(this->tdLibWrapper, SIGNAL(receivedMessage(QString, QVariantMap)), this, SLOT(handleMessageReceived(QString, QVariantMap)));
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(qlonglong, qlonglong, QVariantMap)), this, SLOT(handleMessageSendSucceeded(qlonglong, qlonglong, QVariantMap)));
@ -326,6 +327,20 @@ void ChatModel::handleNewMessageReceived(qlonglong chatId, const QVariantMap &me
}
}
void ChatModel::handleMessageReceived(const QString &messageId, const QVariantMap &message)
{
const qlonglong messageIdLL = messageId.toLongLong();
if (messageIndexMap.contains(messageIdLL)) {
LOG("Received a message that we already know, let's update it!");
const int position = messageIndexMap.value(messageIdLL);
MessageData *messageData = messages.at(position);
messageData->messageData = message;
LOG("Message was updated at index" << position);
const QModelIndex messageIndex(index(position));
emit dataChanged(messageIndex, messageIndex);
}
}
void ChatModel::handleChatReadInboxUpdated(const QString &id, const QString &lastReadInboxMessageId, int unreadCount)
{
if (id.toLongLong() == chatId) {

View file

@ -63,6 +63,7 @@ signals:
private slots:
void handleMessagesReceived(const QVariantList &messages, int totalCount);
void handleNewMessageReceived(qlonglong chatId, const QVariantMap &message);
void handleMessageReceived(const QString &messageId, const QVariantMap &message);
void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, int unreadCount);
void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
void handleMessageSendSucceeded(qlonglong messageId, qlonglong oldMessageId, const QVariantMap &message);

View file

@ -125,6 +125,7 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren
handlers.insert("updateChatPhoto", &TDLibReceiver::processUpdateChatPhoto);
handlers.insert("updateChatTitle", &TDLibReceiver::processUpdateChatTitle);
handlers.insert("updateChatPinnedMessage", &TDLibReceiver::processUpdateChatPinnedMessage);
handlers.insert("updateMessageIsPinned", &TDLibReceiver::processUpdateMessageIsPinned);
handlers.insert("users", &TDLibReceiver::processUsers);
handlers.insert("error", &TDLibReceiver::processError);
handlers.insert("ok", &TDLibReceiver::nop);
@ -519,6 +520,12 @@ void TDLibReceiver::processUpdateChatPinnedMessage(const QVariantMap &receivedIn
emit chatPinnedMessageUpdated(receivedInformation.value(CHAT_ID).toLongLong(), receivedInformation.value("pinned_message_id").toLongLong());
}
void TDLibReceiver::processUpdateMessageIsPinned(const QVariantMap &receivedInformation)
{
LOG("Received UpdateMessageIsPinned");
emit messageIsPinnedUpdated(receivedInformation.value(CHAT_ID).toLongLong(), receivedInformation.value(MESSAGE_ID).toLongLong(), receivedInformation.value("is_pinned").toBool());
}
void TDLibReceiver::processUsers(const QVariantMap &receivedInformation)
{
LOG("Received Users");

View file

@ -83,6 +83,7 @@ signals:
void chatPhotoUpdated(qlonglong chatId, const QVariantMap &photo);
void chatTitleUpdated(const QString &chatId, const QString &title);
void chatPinnedMessageUpdated(qlonglong chatId, qlonglong pinnedMessageId);
void messageIsPinnedUpdated(qlonglong chatId, qlonglong messageId, bool isPinned);
void usersReceived(const QString &extra, const QVariantList &userIds, int totalUsers);
void errorReceived(const int code, const QString &message, const QString &extra);
void secretChat(qlonglong secretChatId, const QVariantMap &secretChat);
@ -145,6 +146,7 @@ private:
void processUpdateChatPhoto(const QVariantMap &receivedInformation);
void processUpdateChatTitle(const QVariantMap &receivedInformation);
void processUpdateChatPinnedMessage(const QVariantMap &receivedInformation);
void processUpdateMessageIsPinned(const QVariantMap &receivedInformation);
void processUsers(const QVariantMap &receivedInformation);
void processError(const QVariantMap &receivedInformation);
void nop(const QVariantMap &receivedInformation);

View file

@ -39,6 +39,7 @@
namespace {
const QString STATUS("status");
const QString ID("id");
const QString CHAT_ID("chat_id");
const QString TYPE("type");
const QString LAST_NAME("last_name");
const QString FIRST_NAME("first_name");
@ -89,7 +90,7 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface,
connect(this->tdLibReceiver, SIGNAL(chatOnlineMemberCountUpdated(QString, int)), this, SIGNAL(chatOnlineMemberCountUpdated(QString, int)));
connect(this->tdLibReceiver, SIGNAL(messagesReceived(QVariantList, int)), this, SIGNAL(messagesReceived(QVariantList, int)));
connect(this->tdLibReceiver, SIGNAL(newMessageReceived(qlonglong, QVariantMap)), this, SIGNAL(newMessageReceived(qlonglong, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageInformation(QString, QVariantMap)), this, SIGNAL(receivedMessage(QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageInformation(QString, QVariantMap)), this, SLOT(handleMessageInformation(QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageSendSucceeded(qlonglong, qlonglong, QVariantMap)), this, SIGNAL(messageSendSucceeded(qlonglong, qlonglong, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SIGNAL(activeNotificationsUpdated(QVariantList)));
connect(this->tdLibReceiver, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SIGNAL(notificationGroupUpdated(QVariantMap)));
@ -118,6 +119,7 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface,
connect(this->tdLibReceiver, SIGNAL(chatPhotoUpdated(qlonglong, QVariantMap)), this, SIGNAL(chatPhotoUpdated(qlonglong, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(chatTitleUpdated(QString, QString)), this, SIGNAL(chatTitleUpdated(QString, QString)));
connect(this->tdLibReceiver, SIGNAL(chatPinnedMessageUpdated(qlonglong, qlonglong)), this, SIGNAL(chatPinnedMessageUpdated(qlonglong, qlonglong)));
connect(this->tdLibReceiver, SIGNAL(messageIsPinnedUpdated(qlonglong, qlonglong, bool)), this, SLOT(handleMessageIsPinnedUpdated(qlonglong, qlonglong, bool)));
connect(this->tdLibReceiver, SIGNAL(usersReceived(QString, QVariantList, int)), this, SIGNAL(usersReceived(QString, QVariantList, int)));
connect(this->tdLibReceiver, SIGNAL(errorReceived(int, QString, QString)), this, SLOT(handleErrorReceived(int, QString, QString)));
connect(this->tdLibReceiver, SIGNAL(contactsImported(QVariantList, QVariantList)), this, SIGNAL(contactsImported(QVariantList, QVariantList)));
@ -310,12 +312,14 @@ void TDLibWrapper::pinMessage(const QString &chatId, const QString &messageId, b
this->sendRequest(requestObject);
}
void TDLibWrapper::unpinMessage(const QString &chatId)
void TDLibWrapper::unpinMessage(const QString &chatId, const QString &messageId)
{
LOG("Unpin message from chat" << chatId);
QVariantMap requestObject;
requestObject.insert(_TYPE, "unpinChatMessage");
requestObject.insert("chat_id", chatId);
requestObject.insert("message_id", messageId);
requestObject.insert(_EXTRA, "unpinChatMessage:" + chatId);
this->sendRequest(requestObject);
}
@ -541,6 +545,16 @@ void TDLibWrapper::getMessage(const QString &chatId, const QString &messageId)
this->sendRequest(requestObject);
}
void TDLibWrapper::getChatPinnedMessage(const qlonglong &chatId)
{
LOG("Retrieving pinned message" << chatId);
QVariantMap requestObject;
requestObject.insert(_TYPE, "getChatPinnedMessage");
requestObject.insert("chat_id", chatId);
requestObject.insert(_EXTRA, "getChatPinnedMessage:" + QString::number(chatId));
this->sendRequest(requestObject);
}
void TDLibWrapper::setOptionInteger(const QString &optionName, int optionValue)
{
LOG("Setting integer option" << optionName << optionValue);
@ -1281,6 +1295,32 @@ void TDLibWrapper::handleErrorReceived(const int code, const QString &message, c
emit errorReceived(code, message, extra);
}
void TDLibWrapper::handleMessageInformation(const QString &messageId, const QVariantMap &receivedInformation)
{
QString extraInformation = receivedInformation.value(_EXTRA).toString();
if (extraInformation.startsWith("getChatPinnedMessage")) {
emit chatPinnedMessageUpdated(receivedInformation.value(CHAT_ID).toLongLong(), messageId.toLongLong());
// Sometimes it seems that pinned messages aren't returned as pinned ones, weird!
// This is a workaround for now, let's see what comes out of https://github.com/tdlib/td/issues/1343
QVariantMap updatedInformation(receivedInformation);
updatedInformation.insert("is_pinned", true);
emit receivedMessage(messageId, updatedInformation);
} else {
emit receivedMessage(messageId, receivedInformation);
}
}
void TDLibWrapper::handleMessageIsPinnedUpdated(qlonglong chatId, qlonglong messageId, bool isPinned)
{
if (isPinned) {
emit chatPinnedMessageUpdated(chatId, messageId);
} else {
emit chatPinnedMessageUpdated(chatId, 0);
this->getChatPinnedMessage(chatId);
}
}
void TDLibWrapper::setInitialParameters()
{
LOG("Sending initial parameters to TD Lib");

View file

@ -134,7 +134,7 @@ public:
Q_INVOKABLE void getChatHistory(qlonglong chatId, const qlonglong &fromMessageId = 0, int offset = -1, int limit = 50, bool onlyLocal = false);
Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId, bool force);
Q_INVOKABLE void pinMessage(const QString &chatId, const QString &messageId, bool disableNotification = false);
Q_INVOKABLE void unpinMessage(const QString &chatId);
Q_INVOKABLE void unpinMessage(const QString &chatId, const QString &messageId);
Q_INVOKABLE void sendTextMessage(const QString &chatId, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendPhotoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendVideoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
@ -143,6 +143,7 @@ public:
Q_INVOKABLE void sendPollMessage(const QString &chatId, const QString &question, const QVariantList &options, const bool &anonymous, const int &correctOption, const bool &multiple, const QString &replyToMessageId = "0");
Q_INVOKABLE void forwardMessages(const QString &chatId, const QString &fromChatId, const QVariantList &messageIds, const bool sendCopy, const bool removeCaption);
Q_INVOKABLE void getMessage(const QString &chatId, const QString &messageId);
Q_INVOKABLE void getChatPinnedMessage(const qlonglong &chatId);
Q_INVOKABLE void setOptionInteger(const QString &optionName, int optionValue);
Q_INVOKABLE void setOptionBoolean(const QString &optionName, bool optionValue);
Q_INVOKABLE void setChatNotificationSettings(const QString &chatId, const QVariantMap &notificationSettings);
@ -267,6 +268,8 @@ public slots:
void handleSecretChatUpdated(qlonglong secretChatId, const QVariantMap &secretChat);
void handleStorageOptimizerChanged();
void handleErrorReceived(const int code, const QString &message, const QString &extra);
void handleMessageInformation(const QString &messageId, const QVariantMap &receivedInformation);
void handleMessageIsPinnedUpdated(qlonglong chatId, qlonglong messageId, bool isPinned);
private:
void setOption(const QString &name, const QString &type, const QVariant &value);

View file

@ -904,6 +904,14 @@
<source>Pin Message</source>
<translation>Nachricht anheften</translation>
</message>
<message>
<source>Message unpinned</source>
<translation>Nachricht losgeheftet</translation>
</message>
<message>
<source>Unpin Message</source>
<translation>Nachricht losheften</translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>

View file

@ -904,6 +904,14 @@
<source>Pin Message</source>
<translation>Pin Message</translation>
</message>
<message>
<source>Message unpinned</source>
<translation>Message unpinned</translation>
</message>
<message>
<source>Unpin Message</source>
<translation>Unpin Message</translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>

View file

@ -894,6 +894,14 @@
<source>Pin Message</source>
<translation>Anclar mensaje </translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished">Desanclar mensaje</translation>
</message>
<message>
<source>Unpin Message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>

View file

@ -905,6 +905,14 @@
<source>Pin Message</source>
<translation>Kiinnitä viesti</translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished">Viestin kiinnitys poistettu</translation>
</message>
<message>
<source>Unpin Message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>

View file

@ -894,6 +894,14 @@
<source>Pin Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unpin Message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>

View file

@ -904,6 +904,14 @@
<source>Pin Message</source>
<translation>Metti messaggio in evidenza</translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished">Messaggio non più in evidenza</translation>
</message>
<message>
<source>Unpin Message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>

View file

@ -914,6 +914,14 @@
<source>Pin Message</source>
<translation>Przypnij wiadomość</translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished">Wiadomość opięta</translation>
</message>
<message>
<source>Unpin Message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>

View file

@ -914,6 +914,14 @@
<source>Pin Message</source>
<translation>Закрепить сообщение</translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished">Сообщение откреплено</translation>
</message>
<message>
<source>Unpin Message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>

View file

@ -904,6 +904,14 @@
<source>Pin Message</source>
<translation>Fäst meddelandet</translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished">Meddelandet lösgjort</translation>
</message>
<message>
<source>Unpin Message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>

View file

@ -894,6 +894,14 @@
<source>Pin Message</source>
<translation></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unpin Message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>

View file

@ -904,6 +904,14 @@
<source>Pin Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unpin Message</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MessageListViewItemSimple</name>