-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathMessageDelegate.cs
More file actions
855 lines (694 loc) · 30.8 KB
/
Copy pathMessageDelegate.cs
File metadata and controls
855 lines (694 loc) · 30.8 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
//
// 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;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Telegram.Common;
using Telegram.Controls;
using Telegram.Navigation;
using Telegram.Navigation.Services;
using Telegram.Services;
using Telegram.Services.Settings;
using Telegram.Td.Api;
using Telegram.ViewModels.Delegates;
using Telegram.ViewModels.Gallery;
using Windows.Storage;
using Windows.UI.Xaml;
namespace Telegram.ViewModels
{
public enum ChatMemberRank
{
Owner,
Admin,
Other
};
public record ChatMemberTag(ChatMemberRank Rank, string Tag, bool CanBeEdited);
public partial class MessageDelegate : ViewModelBase, IMessageDelegate
{
private readonly ViewModelBase _viewModel;
protected static readonly ConcurrentDictionary<long, Dictionary<long, ChatMemberTag>> _admins = new();
public MessageDelegate(ViewModelBase viewModel)
: base(viewModel.ClientService, viewModel.Settings, viewModel.Aggregator)
{
_viewModel = viewModel;
}
public MessageDelegate(IClientService clientService, ISettingsService settings)
: base(clientService, settings, null)
{
_viewModel = null;
}
public virtual Chat Chat { get; }
public bool IsDialog => _viewModel is DialogViewModel;
public bool IsForum => _viewModel is DialogViewModel { IsForum: true };
public bool IsDirectMessagesGroup => _viewModel is DialogViewModel { IsDirectMessagesGroup: true };
public bool IsSavedMessagesTab => _viewModel is DialogViewModel { IsSavedMessagesTab: true };
public override INavigationService NavigationService
{
get => _viewModel?.NavigationService;
set => _viewModel.NavigationService = value;
}
public override IDispatcherContext Dispatcher
{
get => _viewModel?.Dispatcher;
set => _viewModel.Dispatcher = value;
}
public virtual ReactionType SavedMessagesTag { get; set; }
private static readonly string _executableExtensions = "ad ade adp ahk app application appref-ms asp aspx asx bas bat bin cab cdxml cer cfg cgi chi chm cmd cnt com conf cpl crt csh der diagcab dll drv eml exe fon fxp gadget grp hlp hpj hta htt inf ini ins inx isp isu its jar jnlp job js jse jsp key ksh lexe library-ms lnk local lua mad maf mag mam manifest maq mar mas mat mau mav maw mcf mda mdb mde mdt mdw mdz mht mhtml mjs mmc mof msc msg msh msh1 msh2 msh1xml msh2xml mshxml msi msp mst ops osd paf pcd phar php php3 php4 php5 php7 phps php-s pht phtml pif pl plg pm pod prf prg ps1 ps2 ps1xml ps2xml psc1 psc2 psd1 psm1 pssc pst py py3 pyc pyd pyi pyo pyw pyzw pyz rb reg rgs scf scr sct search-ms settingcontent-ms sh shb shs slk sys swf t tmp u3p url vb vbe vbp vbs vbscript vdx vsmacros vsd vsdm vsdx vss vssm vssx vst vstm vstx vsw vsx vtx website wlua ws wsc wsf wsh xbap xll xlsb xlsm xnk xs";
public virtual bool CanBeDownloaded(object content, File file)
{
var chat = Chat;
if (chat == null || ClientService.IsDownloadFileCanceled(file.Id))
{
return false;
}
if (content is Animation animation)
{
return Settings.AutoDownload.ShouldDownloadVideo(GetChatType(chat), animation.AnimationValue.Size);
}
else if (content is Audio audio)
{
return Settings.AutoDownload.ShouldDownloadDocument(GetChatType(chat), audio.AudioValue.Size);
}
else if (content is Document document)
{
var extension = System.IO.Path.GetExtension(document.FileName);
if (_executableExtensions.Contains(extension.TrimStart('.')))
{
return false;
}
return Settings.AutoDownload.ShouldDownloadDocument(GetChatType(chat), document.DocumentValue.Size);
}
else if (content is Photo photo)
{
var big = photo.GetBig();
if (big != null && ClientService.IsDownloadFileCanceled(big.Photo.Id))
{
return false;
}
return Settings.AutoDownload.ShouldDownloadPhoto(GetChatType(chat));
}
else if (content is Sticker)
{
// Stickers aren't part of the deal
return true;
}
else if (content is Video video)
{
return Settings.AutoDownload.ShouldDownloadVideo(GetChatType(chat), video.VideoValue.Size);
}
else if (content is VideoNote videoNote)
{
return Settings.AutoDownload.ShouldDownloadDocument(GetChatType(chat), videoNote.Video.Size);
}
else if (content is VoiceNote)
{
return !Settings.AutoDownload.Disabled;
}
return false;
}
private AutoDownloadChat GetChatType(Chat chat)
{
if (chat.Type is ChatTypeSupergroup supergroup && !supergroup.IsChannel || chat.Type is ChatTypeBasicGroup)
{
return AutoDownloadChat.Group;
}
else if (chat.Type is ChatTypePrivate or ChatTypeSecret)
{
var user = ClientService.GetUser(chat);
if (user == null)
{
return AutoDownloadChat.OtherPrivateChat;
}
else if (user.IsContact)
{
return AutoDownloadChat.Contact;
}
}
return AutoDownloadChat.Channel;
}
public void DownloadFile(MessageViewModel message, File file)
{
ClientService.DownloadFile(file.Id, 32);
}
public async void OpenFile(File file)
{
if (file.Local.Path.EndsWith(".unigram-theme", StringComparison.OrdinalIgnoreCase))
{
}
else if (file.Local.Path.EndsWith(".md", StringComparison.OrdinalIgnoreCase))
{
var instantView = await ParseMarkdown(file);
if (instantView != null)
{
_viewModel.NavigationService.NavigateToInstant(instantView, "tg://" + System.IO.Path.GetFileName(file.Local.Path));
return;
}
}
var service = ClientService.Session.Resolve<IStorageService>();
if (service != null)
{
_ = service.OpenFileAsync(file);
}
}
private async Task<WebPageInstantView> ParseMarkdown(File file)
{
try
{
var storage = await ClientService.GetFileAsync(file);
var text = await FileIO.ReadTextAsync(storage);
var blocks = MarkdownToInstantView.Parse(text);
if (blocks.Count > 0)
{
return new WebPageInstantView(blocks, 0, 2, false, true, null);
}
}
catch
{
}
return null;
}
public void OpenUsername(string username)
{
MessageHelper.NavigateToUsername(ClientService, NavigationService, username);
}
public void OpenUser(long userId)
{
NavigationService.NavigateToUser(userId);
}
public void OpenUrl(string url, bool untrust, OpenUrlSource source = null)
{
source ??= (Chat == null ? null : new OpenUrlSourceChat(Chat.Id, null));
MessageHelper.OpenUrl(ClientService, NavigationService, url, untrust, source);
}
// TODO: needs rework
public async Task<bool> CanEditTagAsync(MessageViewModel message)
{
GetMemberTag(message, out ChatMemberRank rank);
if (message.SenderId.IsUser(message.ClientService.Options.MyId))
{
return message.ClientService.CanEditTag(message.Chat, new ChatMember(message.SenderId, string.Empty, 0, 0, message.ClientService.GetChatMemberStatus(message.Chat, out _)));
}
if (rank == ChatMemberRank.Admin)
{
var response = await message.ClientService.SendAsync(new GetChatMember(message.ChatId, message.SenderId));
if (response is ChatMember member)
{
return message.ClientService.CanEditTag(message.Chat, member);
}
return false;
}
else if (rank != ChatMemberRank.Owner)
{
return message.ClientService.CanEditTag(message.Chat, new ChatMember(message.SenderId, string.Empty, 0, 0, new ChatMemberStatusMember()));
}
return false;
}
public string GetMemberTag(MessageViewModel message, out ChatMemberRank rank)
{
if (message.IsChannelPost)
{
rank = ChatMemberRank.Other;
return string.Empty;
}
if (message.SenderId is MessageSenderUser senderUser)
{
return GetAdminTitle(message, senderUser.UserId, out rank);
}
else if (message.SenderId is MessageSenderChat senderChat && !message.IsChannelPost)
{
rank = ChatMemberRank.Other;
return message.AuthorSignature.Length > 0 ? message.AuthorSignature : senderChat.ChatId == Chat.Id ? Strings.ChannelAdmin : string.Empty;
}
rank = ChatMemberRank.Other;
return string.Empty;
}
public string GetAdminTitle(MessageViewModel message, long userId, out ChatMemberRank rank)
{
if (_admins.TryGetValue(message.ChatId, out Dictionary<long, ChatMemberTag> value))
{
if (value.TryGetValue(userId, out ChatMemberTag tag))
{
rank = tag.Rank;
if (string.IsNullOrEmpty(tag.Tag))
{
if (tag.Rank == ChatMemberRank.Owner)
{
return Strings.ChatTagOwner;
}
return Strings.ChatTagAdmin;
}
return tag.Tag;
}
}
rank = ChatMemberRank.Other;
return message.SenderTag;
}
public bool IsAdministrator(MessageSender memberId)
{
var chat = Chat;
if (chat == null || memberId is not MessageSenderUser user)
{
return false;
}
if (_admins.TryGetValue(chat.Id, out Dictionary<long, ChatMemberTag> value))
{
if (value.TryGetValue(user.UserId, out var tag))
{
return tag.Rank != ChatMemberRank.Owner;
}
}
return false;
}
public void UpdateAdministrators(Chat chat)
{
if (ClientService.TryGetBasicGroupFull(chat, out BasicGroupFullInfo fullInfo))
{
var members = new Dictionary<long, ChatMemberTag>();
foreach (var member in fullInfo.Members)
{
if (member.MemberId is not MessageSenderUser senderUser)
{
continue;
}
var type = member.Status switch
{
ChatMemberStatusCreator => ChatMemberRank.Owner,
ChatMemberStatusAdministrator => ChatMemberRank.Admin,
_ => ChatMemberRank.Other
};
// TODO: needs implementation
//var canBeEdited = member.Status switch
//{
// ChatMemberStatusCreator =>
// ChatMemberStatusAdministrator admin => admin.CanBeEdited
//}
var canBeEdited = false;
members[senderUser.UserId] = new ChatMemberTag(type, member.Tag, canBeEdited);
}
_admins[chat.Id] = members;
}
else if (chat.Type is ChatTypeSupergroup { IsChannel: false })
{
ClientService.Send(new GetChatAdministrators(chat.Id), result =>
{
if (result is ChatAdministrators users)
{
_admins[chat.Id] = users.Administrators.ToDictionary(x => x.UserId, y => new ChatMemberTag(y.IsOwner ? ChatMemberRank.Owner : ChatMemberRank.Admin, y.CustomTitle, y.CanBeEdited));
}
});
}
}
#region Facades
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void HideSponsoredMessage(MessageViewModel message) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void ForwardMessage(MessageViewModel message) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void SummarizeMessage(MessageViewModel message) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void ViewVisibleMessages() { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void ExecuteServiceMessage(MessageViewModel message) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenReply(MessageViewModel message) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenThread(MessageViewModel message) { }
public virtual void OpenSender(MessageViewModel message)
{
if (message.IsSaved || message.IsVerificationCode)
{
if (message.ForwardInfo?.Origin is MessageOriginUser fromUser)
{
OpenUser(fromUser.SenderUserId);
}
else if (message.ForwardInfo?.Origin is MessageOriginChat fromChat)
{
OpenChat(fromChat.SenderChatId, true);
}
else if (message.ForwardInfo?.Origin is MessageOriginChannel fromChannel)
{
// TODO: verify if this is sufficient
OpenChat(fromChannel.ChatId);
}
else if (message.ForwardInfo?.Origin is MessageOriginHiddenUser)
{
ToastPopup.Show(XamlRoot, Strings.HidAccount);
}
}
else if (message.ClientService.TryGetChat(message.SenderId, out Chat senderChat))
{
if (senderChat.Type is ChatTypeSupergroup supergroup && supergroup.IsChannel)
{
OpenChat(senderChat.Id);
}
else
{
OpenChat(senderChat.Id, true);
}
}
else if (message.SenderId is MessageSenderUser senderUser)
{
OpenUser(senderUser.UserId);
}
}
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenWebPage(MessageViewModel message) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenSticker(Sticker sticker) { }
public async void OpenLocation(Location location, string title)
{
try
{
if (title != null)
{
// TODO: is title supported?
await Windows.System.Launcher.LaunchUriAsync(new Uri(string.Format(CultureInfo.InvariantCulture, "https://www.google.com/maps/search/?api=1&query={0},{1}", location.Latitude, location.Longitude)));
}
else
{
await Windows.System.Launcher.LaunchUriAsync(new Uri(string.Format(CultureInfo.InvariantCulture, "https://www.google.com/maps/search/?api=1&query={0},{1}", location.Latitude, location.Longitude)));
}
}
catch
{
// All the remote procedure calls must be wrapped in a try-catch block
}
}
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenGame(MessageViewModel message) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenInlineButton(MessageViewModel message, InlineKeyboardButton button) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void Call(MessageViewModel message, bool video) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void VotePoll(MessageViewModel message, Vector<int> options) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenViaBot(long viaBotUserId) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenChat(long chatId, bool profile = false) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenChat(long chatId, long messageId) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenHashtag(string hashtag) { }
public virtual void OpenBankCardNumber(string number)
{
//var response = await ClientService.SendAsync(new GetBankCardInfo(number));
//if (response is BankCardInfo info)
//{
// var url = info.Actions.FirstOrDefault(x => x.)
//}
}
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenMedia(MessageViewModel message, FrameworkElement target, double timestamp = 0) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenMedia(GalleryMedia media, FrameworkElement target) { }
/// <summary>
/// Opens the gallery for a medium tapped inside a page (an instant view or a rich
/// message): the gallery is built from <paramref name="blocks"/> on demand, in
/// document order, and opens at the block the tapped element belongs to.
///
/// Nothing is collected while rendering — the blocks are the source of truth, and
/// the tapped element finds its own block by walking up the Tag chain. That's what
/// lets one renderer serve both hosts.
/// </summary>
protected void OpenPageBlockMedia(Vector<PageBlock> blocks, PageBlockMediaKind kind, FrameworkElement target)
{
var gallery = new InstantGalleryViewModel(ClientService,
ClientService.Session.Resolve<IStorageService>(),
ClientService.Session.Resolve<IEventAggregator>());
var media = PageBlockHelper.FindAllMedia(blocks, kind);
var source = FindBlock(target);
foreach (var block in media)
{
GalleryMedia item;
if (block is PageBlockPhoto photo)
{
item = new GalleryPhoto(ClientService, photo.Photo, photo.Caption?.ToFormattedText());
}
else if (block is PageBlockVideo video)
{
item = new GalleryVideo(ClientService, video.Video, video.Caption?.ToFormattedText());
}
else if (block is PageBlockAnimation animation)
{
item = new GalleryAnimation(ClientService, animation.Animation, animation.Caption?.ToFormattedText());
}
else
{
continue;
}
gallery.Items.Add(item);
if (source == block)
{
gallery.SelectedItem = item;
gallery.FirstItem = item;
}
}
NavigationService.ShowGallery(gallery, target);
static PageBlock FindBlock(FrameworkElement element)
{
if (element.Tag is PageBlock block)
{
return block;
}
else if (element.Parent is FrameworkElement parent)
{
return FindBlock(parent);
}
return null;
}
}
// Which gallery a tapped medium belongs to. Photos and videos share one; an
// animation opens on its own.
protected static bool TryGetMediaKind(MessageContent content, out PageBlockMediaKind kind)
{
if (content is MessagePhoto or MessageVideo)
{
kind = PageBlockMediaKind.Media;
return true;
}
else if (content is MessageAnimation)
{
kind = PageBlockMediaKind.Animation;
return true;
}
kind = PageBlockMediaKind.None;
return false;
}
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenPoll(MessageViewModel message) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void OpenPaidMedia(MessageViewModel message, PaidMedia media, FrameworkElement target, double timestamp = 0) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void PlayMessage(MessageViewModel message)
{
LifetimeService.Current.Playback.Play(XamlRoot, message);
}
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual bool RecognizeSpeech(MessageViewModel message) { return false; }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void SendBotCommand(string command) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void SendMessage(InputMessageContent content) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual bool IsTranslating { get; }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual bool IsSelectionEnabled { get; }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual IDictionary<long, MessageViewModel> SelectedItems { get; }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void Select(MessageViewModel message) { }
/// <summary>
/// Only available when created through DialogViewModel
/// </summary>
public virtual void Unselect(MessageViewModel message, bool updateSelection) { }
#endregion
}
public partial class ChatMessageDelegate : MessageDelegate
{
private readonly Chat _chat;
public ChatMessageDelegate(IClientService clientService, ISettingsService settings, Chat chat)
: base(clientService, settings)
{
_chat = chat;
}
public ChatMessageDelegate(ViewModelBase viewModel, Chat chat)
: base(viewModel)
{
_chat = chat;
}
public override Chat Chat => _chat;
}
public partial class DialogMessageDelegate : MessageDelegate
{
private readonly DialogViewModel _viewModel;
public DialogMessageDelegate(DialogViewModel viewModel)
: base(viewModel)
{
_viewModel = viewModel;
}
public DialogViewModel ViewModel => _viewModel;
public override Chat Chat => _viewModel.Chat;
#region Facades
public override ReactionType SavedMessagesTag
{
get => _viewModel.Search?.SavedMessagesTag;
set
{
if (_viewModel.Search == null)
{
_viewModel.SearchExecute(string.Empty);
}
_viewModel.Search.SavedMessagesTag = value;
}
}
public override void HideSponsoredMessage(MessageViewModel message) => _viewModel.HideSponsoredMessage(message);
public override void ForwardMessage(MessageViewModel message) => _viewModel.ForwardMessage(message);
public override void SummarizeMessage(MessageViewModel message) => _viewModel.SummarizeMessage(message);
public override void ViewVisibleMessages() => _viewModel.ViewVisibleMessages();
public override void ExecuteServiceMessage(MessageViewModel message) => _viewModel.ExecuteServiceMessage(message);
public override void OpenReply(MessageViewModel message) => _viewModel.OpenReply(message);
public override void OpenThread(MessageViewModel message) => _viewModel.OpenThread(message);
public override void OpenWebPage(MessageViewModel message) => _viewModel.OpenWebPage(message);
public override void OpenSticker(Sticker sticker) => _viewModel.OpenSticker(sticker);
public override void OpenGame(MessageViewModel message) => _viewModel.OpenGame(message);
public override void OpenInlineButton(MessageViewModel message, InlineKeyboardButton button) => _viewModel.OpenInlineButton(message, button);
public override void Call(MessageViewModel message, bool video) => _viewModel.Call(message, video);
public override void VotePoll(MessageViewModel message, Vector<int> options) => _viewModel.VotePoll(message, options);
public override void OpenViaBot(long viaBotUserId) => _viewModel.OpenViaBot(viaBotUserId);
public override void OpenChat(long chatId, bool profile = false) => _viewModel.OpenChat(chatId, profile);
public override void OpenChat(long chatId, long messageId) => _viewModel.OpenChat(chatId, messageId);
public override void OpenHashtag(string hashtag) => _viewModel.OpenHashtag(hashtag);
public override void OpenBankCardNumber(string number)
{
//var response = await ClientService.SendAsync(new GetBankCardInfo(number));
//if (response is BankCardInfo info)
//{
// var url = info.Actions.FirstOrDefault(x => x.)
//}
}
public override void OpenMedia(MessageViewModel message, FrameworkElement target, double timestamp = 0) => _viewModel.OpenMedia(message, target, timestamp);
public override void OpenMedia(GalleryMedia media, FrameworkElement target) => _viewModel.OpenMedia(media, target);
public override void OpenPoll(MessageViewModel message) => _viewModel.OpenPoll(message);
public override void OpenPaidMedia(MessageViewModel message, PaidMedia media, FrameworkElement target, double timestamp = 0)
{
_viewModel.OpenPaidMedia(message, media, target, timestamp);
}
public override void PlayMessage(MessageViewModel message) => _viewModel.PlayMessage(message);
public override bool RecognizeSpeech(MessageViewModel message) => _viewModel.RecognizeSpeech(message);
public override void SendBotCommand(string command) => _viewModel.SendBotCommand(command);
public override void SendMessage(InputMessageContent content) => _viewModel.SendContent(content);
public override bool IsTranslating => _viewModel.IsTranslating;
public override bool IsSelectionEnabled => _viewModel.IsSelectionEnabled;
public override IDictionary<long, MessageViewModel> SelectedItems => _viewModel.SelectedItems;
public override void Select(MessageViewModel message) => _viewModel.Select(message);
public override void Unselect(MessageViewModel message, bool updateSelection) => _viewModel.Unselect(message, updateSelection);
#endregion
}
public partial class InstantMessageDelegate : MessageDelegate
{
private readonly InstantViewModel _viewModel;
public InstantMessageDelegate(InstantViewModel viewModel)
: base(viewModel)
{
_viewModel = viewModel;
}
public override Chat Chat => null;
public override bool CanBeDownloaded(object content, File file)
{
return !Settings.AutoDownload.Disabled;
}
public override void OpenMedia(MessageViewModel message, FrameworkElement target, double timestamp = 0)
{
// Built from the page's blocks on tap, exactly like a rich message. The
// renderer collects nothing while it builds, so there's no parallel gallery
// list to keep in sync — and none to go stale when the page re-renders.
if (TryGetMediaKind(message.Content, out var kind))
{
OpenPageBlockMedia(_viewModel.Blocks, kind, target);
}
}
}
public partial class RichMessageDelegate : DialogMessageDelegate
{
private readonly RichMessage _message;
private readonly DialogMessageDelegate _delegate;
public RichMessageDelegate(RichMessage message, DialogMessageDelegate delegato)
: base(delegato.ViewModel)
{
_message = message;
}
public override void OpenMedia(MessageViewModel message, FrameworkElement target, double timestamp = 0)
{
if (TryGetMediaKind(message.Content, out var kind))
{
OpenPageBlockMedia(_message.Blocks, kind, target);
}
}
}
}