From 4a32b00068cda9ceaa4cf8546132be08e4810e1a Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 19 Mar 2018 20:32:33 +0400 Subject: [PATCH] Setting for cloud stickers suggestions. --- Telegram/Resources/langs/lang.strings | 1 + .../SourceFiles/chat_helpers/stickers.cpp | 22 ++++++++++--------- Telegram/SourceFiles/facades.cpp | 2 ++ Telegram/SourceFiles/facades.h | 1 + .../settings_chat_settings_widget.cpp | 10 +++++++-- .../settings/settings_chat_settings_widget.h | 5 ++++- Telegram/SourceFiles/storage/localstorage.cpp | 12 +++++++++- 7 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index e12f0e95b..3759cab2c 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -296,6 +296,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_section_chat_settings" = "Chat Settings"; "lng_settings_replace_emojis" = "Replace emoji"; +"lng_settings_suggest_by_emoji" = "Suggest popular stickers by emoji"; "lng_settings_view_emojis" = "View list"; "lng_settings_send_enter" = "Send by Enter"; "lng_settings_send_ctrlenter" = "Send by Ctrl+Enter"; diff --git a/Telegram/SourceFiles/chat_helpers/stickers.cpp b/Telegram/SourceFiles/chat_helpers/stickers.cpp index 6d54e4139..d9f4e1461 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers.cpp @@ -783,9 +783,9 @@ std::vector> GetListByEmoji( addList( Auth().data().stickerSetsOrder(), MTPDstickerSet::Flag::f_archived); - addList( - Auth().data().featuredStickerSetsOrder(), - MTPDstickerSet::Flag::f_installed_date); + //addList( + // Auth().data().featuredStickerSetsOrder(), + // MTPDstickerSet::Flag::f_installed_date); if (!setsToRequest.empty()) { for (const auto [setId, accessHash] : setsToRequest) { @@ -794,13 +794,15 @@ std::vector> GetListByEmoji( Auth().api().requestStickerSets(); } - const auto others = Auth().api().stickersByEmoji(original); - if (!others) { - return {}; - } - result.reserve(result.size() + others->size()); - for (const auto document : *others) { - add(document, CreateOtherSortKey(document)); + if (Global::SuggestStickersByEmoji()) { + const auto others = Auth().api().stickersByEmoji(original); + if (!others) { + return {}; + } + result.reserve(result.size() + others->size()); + for (const auto document : *others) { + add(document, CreateOtherSortKey(document)); + } } ranges::action::sort( diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 4c1c37f9a..955090cb5 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -552,6 +552,7 @@ struct Data { QByteArray DownloadPathBookmark; base::Observable DownloadPathChanged; + bool SuggestStickersByEmoji = true; bool SoundNotify = true; bool DesktopNotify = true; bool RestoreSoundNotifyFromTray = false; @@ -674,6 +675,7 @@ DefineVar(Global, QString, DownloadPath); DefineVar(Global, QByteArray, DownloadPathBookmark); DefineRefVar(Global, base::Observable, DownloadPathChanged); +DefineVar(Global, bool, SuggestStickersByEmoji); DefineVar(Global, bool, SoundNotify); DefineVar(Global, bool, DesktopNotify); DefineVar(Global, bool, RestoreSoundNotifyFromTray); diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 3ec3f7bb0..9f6b1de13 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -360,6 +360,7 @@ DeclareVar(QString, DownloadPath); DeclareVar(QByteArray, DownloadPathBookmark); DeclareRefVar(base::Observable, DownloadPathChanged); +DeclareVar(bool, SuggestStickersByEmoji); DeclareVar(bool, SoundNotify); DeclareVar(bool, DesktopNotify); DeclareVar(bool, RestoreSoundNotifyFromTray); diff --git a/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp b/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp index faa027d9f..8ee2f000b 100644 --- a/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp @@ -140,7 +140,8 @@ void ChatSettingsWidget::createControls() { style::margins marginSub(0, 0, 0, st::settingsSubSkip); style::margins slidedPadding(0, marginSub.bottom() / 2, 0, marginSub.bottom() - (marginSub.bottom() / 2)); - createChildRow(_replaceEmoji, marginSkip, lang(lng_settings_replace_emojis), [this](bool) { onReplaceEmoji(); }, cReplaceEmojis()); + createChildRow(_replaceEmoji, marginSmall, lang(lng_settings_replace_emojis), [this](bool) { toggleReplaceEmoji(); }, cReplaceEmojis()); + createChildRow(_suggestByEmoji, marginSkip, lang(lng_settings_suggest_by_emoji), [this](bool) { toggleSuggestStickersByEmoji(); }, Global::SuggestStickersByEmoji()); #ifndef OS_WIN_STORE auto pathMargin = marginSub; @@ -168,11 +169,16 @@ void ChatSettingsWidget::createControls() { createChildRow(_manageStickerSets, marginSmall, lang(lng_stickers_you_have), SLOT(onManageStickerSets())); } -void ChatSettingsWidget::onReplaceEmoji() { +void ChatSettingsWidget::toggleReplaceEmoji() { cSetReplaceEmojis(_replaceEmoji->checked()); Local::writeUserSettings(); } +void ChatSettingsWidget::toggleSuggestStickersByEmoji() { + Global::SetSuggestStickersByEmoji(_suggestByEmoji->checked()); + Local::writeUserSettings(); +} + void ChatSettingsWidget::onDontAskDownloadPath() { Global::SetAskDownloadPath(!_dontAskDownloadPath->checked()); Local::writeUserSettings(); diff --git a/Telegram/SourceFiles/settings/settings_chat_settings_widget.h b/Telegram/SourceFiles/settings/settings_chat_settings_widget.h index 1f2d2b09c..fa11ef11a 100644 --- a/Telegram/SourceFiles/settings/settings_chat_settings_widget.h +++ b/Telegram/SourceFiles/settings/settings_chat_settings_widget.h @@ -81,7 +81,6 @@ public: ChatSettingsWidget(QWidget *parent, UserData *self); private slots: - void onReplaceEmoji(); void onDontAskDownloadPath(); void onAutomaticMediaDownloadSettings(); void onManageStickerSets(); @@ -94,7 +93,11 @@ private: void sendByChanged(SendByType value); void createControls(); + void toggleReplaceEmoji(); + void toggleSuggestStickersByEmoji(); + Ui::Checkbox *_replaceEmoji = nullptr; + Ui::Checkbox *_suggestByEmoji = nullptr; Ui::Checkbox *_dontAskDownloadPath = nullptr; #ifndef OS_WIN_STORE diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 24ca577a9..f7724c322 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -571,6 +571,7 @@ enum { dbiLangPackKey = 0x4e, dbiConnectionType = 0x4f, dbiStickersFavedLimit = 0x50, + dbiSuggestStickersByEmoji = 0x51, dbiEncryptedWithSalt = 333, dbiEncrypted = 444, @@ -998,6 +999,14 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting Global::SetSoundNotify(v == 1); } break; + case dbiSuggestStickersByEmoji: { + qint32 v; + stream >> v; + if (!_checkStreamStatus(stream)) return false; + + Global::SetSuggestStickersByEmoji(v == 1); + } break; + case dbiAutoDownload: { qint32 photo, audio, gif; stream >> photo >> audio >> gif; @@ -1766,7 +1775,7 @@ void _writeUserSettings() { ? userDataInstance->serialize() : QByteArray(); - uint32 size = 21 * (sizeof(quint32) + sizeof(qint32)); + uint32 size = 22 * (sizeof(quint32) + sizeof(qint32)); size += sizeof(quint32) + Serialize::stringSize(Global::AskDownloadPath() ? QString() : Global::DownloadPath()) + Serialize::bytearraySize(Global::AskDownloadPath() ? QByteArray() : Global::DownloadPathBookmark()); size += sizeof(quint32) + sizeof(qint32); @@ -1809,6 +1818,7 @@ void _writeUserSettings() { data.stream << quint32(dbiModerateMode) << qint32(Global::ModerateModeEnabled() ? 1 : 0); data.stream << quint32(dbiAutoPlay) << qint32(cAutoPlayGif() ? 1 : 0); data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer()); + data.stream << quint32(dbiSuggestStickersByEmoji) << qint32(Global::SuggestStickersByEmoji() ? 1 : 0); if (!userData.isEmpty()) { data.stream << quint32(dbiAuthSessionSettings) << userData; }