diff --git a/qml/components/MessageListViewItem.qml b/qml/components/MessageListViewItem.qml
index 1204f6f..da91f29 100644
--- a/qml/components/MessageListViewItem.qml
+++ b/qml/components/MessageListViewItem.qml
@@ -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 {
diff --git a/qml/components/PinnedMessageItem.qml b/qml/components/PinnedMessageItem.qml
index 593bb74..93b6c92 100644
--- a/qml/components/PinnedMessageItem.qml
+++ b/qml/components/PinnedMessageItem.qml
@@ -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(); });
}
diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml
index 25b7165..ef793a3 100644
--- a/qml/pages/ChatPage.qml
+++ b/qml/pages/ChatPage.qml
@@ -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;
}
diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp
index 545422d..f7e85b3 100644
--- a/src/chatmodel.cpp
+++ b/src/chatmodel.cpp
@@ -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) {
diff --git a/src/chatmodel.h b/src/chatmodel.h
index cfea0a9..9353037 100644
--- a/src/chatmodel.h
+++ b/src/chatmodel.h
@@ -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);
diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp
index 94000b2..301e779 100644
--- a/src/tdlibreceiver.cpp
+++ b/src/tdlibreceiver.cpp
@@ -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");
diff --git a/src/tdlibreceiver.h b/src/tdlibreceiver.h
index 42ea9aa..727b7ad 100644
--- a/src/tdlibreceiver.h
+++ b/src/tdlibreceiver.h
@@ -81,8 +81,9 @@ signals:
void userProfilePhotos(const QString &extra, const QVariantList &photos, int totalPhotos);
void chatPermissionsUpdated(const QString &chatId, const QVariantMap &chatPermissions);
void chatPhotoUpdated(qlonglong chatId, const QVariantMap &photo);
- void chatTitleUpdated(const QString &chatId, const QString &title);
+ 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);
diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp
index 785a834..5e3ed51 100644
--- a/src/tdlibwrapper.cpp
+++ b/src/tdlibwrapper.cpp
@@ -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");
diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h
index d41cdb4..50eb2fb 100644
--- a/src/tdlibwrapper.h
+++ b/src/tdlibwrapper.h
@@ -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 ¬ificationSettings);
@@ -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);
diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts
index 7a6cd82..4f8be73 100644
--- a/translations/harbour-fernschreiber-de.ts
+++ b/translations/harbour-fernschreiber-de.ts
@@ -904,6 +904,14 @@
Nachricht anheften
+
+
+ Nachricht losgeheftet
+
+
+
+ Nachricht losheften
+
MessageListViewItemSimple
diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts
index 5d5ce04..503c588 100644
--- a/translations/harbour-fernschreiber-en.ts
+++ b/translations/harbour-fernschreiber-en.ts
@@ -904,6 +904,14 @@
Pin Message
+
+
+ Message unpinned
+
+
+
+ Unpin Message
+
MessageListViewItemSimple
diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts
index d03fc54..6a557ab 100644
--- a/translations/harbour-fernschreiber-es.ts
+++ b/translations/harbour-fernschreiber-es.ts
@@ -894,6 +894,14 @@
Anclar mensaje
+
+
+ Desanclar mensaje
+
+
+
+
+
MessageListViewItemSimple
diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts
index 852b3db..d9f1dcc 100644
--- a/translations/harbour-fernschreiber-fi.ts
+++ b/translations/harbour-fernschreiber-fi.ts
@@ -905,6 +905,14 @@
Kiinnitä viesti
+
+
+ Viestin kiinnitys poistettu
+
+
+
+
+
MessageListViewItemSimple
diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts
index 1fe058b..3b6404c 100644
--- a/translations/harbour-fernschreiber-hu.ts
+++ b/translations/harbour-fernschreiber-hu.ts
@@ -894,6 +894,14 @@
+
+
+
+
+
+
+
+
MessageListViewItemSimple
diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts
index 462b213..f7fdd66 100644
--- a/translations/harbour-fernschreiber-it.ts
+++ b/translations/harbour-fernschreiber-it.ts
@@ -904,6 +904,14 @@
Metti messaggio in evidenza
+
+
+ Messaggio non più in evidenza
+
+
+
+
+
MessageListViewItemSimple
diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts
index b288bf1..022f13f 100644
--- a/translations/harbour-fernschreiber-pl.ts
+++ b/translations/harbour-fernschreiber-pl.ts
@@ -914,6 +914,14 @@
Przypnij wiadomość
+
+
+ Wiadomość opięta
+
+
+
+
+
MessageListViewItemSimple
diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts
index db06186..567fe61 100644
--- a/translations/harbour-fernschreiber-ru.ts
+++ b/translations/harbour-fernschreiber-ru.ts
@@ -914,6 +914,14 @@
Закрепить сообщение
+
+
+ Сообщение откреплено
+
+
+
+
+
MessageListViewItemSimple
diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts
index 94844e1..01e9690 100644
--- a/translations/harbour-fernschreiber-sv.ts
+++ b/translations/harbour-fernschreiber-sv.ts
@@ -904,6 +904,14 @@
Fäst meddelandet
+
+
+ Meddelandet lösgjort
+
+
+
+
+
MessageListViewItemSimple
diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts
index 1e922cc..3bfd943 100644
--- a/translations/harbour-fernschreiber-zh_CN.ts
+++ b/translations/harbour-fernschreiber-zh_CN.ts
@@ -894,6 +894,14 @@
置顶消息
+
+
+ 已取消置顶消息
+
+
+
+
+
MessageListViewItemSimple
diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts
index 6251eb4..e84fe15 100644
--- a/translations/harbour-fernschreiber.ts
+++ b/translations/harbour-fernschreiber.ts
@@ -904,6 +904,14 @@
+
+
+
+
+
+
+
+
MessageListViewItemSimple