Contigurable mess

There's no UI for that, you have to configure your mess manually))
Also, made sure that chats don't handle another char's mess.
This commit is contained in:
Slava Monich 2021-12-06 04:29:40 +02:00
parent 5a2596e9de
commit 84cfcb5150
8 changed files with 60 additions and 12 deletions

View file

@ -36,6 +36,7 @@ namespace {
const QString KEY_ONLINE_ONLY_MODE("onlineOnlyMode");
const QString KEY_DELAY_MESSAGE_READ("delayMessageRead");
const QString KEY_FOCUS_TEXTAREA_ON_CHAT_OPEN("focusTextAreaOnChatOpen");
const QString KEY_SPONSORED_MESS("sponsoredMess");
}
AppSettings::AppSettings(QObject *parent) : QObject(parent), settings("harbour-fernschreiber", "settings")
@ -252,3 +253,18 @@ void AppSettings::setFocusTextAreaOnChatOpen(bool focusTextAreaOnChatOpen)
emit focusTextAreaOnChatOpenChanged();
}
}
AppSettings::SponsoredMess AppSettings::getSponsoredMess() const
{
return (SponsoredMess) settings.value(KEY_SPONSORED_MESS, (int)
AppSettings::SponsoredMessHandle).toInt();
}
void AppSettings::setSponsoredMess(SponsoredMess sponsoredMess)
{
if (getSponsoredMess() != sponsoredMess) {
LOG(KEY_SPONSORED_MESS << sponsoredMess);
settings.setValue(KEY_SPONSORED_MESS, sponsoredMess);
emit sponsoredMessChanged();
}
}

View file

