Setting for cloud stickers suggestions.

This commit is contained in:
John Preston 2018-03-19 20:32:33 +04:00
parent 3406f88fdc
commit 4a32b00068
7 changed files with 39 additions and 14 deletions

View File

@ -296,6 +296,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_section_chat_settings" = "Chat Settings"; "lng_settings_section_chat_settings" = "Chat Settings";
"lng_settings_replace_emojis" = "Replace emoji"; "lng_settings_replace_emojis" = "Replace emoji";
"lng_settings_suggest_by_emoji" = "Suggest popular stickers by emoji";
"lng_settings_view_emojis" = "View list"; "lng_settings_view_emojis" = "View list";
"lng_settings_send_enter" = "Send by Enter"; "lng_settings_send_enter" = "Send by Enter";
"lng_settings_send_ctrlenter" = "Send by Ctrl+Enter"; "lng_settings_send_ctrlenter" = "Send by Ctrl+Enter";

View File

@ -783,9 +783,9 @@ std::vector<not_null<DocumentData*>> GetListByEmoji(
addList( addList(
Auth().data().stickerSetsOrder(), Auth().data().stickerSetsOrder(),
MTPDstickerSet::Flag::f_archived); MTPDstickerSet::Flag::f_archived);
addList( //addList(
Auth().data().featuredStickerSetsOrder(), // Auth().data().featuredStickerSetsOrder(),
MTPDstickerSet::Flag::f_installed_date); // MTPDstickerSet::Flag::f_installed_date);
if (!setsToRequest.empty()) { if (!setsToRequest.empty()) {
for (const auto [setId, accessHash] : setsToRequest) { for (const auto [setId, accessHash] : setsToRequest) {
@ -794,13 +794,15 @@ std::vector<not_null<DocumentData*>> GetListByEmoji(
Auth().api().requestStickerSets(); Auth().api().requestStickerSets();
} }
const auto others = Auth().api().stickersByEmoji(original); if (Global::SuggestStickersByEmoji()) {
if (!others) { const auto others = Auth().api().stickersByEmoji(original);
return {}; if (!others) {
} return {};
result.reserve(result.size() + others->size()); }
for (const auto document : *others) { result.reserve(result.size() + others->size());
add(document, CreateOtherSortKey(document)); for (const auto document : *others) {
add(document, CreateOtherSortKey(document));
}
} }
ranges::action::sort( ranges::action::sort(

View File

@ -552,6 +552,7 @@ struct Data {
QByteArray DownloadPathBookmark; QByteArray DownloadPathBookmark;
base::Observable<void> DownloadPathChanged; base::Observable<void> DownloadPathChanged;
bool SuggestStickersByEmoji = true;
bool SoundNotify = true; bool SoundNotify = true;
bool DesktopNotify = true; bool DesktopNotify = true;
bool RestoreSoundNotifyFromTray = false; bool RestoreSoundNotifyFromTray = false;
@ -674,6 +675,7 @@ DefineVar(Global, QString, DownloadPath);
DefineVar(Global, QByteArray, DownloadPathBookmark); DefineVar(Global, QByteArray, DownloadPathBookmark);
DefineRefVar(Global, base::Observable<void>, DownloadPathChanged); DefineRefVar(Global, base::Observable<void>, DownloadPathChanged);
DefineVar(Global, bool, SuggestStickersByEmoji);
DefineVar(Global, bool, SoundNotify); DefineVar(Global, bool, SoundNotify);
DefineVar(Global, bool, DesktopNotify); DefineVar(Global, bool, DesktopNotify);
DefineVar(Global, bool, RestoreSoundNotifyFromTray); DefineVar(Global, bool, RestoreSoundNotifyFromTray);

View File

@ -360,6 +360,7 @@ DeclareVar(QString, DownloadPath);
DeclareVar(QByteArray, DownloadPathBookmark); DeclareVar(QByteArray, DownloadPathBookmark);
DeclareRefVar(base::Observable<void>, DownloadPathChanged); DeclareRefVar(base::Observable<void>, DownloadPathChanged);
DeclareVar(bool, SuggestStickersByEmoji);
DeclareVar(bool, SoundNotify); DeclareVar(bool, SoundNotify);
DeclareVar(bool, DesktopNotify); DeclareVar(bool, DesktopNotify);
DeclareVar(bool, RestoreSoundNotifyFromTray); DeclareVar(bool, RestoreSoundNotifyFromTray);

View File

@ -140,7 +140,8 @@ void ChatSettingsWidget::createControls() {
style::margins marginSub(0, 0, 0, st::settingsSubSkip); style::margins marginSub(0, 0, 0, st::settingsSubSkip);
style::margins slidedPadding(0, marginSub.bottom() / 2, 0, marginSub.bottom() - (marginSub.bottom() / 2)); 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 #ifndef OS_WIN_STORE
auto pathMargin = marginSub; auto pathMargin = marginSub;
@ -168,11 +169,16 @@ void ChatSettingsWidget::createControls() {
createChildRow(_manageStickerSets, marginSmall, lang(lng_stickers_you_have), SLOT(onManageStickerSets())); createChildRow(_manageStickerSets, marginSmall, lang(lng_stickers_you_have), SLOT(onManageStickerSets()));
} }
void ChatSettingsWidget::onReplaceEmoji() { void ChatSettingsWidget::toggleReplaceEmoji() {
cSetReplaceEmojis(_replaceEmoji->checked()); cSetReplaceEmojis(_replaceEmoji->checked());
Local::writeUserSettings(); Local::writeUserSettings();
} }
void ChatSettingsWidget::toggleSuggestStickersByEmoji() {
Global::SetSuggestStickersByEmoji(_suggestByEmoji->checked());
Local::writeUserSettings();
}
void ChatSettingsWidget::onDontAskDownloadPath() { void ChatSettingsWidget::onDontAskDownloadPath() {
Global::SetAskDownloadPath(!_dontAskDownloadPath->checked()); Global::SetAskDownloadPath(!_dontAskDownloadPath->checked());
Local::writeUserSettings(); Local::writeUserSettings();

View File

@ -81,7 +81,6 @@ public:
ChatSettingsWidget(QWidget *parent, UserData *self); ChatSettingsWidget(QWidget *parent, UserData *self);
private slots: private slots:
void onReplaceEmoji();
void onDontAskDownloadPath(); void onDontAskDownloadPath();
void onAutomaticMediaDownloadSettings(); void onAutomaticMediaDownloadSettings();
void onManageStickerSets(); void onManageStickerSets();
@ -94,7 +93,11 @@ private:
void sendByChanged(SendByType value); void sendByChanged(SendByType value);
void createControls(); void createControls();
void toggleReplaceEmoji();
void toggleSuggestStickersByEmoji();
Ui::Checkbox *_replaceEmoji = nullptr; Ui::Checkbox *_replaceEmoji = nullptr;
Ui::Checkbox *_suggestByEmoji = nullptr;
Ui::Checkbox *_dontAskDownloadPath = nullptr; Ui::Checkbox *_dontAskDownloadPath = nullptr;
#ifndef OS_WIN_STORE #ifndef OS_WIN_STORE

View File

@ -571,6 +571,7 @@ enum {
dbiLangPackKey = 0x4e, dbiLangPackKey = 0x4e,
dbiConnectionType = 0x4f, dbiConnectionType = 0x4f,
dbiStickersFavedLimit = 0x50, dbiStickersFavedLimit = 0x50,
dbiSuggestStickersByEmoji = 0x51,
dbiEncryptedWithSalt = 333, dbiEncryptedWithSalt = 333,
dbiEncrypted = 444, dbiEncrypted = 444,
@ -998,6 +999,14 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
Global::SetSoundNotify(v == 1); Global::SetSoundNotify(v == 1);
} break; } break;
case dbiSuggestStickersByEmoji: {
qint32 v;
stream >> v;
if (!_checkStreamStatus(stream)) return false;
Global::SetSuggestStickersByEmoji(v == 1);
} break;
case dbiAutoDownload: { case dbiAutoDownload: {
qint32 photo, audio, gif; qint32 photo, audio, gif;
stream >> photo >> audio >> gif; stream >> photo >> audio >> gif;
@ -1766,7 +1775,7 @@ void _writeUserSettings() {
? userDataInstance->serialize() ? userDataInstance->serialize()
: QByteArray(); : 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) + Serialize::stringSize(Global::AskDownloadPath() ? QString() : Global::DownloadPath()) + Serialize::bytearraySize(Global::AskDownloadPath() ? QByteArray() : Global::DownloadPathBookmark());
size += sizeof(quint32) + sizeof(qint32); size += sizeof(quint32) + sizeof(qint32);
@ -1809,6 +1818,7 @@ void _writeUserSettings() {
data.stream << quint32(dbiModerateMode) << qint32(Global::ModerateModeEnabled() ? 1 : 0); data.stream << quint32(dbiModerateMode) << qint32(Global::ModerateModeEnabled() ? 1 : 0);
data.stream << quint32(dbiAutoPlay) << qint32(cAutoPlayGif() ? 1 : 0); data.stream << quint32(dbiAutoPlay) << qint32(cAutoPlayGif() ? 1 : 0);
data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer()); data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer());
data.stream << quint32(dbiSuggestStickersByEmoji) << qint32(Global::SuggestStickersByEmoji() ? 1 : 0);
if (!userData.isEmpty()) { if (!userData.isEmpty()) {
data.stream << quint32(dbiAuthSessionSettings) << userData; data.stream << quint32(dbiAuthSessionSettings) << userData;
} }