TDLib 1.8.0: New format for sponsored messages
This commit is contained in:
parent
fcbf9d65f1
commit
932f483b7a
7 changed files with 34 additions and 41 deletions
|
@ -572,7 +572,7 @@ Page {
|
|||
chatPage.botInformation = userFullInfo;
|
||||
}
|
||||
}
|
||||
onSponsoredMessagesReceived: {
|
||||
onSponsoredMessageReceived: {
|
||||
chatPage.containsSponsoredMessages = true;
|
||||
}
|
||||
}
|
||||
|
@ -707,7 +707,7 @@ Page {
|
|||
var messageToRead = chatModel.getMessage(lastQueuedIndex);
|
||||
if (messageToRead['@type'] === "sponsoredMessage") {
|
||||
Debug.log("sponsored message to read: ", messageToRead.id);
|
||||
tdLibWrapper.viewSponsoredMessage(chatInformation.id, messageToRead.id);
|
||||
tdLibWrapper.viewMessage(chatInformation.id, messageToRead.message_id, false);
|
||||
} else if (chatInformation.unread_count > 0 && lastQueuedIndex > -1) {
|
||||
Debug.log("message to read: ", messageToRead.id);
|
||||
if (messageToRead && messageToRead.id) {
|
||||
|
@ -1124,7 +1124,7 @@ Page {
|
|||
chatPage.isInitialized = true;
|
||||
chatView.handleScrollPositionChanged();
|
||||
if (chatPage.isChannel) {
|
||||
tdLibWrapper.getChatSponsoredMessages(chatInformation.id);
|
||||
tdLibWrapper.getChatSponsoredMessage(chatInformation.id);
|
||||
}
|
||||
if (typeof chatPage.messageToShow !== "undefined" && chatPage.messageToShow !== {}) {
|
||||
messageOverlayLoader.overlayMessage = chatPage.messageToShow;
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace {
|
|||
const QString LAST_READ_OUTBOX_MESSAGE_ID("last_read_outbox_message_id");
|
||||
const QString SENDER_ID("sender_id");
|
||||
const QString USER_ID("user_id");
|
||||
const QString MESSAGE_ID("message_id");
|
||||
const QString PINNED_MESSAGE_ID("pinned_message_id");
|
||||
const QString REPLY_MARKUP("reply_markup");
|
||||
const QString _TYPE("@type");
|
||||
|
@ -248,7 +249,7 @@ ChatModel::ChatModel(TDLibWrapper *tdLibWrapper) :
|
|||
{
|
||||
this->tdLibWrapper = tdLibWrapper;
|
||||
connect(this->tdLibWrapper, SIGNAL(messagesReceived(QVariantList, int)), this, SLOT(handleMessagesReceived(QVariantList, int)));
|
||||
connect(this->tdLibWrapper, SIGNAL(sponsoredMessagesReceived(qlonglong, QVariantList)), this, SLOT(handleSponsoredMessagesReceived(qlonglong, QVariantList)));
|
||||
connect(this->tdLibWrapper, SIGNAL(sponsoredMessageReceived(qlonglong, QVariantMap)), this, SLOT(handleSponsoredMessageReceived(qlonglong, QVariantMap)));
|
||||
connect(this->tdLibWrapper, SIGNAL(newMessageReceived(qlonglong, QVariantMap)), this, SLOT(handleNewMessageReceived(qlonglong, QVariantMap)));
|
||||
connect(this->tdLibWrapper, SIGNAL(receivedMessage(qlonglong, qlonglong, QVariantMap)), this, SLOT(handleMessageReceived(qlonglong, qlonglong, QVariantMap)));
|
||||
connect(this->tdLibWrapper, SIGNAL(chatReadInboxUpdated(QString, QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, QString, int)));
|
||||
|
@ -479,22 +480,17 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages, int totalCo
|
|||
|
||||
}
|
||||
|
||||
void ChatModel::handleSponsoredMessagesReceived(qlonglong chatId, const QVariantList &sponsoredMessages)
|
||||
void ChatModel::handleSponsoredMessageReceived(qlonglong chatId, const QVariantMap &sponsoredMessage)
|
||||
{
|
||||
if (chatId == this->chatId && sponsoredMessages.size() > 0) {
|
||||
LOG("Handling sponsored messages:" <<sponsoredMessages.size());
|
||||
LOG("Handling sponsored message" << chatId);
|
||||
QList<MessageData*> messagesToBeAdded;
|
||||
for (QVariant sponsoredMessage: sponsoredMessages) {
|
||||
QVariantMap sponsoredMessageData = sponsoredMessage.toMap();
|
||||
const qlonglong messageId = sponsoredMessageData.value(ID).toLongLong();
|
||||
const qlonglong messageId = sponsoredMessage.value(MESSAGE_ID).toLongLong();
|
||||
if (messageId && !messageIndexMap.contains(messageId)) {
|
||||
LOG("New sponsored message will be added:" << messageId);
|
||||
messagesToBeAdded.append(new MessageData(sponsoredMessageData, messageId));
|
||||
}
|
||||
messagesToBeAdded.append(new MessageData(sponsoredMessage, messageId));
|
||||
}
|
||||
appendMessages(messagesToBeAdded);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatModel::handleNewMessageReceived(qlonglong chatId, const QVariantMap &message)
|
||||
{
|
||||
|
|
|
@ -63,7 +63,7 @@ signals:
|
|||
|
||||
private slots:
|
||||
void handleMessagesReceived(const QVariantList &messages, int totalCount);
|
||||
void handleSponsoredMessagesReceived(qlonglong chatId, const QVariantList &sponsoredMessages);
|
||||
void handleSponsoredMessageReceived(qlonglong chatId, const QVariantMap &sponsoredMessage);
|
||||
void handleNewMessageReceived(qlonglong chatId, const QVariantMap &message);
|
||||
void handleMessageReceived(qlonglong chatId, qlonglong messageId, const QVariantMap &message);
|
||||
void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, int unreadCount);
|
||||
|
|
|
@ -117,7 +117,7 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren
|
|||
handlers.insert("updateSupergroup", &TDLibReceiver::processUpdateSuperGroup);
|
||||
handlers.insert("updateChatOnlineMemberCount", &TDLibReceiver::processChatOnlineMemberCountUpdated);
|
||||
handlers.insert("messages", &TDLibReceiver::processMessages);
|
||||
handlers.insert("sponsoredMessages", &TDLibReceiver::processSponsoredMessages);
|
||||
handlers.insert("sponsoredMessage", &TDLibReceiver::processSponsoredMessage);
|
||||
handlers.insert("updateNewMessage", &TDLibReceiver::processUpdateNewMessage);
|
||||
handlers.insert("message", &TDLibReceiver::processMessage);
|
||||
handlers.insert("messageLinkInfo", &TDLibReceiver::processMessageLinkInfo);
|
||||
|
@ -375,11 +375,11 @@ void TDLibReceiver::processMessages(const QVariantMap &receivedInformation)
|
|||
emit messagesReceived(cleanupList(receivedInformation.value(MESSAGES).toList()), total_count);
|
||||
}
|
||||
|
||||
void TDLibReceiver::processSponsoredMessages(const QVariantMap &receivedInformation)
|
||||
void TDLibReceiver::processSponsoredMessage(const QVariantMap &receivedInformation)
|
||||
{
|
||||
const qlonglong chatId = receivedInformation.value(_EXTRA).toLongLong(); // See TDLibWrapper::getChatSponsoredMessages
|
||||
LOG("Received sponsored messages for chat" << chatId);
|
||||
emit sponsoredMessagesReceived(chatId, receivedInformation.value(MESSAGES).toList());
|
||||
const qlonglong chatId = receivedInformation.value(_EXTRA).toLongLong(); // See TDLibWrapper::getChatSponsoredMessage
|
||||
LOG("Received sponsored message for chat" << chatId);
|
||||
emit sponsoredMessageReceived(chatId, receivedInformation);
|
||||
}
|
||||
|
||||
void TDLibReceiver::processUpdateNewMessage(const QVariantMap &receivedInformation)
|
||||
|
|
|
@ -57,7 +57,7 @@ signals:
|
|||
void chatOnlineMemberCountUpdated(const QString &chatId, int onlineMemberCount);
|
||||
void messagesReceived(const QVariantList &messages, int totalCount);
|
||||
void messageLinkInfoReceived(const QString &url, const QVariantMap &messageLinkInfo, const QString &extra);
|
||||
void sponsoredMessagesReceived(qlonglong chatId, const QVariantList &messages);
|
||||
void sponsoredMessageReceived(qlonglong chatId, const QVariantMap &message);
|
||||
void newMessageReceived(qlonglong chatId, const QVariantMap &message);
|
||||
void messageInformation(qlonglong chatId, qlonglong messageId, const QVariantMap &message);
|
||||
void messageSendSucceeded(qlonglong messageId, qlonglong oldMessageId, const QVariantMap &message);
|
||||
|
@ -135,7 +135,7 @@ private:
|
|||
void processUpdateSuperGroup(const QVariantMap &receivedInformation);
|
||||
void processChatOnlineMemberCountUpdated(const QVariantMap &receivedInformation);
|
||||
void processMessages(const QVariantMap &receivedInformation);
|
||||
void processSponsoredMessages(const QVariantMap &receivedInformation);
|
||||
void processSponsoredMessage(const QVariantMap &receivedInformation);
|
||||
void processUpdateNewMessage(const QVariantMap &receivedInformation);
|
||||
void processMessage(const QVariantMap &receivedInformation);
|
||||
void processMessageLinkInfo(const QVariantMap &receivedInformation);
|
||||
|
|
|
@ -118,7 +118,7 @@ void TDLibWrapper::initializeTDLibReciever() {
|
|||
connect(this->tdLibReceiver, SIGNAL(superGroupUpdated(qlonglong, QVariantMap)), this, SLOT(handleSuperGroupUpdated(qlonglong, QVariantMap)));
|
||||
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(sponsoredMessagesReceived(qlonglong, QVariantList)), this, SLOT(handleSponsoredMess(qlonglong, QVariantList)));
|
||||
connect(this->tdLibReceiver, SIGNAL(sponsoredMessageReceived(qlonglong, QVariantMap)), this, SLOT(handleSponsoredMessage(qlonglong, QVariantMap)));
|
||||
connect(this->tdLibReceiver, SIGNAL(messageLinkInfoReceived(QString, QVariantMap, QString)), this, SIGNAL(messageLinkInfoReceived(QString, QVariantMap, QString)));
|
||||
connect(this->tdLibReceiver, SIGNAL(newMessageReceived(qlonglong, QVariantMap)), this, SIGNAL(newMessageReceived(qlonglong, QVariantMap)));
|
||||
connect(this->tdLibReceiver, SIGNAL(messageInformation(qlonglong, qlonglong, QVariantMap)), this, SLOT(handleMessageInformation(qlonglong, qlonglong, QVariantMap)));
|
||||
|
@ -692,13 +692,13 @@ void TDLibWrapper::getChatPinnedMessage(qlonglong chatId)
|
|||
this->sendRequest(requestObject);
|
||||
}
|
||||
|
||||
void TDLibWrapper::getChatSponsoredMessages(qlonglong chatId)
|
||||
void TDLibWrapper::getChatSponsoredMessage(qlonglong chatId)
|
||||
{
|
||||
LOG("Retrieving sponsored messages" << chatId);
|
||||
LOG("Retrieving sponsored message" << chatId);
|
||||
QVariantMap requestObject;
|
||||
requestObject.insert(_TYPE, "getChatSponsoredMessages");
|
||||
requestObject.insert(_TYPE, "getChatSponsoredMessage");
|
||||
requestObject.insert(CHAT_ID, chatId);
|
||||
requestObject.insert(_EXTRA, chatId); // see TDLibReceiver::processSponsoredMessages
|
||||
requestObject.insert(_EXTRA, chatId); // see TDLibReceiver::processSponsoredMessage
|
||||
this->sendRequest(requestObject);
|
||||
}
|
||||
|
||||
|
@ -1882,21 +1882,18 @@ void TDLibWrapper::handleUpdatedUserPrivacySettingRules(const QVariantMap &updat
|
|||
}
|
||||
}
|
||||
|
||||
void TDLibWrapper::handleSponsoredMess(qlonglong chatId, const QVariantList &messages)
|
||||
void TDLibWrapper::handleSponsoredMessage(qlonglong chatId, const QVariantMap &message)
|
||||
{
|
||||
switch (appSettings->getSponsoredMess()) {
|
||||
case AppSettings::SponsoredMessHandle:
|
||||
emit sponsoredMessagesReceived(chatId, messages);
|
||||
emit sponsoredMessageReceived(chatId, message);
|
||||
break;
|
||||
case AppSettings::SponsoredMessAutoView:
|
||||
LOG("Auto-viewing sponsored mess");
|
||||
for (int i = 0; i < messages.count(); i++) {
|
||||
const QVariantMap mess(messages.at(i).toMap());
|
||||
viewSponsoredMessage(chatId, mess.value(ID).toULongLong());
|
||||
}
|
||||
LOG("Auto-viewing sponsored message");
|
||||
viewSponsoredMessage(chatId, message.value(ID).toULongLong());
|
||||
break;
|
||||
case AppSettings::SponsoredMessIgnore:
|
||||
LOG("Ignoring sponsored mess");
|
||||
LOG("Ignoring sponsored message");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ public:
|
|||
Q_INVOKABLE void getMessageLinkInfo(const QString &url, const QString &extra = "");
|
||||
Q_INVOKABLE void getCallbackQueryAnswer(const QString &chatId, const QString &messageId, const QVariantMap &payload);
|
||||
Q_INVOKABLE void getChatPinnedMessage(qlonglong chatId);
|
||||
Q_INVOKABLE void getChatSponsoredMessages(qlonglong chatId);
|
||||
Q_INVOKABLE void getChatSponsoredMessage(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);
|
||||
|
@ -264,7 +264,7 @@ signals:
|
|||
void superGroupUpdated(qlonglong groupId);
|
||||
void chatOnlineMemberCountUpdated(const QString &chatId, int onlineMemberCount);
|
||||
void messagesReceived(const QVariantList &messages, int totalCount);
|
||||
void sponsoredMessagesReceived(qlonglong chatId, const QVariantList &messages);
|
||||
void sponsoredMessageReceived(qlonglong chatId, const QVariantMap &message);
|
||||
void messageLinkInfoReceived(const QString &url, const QVariantMap &messageLinkInfo, const QString &extra);
|
||||
void newMessageReceived(qlonglong chatId, const QVariantMap &message);
|
||||
void copyToDownloadsSuccessful(const QString &fileName, const QString &filePath);
|
||||
|
@ -338,7 +338,7 @@ public slots:
|
|||
void handleMessageIsPinnedUpdated(qlonglong chatId, qlonglong messageId, bool isPinned);
|
||||
void handleUserPrivacySettingRules(const QVariantMap &rules);
|
||||
void handleUpdatedUserPrivacySettingRules(const QVariantMap &updatedRules);
|
||||
void handleSponsoredMess(qlonglong chatId, const QVariantList &messages);
|
||||
void handleSponsoredMessage(qlonglong chatId, const QVariantMap &message);
|
||||
|
||||
private:
|
||||
void setOption(const QString &name, const QString &type, const QVariant &value);
|
||||
|
|
Loading…
Reference in a new issue