Better support sponsored message types
This commit is contained in:
parent
b5b0ec5ed1
commit
0f4e0eaf58
5 changed files with 45 additions and 3 deletions
|
@ -28,6 +28,16 @@ Column {
|
|||
|
||||
property var sponsoredMessageData;
|
||||
|
||||
Connections {
|
||||
target: tdLibWrapper
|
||||
onMessageLinkInfoReceived: {
|
||||
if (sponsoredMessageData.link.url === url) {
|
||||
messageOverlayLoader.overlayMessage = messageLinkInfo.message;
|
||||
messageOverlayLoader.active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (sponsoredMessageData) {
|
||||
if (typeof sponsoredMessageData.link === "undefined") {
|
||||
|
@ -35,10 +45,10 @@ Column {
|
|||
sponsoredMessageButton.advertisesChannel = true;
|
||||
} else if (sponsoredMessageData.link['@type'] === "internalLinkTypeMessage") {
|
||||
sponsoredMessageButton.text = qsTr("Go to Message");
|
||||
sponsoredMessageButton.enabled = false;
|
||||
sponsoredMessageButton.advertisesMessage = true;
|
||||
} else {
|
||||
sponsoredMessageButton.text = qsTr("Start Bot");
|
||||
sponsoredMessageButton.enabled = false;
|
||||
sponsoredMessageButton.advertisesBot = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,12 +56,21 @@ Column {
|
|||
Button {
|
||||
id: sponsoredMessageButton
|
||||
property bool advertisesChannel: false;
|
||||
property bool advertisesMessage: false;
|
||||
property bool advertisesBot: false;
|
||||
anchors {
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
onClicked: {
|
||||
if (advertisesChannel) {
|
||||
tdLibWrapper.createSupergroupChat(sponsoredMessageData.sponsor_chat_id, "openDirectly");
|
||||
tdLibWrapper.createSupergroupChat(tdLibWrapper.getChat(sponsoredMessageData.sponsor_chat_id).type.supergroup_id, "openDirectly");
|
||||
}
|
||||
if (advertisesMessage) {
|
||||
tdLibWrapper.getMessageLinkInfo(sponsoredMessageData.link.url);
|
||||
}
|
||||
if (advertisesBot) {
|
||||
tdLibWrapper.createPrivateChat(tdLibWrapper.getUserInformationByName(sponsoredMessageData.link.bot_username).id, "openAndSendStartToBot:" + sponsoredMessageData.link.start_parameter);
|
||||
//tdLibWrapper.sendBotStartMessage(tdLibWrapper.getUserInformationByName(sponsoredMessageData.link.bot_username).id, sponsoredMessageData.sponsor_chat_id, sponsoredMessageData.link.start_parameter, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren
|
|||
handlers.insert("sponsoredMessages", &TDLibReceiver::processSponsoredMessages);
|
||||
handlers.insert("updateNewMessage", &TDLibReceiver::processUpdateNewMessage);
|
||||
handlers.insert("message", &TDLibReceiver::processMessage);
|
||||
handlers.insert("messageLinkInfo", &TDLibReceiver::processMessageLinkInfo);
|
||||
handlers.insert("updateMessageSendSucceeded", &TDLibReceiver::processMessageSendSucceeded);
|
||||
handlers.insert("updateActiveNotifications", &TDLibReceiver::processUpdateActiveNotifications);
|
||||
handlers.insert("updateNotificationGroup", &TDLibReceiver::processUpdateNotificationGroup);
|
||||
|
@ -380,6 +381,13 @@ void TDLibReceiver::processMessage(const QVariantMap &receivedInformation)
|
|||
emit messageInformation(chatId, messageId, receivedInformation);
|
||||
}
|
||||
|
||||
void TDLibReceiver::processMessageLinkInfo(const QVariantMap &receivedInformation)
|
||||
{
|
||||
const QString url = receivedInformation.value(EXTRA).toString();
|
||||
LOG("Received message link info " << url);
|
||||
emit messageLinkInfoReceived(url, receivedInformation);
|
||||
}
|
||||
|
||||
void TDLibReceiver::processMessageSendSucceeded(const QVariantMap &receivedInformation)
|
||||
{
|
||||
const qlonglong oldMessageId = receivedInformation.value(OLD_MESSAGE_ID).toLongLong();
|
||||
|
|
|
@ -56,6 +56,7 @@ signals:
|
|||
void superGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation);
|
||||
void chatOnlineMemberCountUpdated(const QString &chatId, int onlineMemberCount);
|
||||
void messagesReceived(const QVariantList &messages, int totalCount);
|
||||
void messageLinkInfoReceived(const QString &url, const QVariantMap &messageLinkInfo);
|
||||
void sponsoredMessagesReceived(qlonglong chatId, const QVariantList &messages);
|
||||
void newMessageReceived(qlonglong chatId, const QVariantMap &message);
|
||||
void messageInformation(qlonglong chatId, qlonglong messageId, const QVariantMap &message);
|
||||
|
@ -134,6 +135,7 @@ private:
|
|||
void processSponsoredMessages(const QVariantMap &receivedInformation);
|
||||
void processUpdateNewMessage(const QVariantMap &receivedInformation);
|
||||
void processMessage(const QVariantMap &receivedInformation);
|
||||
void processMessageLinkInfo(const QVariantMap &receivedInformation);
|
||||
void processMessageSendSucceeded(const QVariantMap &receivedInformation);
|
||||
void processUpdateActiveNotifications(const QVariantMap &receivedInformation);
|
||||
void processUpdateNotificationGroup(const QVariantMap &receivedInformation);
|
||||
|
|
|
@ -119,6 +119,7 @@ void TDLibWrapper::initializeTDLibReciever() {
|
|||
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(messageLinkInfoReceived(QString, QVariantMap)), this, SIGNAL(messageLinkInfoReceived(QString, QVariantMap)));
|
||||
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)));
|
||||
connect(this->tdLibReceiver, SIGNAL(messageSendSucceeded(qlonglong, qlonglong, QVariantMap)), this, SIGNAL(messageSendSucceeded(qlonglong, qlonglong, QVariantMap)));
|
||||
|
@ -646,6 +647,16 @@ void TDLibWrapper::getMessage(qlonglong chatId, qlonglong messageId)
|
|||
this->sendRequest(requestObject);
|
||||
}
|
||||
|
||||
void TDLibWrapper::getMessageLinkInfo(const QString &url)
|
||||
{
|
||||
LOG("Retrieving message link info" << url);
|
||||
QVariantMap requestObject;
|
||||
requestObject.insert(_TYPE, "getMessageLinkInfo");
|
||||
requestObject.insert("url", url);
|
||||
requestObject.insert(_EXTRA, url);
|
||||
this->sendRequest(requestObject);
|
||||
}
|
||||
|
||||
void TDLibWrapper::getCallbackQueryAnswer(const QString &chatId, const QString &messageId, const QVariantMap &payload)
|
||||
{
|
||||
LOG("Getting Callback Query Answer" << chatId << messageId);
|
||||
|
|
|
@ -171,6 +171,7 @@ public:
|
|||
Q_INVOKABLE void sendPollMessage(const QString &chatId, const QString &question, const QVariantList &options, bool anonymous, int correctOption, bool multiple, const QString &explanation, const QString &replyToMessageId = "0");
|
||||
Q_INVOKABLE void forwardMessages(const QString &chatId, const QString &fromChatId, const QVariantList &messageIds, bool sendCopy, bool removeCaption);
|
||||
Q_INVOKABLE void getMessage(qlonglong chatId, qlonglong messageId);
|
||||
Q_INVOKABLE void getMessageLinkInfo(const QString &url);
|
||||
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);
|
||||
|
@ -263,6 +264,7 @@ signals:
|
|||
void chatOnlineMemberCountUpdated(const QString &chatId, int onlineMemberCount);
|
||||
void messagesReceived(const QVariantList &messages, int totalCount);
|
||||
void sponsoredMessagesReceived(qlonglong chatId, const QVariantList &messages);
|
||||
void messageLinkInfoReceived(const QString &url, const QVariantMap &messageLinkInfo);
|
||||
void newMessageReceived(qlonglong chatId, const QVariantMap &message);
|
||||
void copyToDownloadsSuccessful(const QString &fileName, const QString &filePath);
|
||||
void copyToDownloadsError(const QString &fileName, const QString &filePath);
|
||||
|
|
Loading…
Reference in a new issue