Fixed title of recently used emoji in touchbar.

- Added "No found" title if sticker list is empty.
This commit is contained in:
23rd 2019-06-20 20:31:50 +03:00 committed by John Preston
parent 07a063e19e
commit c7526ae1cd
4 changed files with 32 additions and 23 deletions

View File

@ -18,22 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_chat_helpers.h"
namespace ChatHelpers {
namespace {
tr::phrase<> CategoryTitle(int index) {
switch (index) {
case 1: return tr::lng_emoji_category1;
case 2: return tr::lng_emoji_category2;
case 3: return tr::lng_emoji_category3;
case 4: return tr::lng_emoji_category4;
case 5: return tr::lng_emoji_category5;
case 6: return tr::lng_emoji_category6;
case 7: return tr::lng_emoji_category7;
}
Unexpected("Index in CategoryTitle.");
}
} // namespace
class EmojiColorPicker : public Ui::RpWidget {
public:
@ -545,7 +529,7 @@ void EmojiListWidget::paintEvent(QPaintEvent *e) {
if (info.section > 0 && r.top() < info.rowsTop) {
p.setFont(st::emojiPanHeaderFont);
p.setPen(st::emojiPanHeaderFg);
p.drawTextLeft(st::emojiPanHeaderLeft - st::buttonRadius, info.top + st::emojiPanHeaderTop, width(), CategoryTitle(info.section)(tr::now));
p.drawTextLeft(st::emojiPanHeaderLeft - st::buttonRadius, info.top + st::emojiPanHeaderTop, width(), Ui::Emoji::CategoryTitle(info.section)(tr::now));
}
if (r.top() + r.height() > info.rowsTop) {
ensureLoaded(info.section);

View File

@ -172,6 +172,15 @@ inline int UnreadCount(not_null<PeerData*> peer) {
return 0;
}
QString TitleRecentlyUsed() {
const auto &sets = Auth().data().stickerSets();
const auto it = sets.constFind(Stickers::CloudRecentSetId);
if (it != sets.cend()) {
return it->title;
}
return tr::lng_recent_stickers(tr::now);
}
NSString *FormatTime(int time) {
const auto seconds = time % 60;
const auto minutes = (time / 60) % 60;
@ -324,16 +333,12 @@ void AppendFavedStickers(std::vector<PickerScrubberItem> &to) {
}
void AppendEmojiPacks(std::vector<PickerScrubberItem> &to) {
// Get 'Recent' string.
const auto recent = Auth().data().stickerSets()
.constFind(Stickers::CloudRecentSetId)->title;
for (auto i = 0; i != ChatHelpers::kEmojiSectionCount; ++i) {
const auto section = Ui::Emoji::GetSection(
static_cast<Ui::Emoji::Section>(i));
const auto title = i
? lang(LangKey(lng_emoji_category1 + i))
: recent;
? Ui::Emoji::CategoryTitle(i)(tr::now)
: TitleRecentlyUsed();
to.emplace_back(title);
for (const auto &emoji : section) {
to.emplace_back(PickerScrubberItem(emoji));
@ -712,6 +717,10 @@ void AppendEmojiPacks(std::vector<PickerScrubberItem> &to) {
break;
}
}
if (!temp.size()) {
temp.emplace_back(PickerScrubberItem(
tr::lng_stickers_nothing_found(tr::now)));
}
_stickers = std::move(temp);
}

View File

@ -576,6 +576,19 @@ void ClearIrrelevantCache() {
});
}
tr::phrase<> CategoryTitle(int index) {
switch (index) {
case 1: return tr::lng_emoji_category1;
case 2: return tr::lng_emoji_category2;
case 3: return tr::lng_emoji_category3;
case 4: return tr::lng_emoji_category4;
case 5: return tr::lng_emoji_category5;
case 6: return tr::lng_emoji_category6;
case 7: return tr::lng_emoji_category7;
}
Unexpected("Index in CategoryTitle.");
}
std::vector<Set> Sets() {
return kSets | ranges::to_vector;
}

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/binary_guard.h"
#include "emoji.h"
#include "lang/lang_keys.h"
namespace Ui {
namespace Emoji {
@ -37,6 +38,8 @@ struct Set {
// Thread safe, callback is called on main thread.
void SwitchToSet(int id, Fn<void(bool)> callback);
tr::phrase<> CategoryTitle(int index);
std::vector<Set> Sets();
int CurrentSetId();
bool SetIsReady(int id);