diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Telegram/src/groupchat.cpp | 15 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 6 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 42 | ||||
-rw-r--r-- | protocols/Telegram/src/utils.cpp | 7 |
4 files changed, 53 insertions, 17 deletions
diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp index 1d45d5630c..fddb95809b 100644 --- a/protocols/Telegram/src/groupchat.cpp +++ b/protocols/Telegram/src/groupchat.cpp @@ -171,17 +171,10 @@ int CTelegramProto::GcMuteHook(WPARAM hContact, LPARAM mode) auto settings = TD::make_object<TD::chatNotificationSettings>(); memcpy(settings.get(), &pUser->notificationSettings, sizeof(pUser->notificationSettings)); - switch (mode) { - case CHATMODE_MUTE: - settings->use_default_mute_for_ = false; - settings->mute_for_ = 45000000; - break; - - default: - settings->use_default_mute_for_ = true; - settings->mute_for_ = 0; - break; - } + TD::int32 defaultMute = GetDefaultMute(pUser); + TD::int32 newMute = (mode == CHATMODE_MUTE) ? 421689178 : 0; + settings->use_default_mute_for_ = (newMute == defaultMute); + settings->mute_for_ = newMute; SendQuery(new TD::setChatNotificationSettings(pUser->chatId, std::move(settings))); } } diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index f478dc7c82..b13a6cec52 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -101,7 +101,7 @@ struct TG_USER : public MZeroedObject int64_t id, chatId = -1; MCONTACT hContact; int folderId = -1, nHistoryChunks; - bool isGroupChat, isBot, isForum, bLoadMembers, bStartChat, bInited; + bool isGroupChat, isChannel, isBot, isForum, bLoadMembers, bStartChat, bInited; CMStringA szAvatarHash; CMStringW wszNick, wszFirstName, wszLastName; time_t m_timer1 = 0, m_timer2 = 0; @@ -208,6 +208,7 @@ class CTelegramProto : public PROTO<CTelegramProto> bool m_bAuthorized, m_bTerminated, m_bUnregister = false, m_bSmileyAdd = false; int32_t m_iClientId, m_iQueryId; + TD::int32 m_iDefaultMutePrivate, m_iDefaultMuteGroup, m_iDefaultMuteChannel; CMStringA m_defaultEmoji; OBJLIST<TG_OWN_MESSAGE> m_arOwnMsg; @@ -275,6 +276,7 @@ class CTelegramProto : public PROTO<CTelegramProto> void ProcessMessageContent(TD::updateMessageContent *pObj); void ProcessMessageReactions(TD::updateMessageInteractionInfo *pObj); void ProcessOption(TD::updateOption *pObj); + void ProcessScopeNotification(TD::updateScopeNotificationSettings *pObj); void ProcessStatus(TD::updateUserStatus *pObj); void ProcessSuperGroup(TD::updateSupergroup *pObj); void ProcessUser(TD::updateUser *pObj); @@ -354,6 +356,8 @@ class CTelegramProto : public PROTO<CTelegramProto> int64_t GetId(MCONTACT, const char *pszSetting = DBKEY_ID); void SetId(MCONTACT, int64_t id, const char *pszSetting = DBKEY_ID); + int GetDefaultMute(const TG_USER *pUser); + MCONTACT GetRealContact(const TG_USER *pUser); void RemoveFromClist(TG_USER *pUser); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index e4cd70693a..81ec9f3edd 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -314,6 +314,10 @@ void CTelegramProto::ProcessResponse(td::ClientManager::Response response) ProcessOption((TD::updateOption *)response.object.get());
break;
+ case TD::updateScopeNotificationSettings::ID:
+ ProcessScopeNotification((TD::updateScopeNotificationSettings *)response.object.get());
+ break;
+
case TD::updateSupergroup::ID:
ProcessSuperGroup((TD::updateSupergroup *)response.object.get());
break;
@@ -527,6 +531,7 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) int64_t userId;
auto *pChat = pObj->chat_.get();
std::string szTitle;
+ bool isChannel = false;
switch (pChat->type_->get_id()) {
case TD::chatTypePrivate::ID:
@@ -540,8 +545,12 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) break;
case TD::chatTypeSupergroup::ID:
- userId = ((TD::chatTypeSupergroup *)pChat->type_.get())->supergroup_id_;
- szTitle = pChat->title_;
+ {
+ auto *pGroup = (TD::chatTypeSupergroup *)pChat->type_.get();
+ userId = pGroup->supergroup_id_;
+ szTitle = pChat->title_;
+ isChannel = pGroup->is_channel_;
+ }
break;
default:
@@ -556,6 +565,7 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) }
pUser->chatId = pChat->id_;
+ pUser->isChannel = isChannel;
MCONTACT hContact = (pUser->id == m_iOwnId) ? 0 : pUser->hContact;
@@ -643,10 +653,13 @@ void CTelegramProto::ProcessChatNotification(TD::updateChatNotificationSettings return;
auto &pSettings = pObj->notification_settings_;
- if (!pSettings->use_default_mute_for_ && pSettings->mute_for_ != 0)
- Chat_Mute(pUser->hContact, CHATMODE_MUTE);
+
+ TD::int32 muteFor;
+ if (!pSettings->use_default_mute_for_)
+ muteFor = pSettings->mute_for_;
else
- Chat_Mute(pUser->hContact, CHATMODE_NORMAL);
+ muteFor = GetDefaultMute(pUser);
+ Chat_Mute(pUser->hContact, muteFor ? CHATMODE_MUTE : CHATMODE_NORMAL);
memcpy(&pUser->notificationSettings, pSettings.get(), sizeof(pUser->notificationSettings));
}
@@ -1061,6 +1074,25 @@ void CTelegramProto::ProcessOption(TD::updateOption *pObj) /////////////////////////////////////////////////////////////////////////////////////////
+void CTelegramProto::ProcessScopeNotification(TD::updateScopeNotificationSettings *pObj)
+{
+ switch (pObj->scope_->get_id()) {
+ case TD::notificationSettingsScopePrivateChats::ID:
+ m_iDefaultMutePrivate = pObj->notification_settings_->mute_for_;
+ break;
+
+ case TD::notificationSettingsScopeGroupChats::ID:
+ m_iDefaultMuteGroup = pObj->notification_settings_->mute_for_;
+ break;
+
+ case TD::notificationSettingsScopeChannelChats::ID:
+ m_iDefaultMuteChannel = pObj->notification_settings_->mute_for_;
+ break;
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
void CTelegramProto::ProcessStatus(TD::updateUserStatus *pObj)
{
if (auto *pUser = FindUser(pObj->user_id_)) {
diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index ba7515cce6..d69f1231e0 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -197,6 +197,13 @@ void CTelegramProto::RemoveFromClist(TG_USER *pUser) }
}
+int CTelegramProto::GetDefaultMute(const TG_USER *pUser)
+{
+ if (pUser->isGroupChat)
+ return (pUser->isChannel) ? m_iDefaultMuteChannel : m_iDefaultMuteGroup;
+ return m_iDefaultMutePrivate;
+}
+
MCONTACT CTelegramProto::GetRealContact(const TG_USER *pUser)
{
return (pUser->hContact != 0) ? pUser->hContact : m_iSavedMessages;
|