@ -38,9 +38,16 @@ class AppSettings : public QObject {
Q_PROPERTY(bool onlineOnlyMode READ onlineOnlyMode WRITE setOnlineOnlyMode NOTIFY onlineOnlyModeChanged)
Q_PROPERTY(bool delayMessageRead READ delayMessageRead WRITE setDelayMessageRead NOTIFY delayMessageReadChanged)
Q_PROPERTY(bool focusTextAreaOnChatOpen READ getFocusTextAreaOnChatOpen WRITE setFocusTextAreaOnChatOpen NOTIFY focusTextAreaOnChatOpenChanged)
Q_PROPERTY(SponsoredMess sponsoredMess READ getSponsoredMess WRITE setSponsoredMess NOTIFY sponsoredMessChanged)
public:
enum SponsoredMess {
SponsoredMessHandle,
SponsoredMessAutoView,
SponsoredMessIgnore
};
Q_ENUM(SponsoredMess)
enum NotificationFeedback {
NotificationFeedbackNone,
NotificationFeedbackNew,
@ -96,6 +103,9 @@ public:
bool getFocusTextAreaOnChatOpen() const;
void setFocusTextAreaOnChatOpen(bool focusTextAreaOnChatOpen);
SponsoredMess getSponsoredMess() const;
void setSponsoredMess(SponsoredMess sponsoredMess);
signals:
void sendByEnterChanged();
void focusTextAreaAfterSendChanged();
@ -112,6 +122,7 @@ signals:
void onlineOnlyModeChanged();
void delayMessageReadChanged();
void focusTextAreaOnChatOpenChanged();
void sponsoredMessChanged();
private:
QSettings settings;

View file

@ -248,7 +248,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(QVariantList)), this, SLOT(handleSponsoredMessagesReceived(QVariantList)));
connect(this->tdLibWrapper, SIGNAL(sponsoredMessagesReceived(qlonglong, QVariantList)), this, SLOT(handleSponsoredMessagesReceived(qlonglong, QVariantList)));
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,10 +479,10 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages, int totalCo
}
void ChatModel::handleSponsoredMessagesReceived(const QVariantList &sponsoredMessages)
void ChatModel::handleSponsoredMessagesReceived(qlonglong chatId, const QVariantList &sponsoredMessages)
{
LOG("Handling sponsored messages:" <<sponsoredMessages.size());
if (sponsoredMessages.size() > 0) {
if (chatId == this->chatId && sponsoredMessages.size() > 0) {
LOG("Handling sponsored messages:" <<sponsoredMessages.size());
QList<MessageData*> messagesToBeAdded;
for (QVariant sponsoredMessage: sponsoredMessages) {
QVariantMap sponsoredMessageData = sponsoredMessage.toMap();

View file

@ -63,7 +63,7 @@ signals:
private slots:
void handleMessagesReceived(const QVariantList &messages, int totalCount);
void handleSponsoredMessagesReceived(const QVariantList &sponsoredMessages);
void handleSponsoredMessagesReceived(qlonglong chatId, const QVariantList &sponsoredMessages);
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);

View file

@ -359,8 +359,9 @@ void TDLibReceiver::processMessages(const QVariantMap &receivedInformation)
void TDLibReceiver::processSponsoredMessages(const QVariantMap &receivedInformation)
{
LOG("Received sponsored messages");
emit sponsoredMessagesReceived(receivedInformation.value("messages").toList());
const qlonglong chatId = receivedInformation.value(EXTRA).toLongLong(); // See TDLibWrapper::getChatSponsoredMessages
LOG("Received sponsored messages for chat" << chatId);
emit sponsoredMessagesReceived(chatId, receivedInformation.value(MESSAGES).toList());
}
void TDLibReceiver::processUpdateNewMessage(const QVariantMap &receivedInformation)

View file

@ -56,7 +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 sponsoredMessagesReceived(const QVariantList &sponsoredMessages);
void sponsoredMessagesReceived(qlonglong chatId, const QVariantList &messages);
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);

View file

@ -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(QVariantList)), this, SIGNAL(sponsoredMessagesReceived(QVariantList)));
connect(this->tdLibReceiver, SIGNAL(sponsoredMessagesReceived(qlonglong, QVariantList)), this, SLOT(handleSponsoredMess(qlonglong, QVariantList)));
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)));
@ -673,7 +673,7 @@ void TDLibWrapper::getChatSponsoredMessages(qlonglong chatId)
QVariantMap requestObject;
requestObject.insert(_TYPE, "getChatSponsoredMessages");
requestObject.insert(CHAT_ID, chatId);
requestObject.insert(_EXTRA, "getChatSponsoredMessages:" + QString::number(chatId));
requestObject.insert(_EXTRA, chatId); // see TDLibReceiver::processSponsoredMessages
this->sendRequest(requestObject);
}
@ -1857,6 +1857,25 @@ void TDLibWrapper::handleUpdatedUserPrivacySettingRules(const QVariantMap &updat
}
}
void TDLibWrapper::handleSponsoredMess(qlonglong chatId, const QVariantList &messages)
{
switch (appSettings->getSponsoredMess()) {
case AppSettings::SponsoredMessHandle:
emit sponsoredMessagesReceived(chatId, messages);
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());
}
break;
case AppSettings::SponsoredMessIgnore:
LOG("Ignoring sponsored mess");
break;
}
}
void TDLibWrapper::setInitialParameters()
{
LOG("Sending initial parameters to TD Lib");

View file

@ -262,7 +262,7 @@ signals:
void superGroupUpdated(qlonglong groupId);
void chatOnlineMemberCountUpdated(const QString &chatId, int onlineMemberCount);
void messagesReceived(const QVariantList &messages, int totalCount);
void sponsoredMessagesReceived(const QVariantList &sponsoredMessages);
void sponsoredMessagesReceived(qlonglong chatId, const QVariantList &messages);
void newMessageReceived(qlonglong chatId, const QVariantMap &message);
void copyToDownloadsSuccessful(const QString &fileName, const QString &filePath);
void copyToDownloadsError(const QString &fileName, const QString &filePath);
@ -335,6 +335,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);
private:
void setOption(const QString &name, const QString &type, const QVariant &value);