-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathSearchEmojiCollection.cs
More file actions
73 lines (64 loc) · 2.5 KB
/
Copy pathSearchEmojiCollection.cs
File metadata and controls
73 lines (64 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Copyright (c) Fela Ameghino 2015-2026
//
// Distributed under the GNU General Public License v3.0. (See accompanying
// file LICENSE or copy at https://www.gnu.org/licenses/gpl-3.0.txt)
//
using System.Linq;
using System.Threading.Tasks;
using Telegram.Common;
using Telegram.Native;
using Telegram.Services;
using Telegram.Td.Api;
using Telegram.ViewModels.Drawers;
namespace Telegram.Collections
{
public partial class SearchEmojiCollection : IncrementalCollection<object>
{
private readonly IClientService _clientService;
private readonly string _query;
private readonly EmojiDrawerMode _mode;
public SearchEmojiCollection(IClientService clientService, string query, EmojiDrawerMode mode)
{
_clientService = clientService;
_query = query;
_mode = mode;
}
// One response covers the query, so there is never a second page.
protected override async Task<IncrementalLoadResult> OnLoadMoreItemsAsync(uint count)
{
var totalCount = 0u;
var inputLanguage = NativeUtils.GetKeyboardCulture();
var response = await _clientService.SendAsync(new SearchEmojis(_query, new[] { inputLanguage }));
if (response is EmojiKeywords suggestions)
{
if (_clientService.IsPremium)
{
var stickers = await Emoji.SearchAsync(_clientService, suggestions.EmojiKeywordsValue.DistinctBy(x => x.Emoji).Select(x => x.Emoji));
foreach (var item in stickers)
{
Add(item);
totalCount++;
}
}
if (_mode == EmojiDrawerMode.Chat)
{
foreach (var item in suggestions.EmojiKeywordsValue.DistinctBy(x => x.Emoji))
{
var emoji = item.Emoji;
if (Emoji.EmojiGroupInternal._skinEmojis.Contains(emoji) || Emoji.EmojiGroupInternal._skinEmojis.Contains(emoji.TrimEnd('\uFE0F')))
{
Add(AppSettings.Emoji.GetEmojiSkinTone(emoji));
}
else
{
Add(new EmojiData(item.Emoji));
}
totalCount++;
}
}
}
return new IncrementalLoadResult(totalCount, false);
}
}
}