-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathCustomEmojiFileSource.cs
107 lines (92 loc) · 3.25 KB
/
CustomEmojiFileSource.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Copyright Fela Ameghino 2015-2025
//
// 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 Telegram.Common;
using Telegram.Services;
using Telegram.Td.Api;
namespace Telegram.Streams
{
public partial class CustomEmojiFileSource : DelayedFileSource
{
private readonly long _customEmojiId;
public CustomEmojiFileSource(IClientService clientService, long customEmojiId)
: base(clientService, null as File)
{
_customEmojiId = customEmojiId;
DownloadFile(null, null);
}
public CustomEmojiFileSource(IClientService clientService, EmojiStatusType type)
: base(clientService, null as File)
{
if (type is EmojiStatusTypeCustomEmoji customEmoji)
{
_customEmojiId = customEmoji.CustomEmojiId;
}
else if (type is EmojiStatusTypeUpgradedGift upgradedGift)
{
_customEmojiId = upgradedGift.ModelCustomEmojiId;
}
DownloadFile(null, null);
}
public override long Id => _customEmojiId;
public override async void DownloadFile(object sender, UpdateHandler<File> handler)
{
if (_file != null && _file.Local.IsDownloadingCompleted)
{
handler?.Invoke(sender, _file);
}
else
{
if (_file == null)
{
var response = await _clientService.SendAsync(new GetCustomEmojiStickers(new[] { _customEmojiId }));
if (response is Stickers stickers && stickers.StickersValue.Count == 1)
{
var sticker = stickers.StickersValue[0];
_file = sticker.StickerValue;
Format = sticker.Format;
Width = sticker.Width;
Height = sticker.Height;
NeedsRepainting = sticker.FullType is StickerFullTypeCustomEmoji { NeedsRepainting: true };
}
}
if (_file == null)
{
return;
}
else if (_file.Local.IsDownloadingCompleted)
{
handler?.Invoke(sender, _file);
return;
}
if (handler != null)
{
UpdateManager.Subscribe(sender, _clientService, _file, ref _fileToken, handler, true);
}
if (_file.Local.CanBeDownloaded /*&& !_file.Local.IsDownloadingActive*/)
{
_clientService.DownloadFile(_file.Id, 16);
}
}
}
public override bool Equals(object obj)
{
if (obj is CustomEmojiFileSource y && !y.IsUnique && !IsUnique)
{
return y.Id == Id;
}
return base.Equals(obj);
}
public override int GetHashCode()
{
if (IsUnique)
{
return base.GetHashCode();
}
return Id.GetHashCode();
}
}
}