mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Find emoji by words for stickers search.
This commit is contained in:
parent
c48ac28204
commit
21f3a7b07f
5 changed files with 50 additions and 42 deletions
|
@ -46,7 +46,6 @@ namespace {
|
|||
|
||||
constexpr auto kCollapsedRows = 3;
|
||||
constexpr auto kAppearDuration = 0.3;
|
||||
constexpr auto kPlainSearchLimit = 32;
|
||||
constexpr auto kCustomSearchLimit = 256;
|
||||
|
||||
using Core::RecentEmojiId;
|
||||
|
@ -519,39 +518,7 @@ void EmojiListWidget::applyNextSearchQuery() {
|
|||
}
|
||||
|
||||
std::vector<EmojiPtr> EmojiListWidget::collectPlainSearchResults() {
|
||||
auto result = std::vector<EmojiPtr>();
|
||||
const auto pushPlain = [&](EmojiPtr emoji) {
|
||||
if (result.size() < kPlainSearchLimit
|
||||
&& _searchEmoji.emplace(emoji).second) {
|
||||
result.push_back(emoji);
|
||||
}
|
||||
if (const auto original = emoji->original(); original != emoji) {
|
||||
_searchEmoji.emplace(original);
|
||||
}
|
||||
};
|
||||
auto refreshed = false;
|
||||
auto &keywords = Core::App().emojiKeywords();
|
||||
for (const auto &entry : _searchQuery) {
|
||||
if (const auto emoji = Ui::Emoji::Find(entry)) {
|
||||
pushPlain(emoji);
|
||||
if (result.size() >= kPlainSearchLimit) {
|
||||
return result;
|
||||
}
|
||||
} else if (!entry.isEmpty()) {
|
||||
if (!refreshed) {
|
||||
refreshed = true;
|
||||
keywords.refresh();
|
||||
}
|
||||
const auto list = keywords.queryMine(entry);
|
||||
for (const auto &entry : list) {
|
||||
pushPlain(entry.emoji);
|
||||
if (result.size() >= kPlainSearchLimit) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return SearchEmoji(_searchQuery, _searchEmoji);
|
||||
}
|
||||
|
||||
void EmojiListWidget::appendPremiumSearchResults() {
|
||||
|
|
|
@ -7,8 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "chat_helpers/stickers_list_footer.h"
|
||||
|
||||
#include "chat_helpers/emoji_keywords.h"
|
||||
#include "chat_helpers/stickers_emoji_pack.h"
|
||||
#include "chat_helpers/stickers_lottie.h"
|
||||
#include "core/application.h"
|
||||
#include "data/stickers/data_stickers_set.h"
|
||||
#include "data/stickers/data_stickers.h"
|
||||
#include "data/stickers/data_custom_emoji.h"
|
||||
|
@ -36,6 +38,7 @@ namespace ChatHelpers {
|
|||
namespace {
|
||||
|
||||
constexpr auto kEmojiSectionSetIdBase = uint64(0x77FF'FFFF'FFFF'FFF0ULL);
|
||||
constexpr auto kEmojiSearchLimit = 32;
|
||||
|
||||
using EmojiSection = Ui::Emoji::Section;
|
||||
|
||||
|
@ -145,6 +148,44 @@ rpl::producer<std::vector<GifSection>> GifSectionsValue(
|
|||
}) | rpl::flatten_latest();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<EmojiPtr> SearchEmoji(
|
||||
const std::vector<QString> &query,
|
||||
base::flat_set<EmojiPtr> &outResultSet) {
|
||||
auto result = std::vector<EmojiPtr>();
|
||||
const auto pushPlain = [&](EmojiPtr emoji) {
|
||||
if (result.size() < kEmojiSearchLimit
|
||||
&& outResultSet.emplace(emoji).second) {
|
||||
result.push_back(emoji);
|
||||
}
|
||||
if (const auto original = emoji->original(); original != emoji) {
|
||||
outResultSet.emplace(original);
|
||||
}
|
||||
};
|
||||
auto refreshed = false;
|
||||
auto &keywords = Core::App().emojiKeywords();
|
||||
for (const auto &entry : query) {
|
||||
if (const auto emoji = Ui::Emoji::Find(entry)) {
|
||||
pushPlain(emoji);
|
||||
if (result.size() >= kEmojiSearchLimit) {
|
||||
return result;
|
||||
}
|
||||
} else if (!entry.isEmpty()) {
|
||||
if (!refreshed) {
|
||||
refreshed = true;
|
||||
keywords.refresh();
|
||||
}
|
||||
const auto list = keywords.queryMine(entry);
|
||||
for (const auto &entry : list) {
|
||||
pushPlain(entry.emoji);
|
||||
if (result.size() >= kEmojiSearchLimit) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
StickerIcon::StickerIcon(uint64 setId) : setId(setId) {
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,10 @@ struct GifSection {
|
|||
[[nodiscard]] rpl::producer<std::vector<GifSection>> GifSectionsValue(
|
||||
not_null<Main::Session*> session);
|
||||
|
||||
[[nodiscard]] std::vector<EmojiPtr> SearchEmoji(
|
||||
const std::vector<QString> &query,
|
||||
base::flat_set<EmojiPtr> &outResultSet);
|
||||
|
||||
struct StickerIcon {
|
||||
explicit StickerIcon(uint64 setId);
|
||||
StickerIcon(
|
||||
|
|
|
@ -2557,17 +2557,13 @@ void StickersListWidget::beforeHiding() {
|
|||
void StickersListWidget::setupSearch() {
|
||||
const auto session = &_controller->session();
|
||||
_search = MakeSearch(this, st(), [=](std::vector<QString> &&query) {
|
||||
auto emoji = query | ranges::views::transform([](const QString &k) {
|
||||
return Ui::Emoji::Find(k);
|
||||
}) | ranges::views::filter([](EmojiPtr emoji) {
|
||||
return (emoji != nullptr);
|
||||
}) | ranges::to_vector;
|
||||
auto set = base::flat_set<EmojiPtr>();
|
||||
auto text = ranges::accumulate(query, QString(), [](
|
||||
QString a,
|
||||
QString b) {
|
||||
return a.isEmpty() ? b : (a + ' ' + b);
|
||||
});
|
||||
searchForSets(std::move(text), std::move(emoji));
|
||||
searchForSets(std::move(text), SearchEmoji(query, set));
|
||||
}, session);
|
||||
}
|
||||
|
||||
|
|
|
@ -1273,11 +1273,11 @@ std::vector<not_null<DocumentData*>> Stickers::getListByEmoji(
|
|||
for (const auto document : *list) {
|
||||
const auto sticker = document->sticker();
|
||||
if (!sticker) {
|
||||
return;
|
||||
continue;
|
||||
} else if (!single) {
|
||||
const auto main = Ui::Emoji::Find(sticker->alt);
|
||||
if (!main || !all.contains(main)) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const auto installDate = my ? set->installDate : TimeId(0);
|
||||
|
|
Loading…
Add table
Reference in a new issue