mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Support mixed custom / default recent emoji.
This commit is contained in:
@@ -81,11 +81,17 @@ QByteArray Settings::serialize() const {
|
||||
const auto windowPosition = Serialize(_windowPosition);
|
||||
const auto proxy = _proxy.serialize();
|
||||
|
||||
auto recentEmojiPreloadGenerated = std::vector<RecentEmojiId>();
|
||||
auto recentEmojiPreloadGenerated = std::vector<RecentEmojiPreload>();
|
||||
if (_recentEmojiPreload.empty()) {
|
||||
recentEmojiPreloadGenerated.reserve(_recentEmoji.size());
|
||||
for (const auto &[emoji, rating] : _recentEmoji) {
|
||||
recentEmojiPreloadGenerated.push_back({ emoji->id(), rating });
|
||||
for (const auto &[id, rating] : _recentEmoji) {
|
||||
auto string = QString();
|
||||
if (const auto documentId = std::get_if<DocumentId>(&id.data)) {
|
||||
string = QString::number(*documentId);
|
||||
} else if (const auto emoji = std::get_if<EmojiPtr>(&id.data)) {
|
||||
string = (*emoji)->id();
|
||||
}
|
||||
recentEmojiPreloadGenerated.push_back({ string, rating });
|
||||
}
|
||||
}
|
||||
const auto &recentEmojiPreloadData = _recentEmojiPreload.empty()
|
||||
@@ -316,7 +322,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||
qint32 callAudioBackend = 0;
|
||||
qint32 disableCallsLegacy = 0;
|
||||
QByteArray windowPosition;
|
||||
std::vector<RecentEmojiId> recentEmojiPreload;
|
||||
std::vector<RecentEmojiPreload> recentEmojiPreload;
|
||||
base::flat_map<QString, uint8> emojiVariants;
|
||||
qint32 disableOpenGL = _disableOpenGL ? 1 : 0;
|
||||
qint32 groupCallNoiseSuppression = _groupCallNoiseSuppression ? 1 : 0;
|
||||
@@ -790,18 +796,24 @@ const std::vector<Settings::RecentEmoji> &Settings::recentEmoji() const {
|
||||
}
|
||||
|
||||
void Settings::resolveRecentEmoji() const {
|
||||
const auto haveAlready = [&](EmojiPtr emoji) {
|
||||
const auto haveAlready = [&](RecentEmojiId id) {
|
||||
return ranges::contains(
|
||||
_recentEmoji,
|
||||
emoji->id(),
|
||||
[](const RecentEmoji &data) { return data.emoji->id(); });
|
||||
id,
|
||||
[](const RecentEmoji &data) { return data.id; });
|
||||
};
|
||||
if (!_recentEmojiPreload.empty()) {
|
||||
_recentEmoji.reserve(_recentEmojiPreload.size());
|
||||
for (const auto &[id, rating] : base::take(_recentEmojiPreload)) {
|
||||
if (const auto emoji = Ui::Emoji::Find(id)) {
|
||||
if (!haveAlready(emoji)) {
|
||||
_recentEmoji.push_back({ emoji, rating });
|
||||
auto length = int();
|
||||
const auto emoji = Ui::Emoji::Find(id, &length);
|
||||
if (emoji && length == id.size()) {
|
||||
if (!haveAlready({ emoji })) {
|
||||
_recentEmoji.push_back({ { emoji }, rating });
|
||||
}
|
||||
} else if (const auto documentId = id.toULongLong()) {
|
||||
if (!haveAlready({ documentId })) {
|
||||
_recentEmoji.push_back({ { documentId }, rating });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -810,29 +822,18 @@ void Settings::resolveRecentEmoji() const {
|
||||
for (const auto emoji : Ui::Emoji::GetDefaultRecent()) {
|
||||
if (_recentEmoji.size() >= kRecentEmojiLimit) {
|
||||
break;
|
||||
} else if (!haveAlready(emoji)) {
|
||||
_recentEmoji.push_back({ emoji, 1 });
|
||||
} else if (!haveAlready({ emoji })) {
|
||||
_recentEmoji.push_back({ { emoji }, 1 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EmojiPack Settings::recentEmojiSection() const {
|
||||
const auto &recent = recentEmoji();
|
||||
|
||||
auto result = EmojiPack();
|
||||
result.reserve(recent.size());
|
||||
for (const auto &[emoji, rating] : recent) {
|
||||
result.push_back(emoji);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Settings::incrementRecentEmoji(EmojiPtr emoji) {
|
||||
void Settings::incrementRecentEmoji(RecentEmojiId id) {
|
||||
resolveRecentEmoji();
|
||||
|
||||
auto i = _recentEmoji.begin(), e = _recentEmoji.end();
|
||||
for (; i != e; ++i) {
|
||||
if (i->emoji == emoji) {
|
||||
if (i->id == id) {
|
||||
++i->rating;
|
||||
if (i->rating > 0x8000) {
|
||||
for (auto j = _recentEmoji.begin(); j != e; ++j) {
|
||||
@@ -856,7 +857,7 @@ void Settings::incrementRecentEmoji(EmojiPtr emoji) {
|
||||
while (_recentEmoji.size() >= kRecentEmojiLimit) {
|
||||
_recentEmoji.pop_back();
|
||||
}
|
||||
_recentEmoji.push_back({ emoji, 1 });
|
||||
_recentEmoji.push_back({ id, 1 });
|
||||
for (i = _recentEmoji.end() - 1; i != _recentEmoji.begin(); --i) {
|
||||
if ((i - 1)->rating > i->rating) {
|
||||
break;
|
||||
|
@@ -573,13 +573,19 @@ public:
|
||||
return _workMode.changes();
|
||||
}
|
||||
|
||||
struct RecentEmojiId {
|
||||
std::variant<EmojiPtr, DocumentId> data;
|
||||
|
||||
friend inline auto operator<=>(
|
||||
RecentEmojiId,
|
||||
RecentEmojiId) = default;
|
||||
};
|
||||
struct RecentEmoji {
|
||||
EmojiPtr emoji = nullptr;
|
||||
RecentEmojiId id;
|
||||
ushort rating = 0;
|
||||
};
|
||||
[[nodiscard]] const std::vector<RecentEmoji> &recentEmoji() const;
|
||||
[[nodiscard]] EmojiPack recentEmojiSection() const;
|
||||
void incrementRecentEmoji(EmojiPtr emoji);
|
||||
void incrementRecentEmoji(RecentEmojiId id);
|
||||
void setLegacyRecentEmojiPreload(QVector<QPair<QString, ushort>> data);
|
||||
[[nodiscard]] rpl::producer<> recentEmojiUpdated() const {
|
||||
return _recentEmojiUpdated.events();
|
||||
@@ -708,7 +714,7 @@ private:
|
||||
static constexpr auto kDefaultDialogsWidthRatio = 5. / 14;
|
||||
static constexpr auto kDefaultBigDialogsWidthRatio = 0.275;
|
||||
|
||||
struct RecentEmojiId {
|
||||
struct RecentEmojiPreload {
|
||||
QString emoji;
|
||||
ushort rating = 0;
|
||||
};
|
||||
@@ -764,7 +770,7 @@ private:
|
||||
rpl::variable<std::vector<int>> _dictionariesEnabled;
|
||||
rpl::variable<bool> _autoDownloadDictionaries = true;
|
||||
rpl::variable<bool> _mainMenuAccountsShown = true;
|
||||
mutable std::vector<RecentEmojiId> _recentEmojiPreload;
|
||||
mutable std::vector<RecentEmojiPreload> _recentEmojiPreload;
|
||||
mutable std::vector<RecentEmoji> _recentEmoji;
|
||||
base::flat_map<QString, uint8> _emojiVariants;
|
||||
rpl::event_stream<> _recentEmojiUpdated;
|
||||
|
@@ -269,7 +269,7 @@ const Ui::Emoji::One *UiIntegration::defaultEmojiVariant(
|
||||
const auto result = (i != end(variants))
|
||||
? emoji->variant(i->second)
|
||||
: emoji;
|
||||
Core::App().settings().incrementRecentEmoji(result);
|
||||
Core::App().settings().incrementRecentEmoji({ result });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user