-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathChatJoinRequestsViewModel.cs
86 lines (68 loc) · 2.71 KB
/
ChatJoinRequestsViewModel.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
//
// 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 System.Threading.Tasks;
using Telegram.Collections;
using Telegram.Common;
using Telegram.Navigation;
using Telegram.Services;
using Telegram.Td.Api;
using Windows.UI.Xaml.Data;
namespace Telegram.ViewModels
{
public partial class ChatJoinRequestsViewModel : ViewModelBase, IIncrementalCollectionOwner
{
private readonly Chat _chat;
private readonly string _inviteLink;
public ChatJoinRequestsViewModel(Chat chat, string inviteLink, IClientService clientService, ISettingsService settingsService, IEventAggregator aggregator)
: base(clientService, settingsService, aggregator)
{
_chat = chat;
_inviteLink = inviteLink;
Items = new IncrementalCollection<ChatJoinRequest>(this);
AcceptCommand = new RelayCommand<ChatJoinRequest>(Accept);
DismissCommand = new RelayCommand<ChatJoinRequest>(Dismiss);
}
public bool IsChannel => _chat?.Type is ChatTypeSupergroup supergroup && supergroup.IsChannel;
public IncrementalCollection<ChatJoinRequest> Items { get; private set; }
public RelayCommand<ChatJoinRequest> AcceptCommand { get; }
private void Accept(ChatJoinRequest request)
{
Process(request, true);
}
public RelayCommand<ChatJoinRequest> DismissCommand { get; }
private void Dismiss(ChatJoinRequest request)
{
Process(request, false);
}
private void Process(ChatJoinRequest request, bool approve)
{
Items.Remove(request);
ClientService.Send(new ProcessChatJoinRequest(_chat.Id, request.UserId, approve));
}
#region IIncrementalCollectionOwner
private ChatJoinRequest _offset;
private bool _hasMoreItems = true;
public async Task<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
{
var totalCount = 0u;
var response = await ClientService.SendAsync(new GetChatJoinRequests(_chat.Id, _inviteLink, string.Empty, _offset, 10));
if (response is ChatJoinRequests requests)
{
foreach (var item in requests.Requests)
{
_offset = item;
Items.Add(item);
totalCount++;
}
_hasMoreItems = requests.Requests.Count > 0;
}
return new LoadMoreItemsResult { Count = totalCount };
}
public bool HasMoreItems => _hasMoreItems;
#endregion
}
}