-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathProfileGroupsTabViewModel.cs
More file actions
75 lines (61 loc) · 2.18 KB
/
Copy pathProfileGroupsTabViewModel.cs
File metadata and controls
75 lines (61 loc) · 2.18 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
//
// 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.Threading.Tasks;
using Telegram.Collections;
using Telegram.Navigation;
using Telegram.Navigation.Services;
using Telegram.Services;
using Telegram.Td.Api;
using Windows.UI.Xaml.Navigation;
namespace Telegram.ViewModels.Profile
{
public partial class ProfileGroupsTabViewModel : ViewModelBase, IIncrementalCollectionOwner
{
private long _userId;
private long _nextOffsetId;
public ProfileGroupsTabViewModel(IClientService clientService, ISettingsService settingsService, IEventAggregator aggregator)
: base(clientService, settingsService, aggregator)
{
Items = new IncrementalCollection<Chat>(this);
}
protected override Task OnNavigatedToAsync(object parameter, NavigationMode mode, NavigationState state)
{
if (parameter is long chatId)
{
var chat = ClientService.GetChat(chatId);
if (chat == null)
{
return Task.CompletedTask;
}
var user = ClientService.GetUser(chat);
if (user == null)
{
return Task.CompletedTask;
}
_userId = user.Id;
}
return Task.CompletedTask;
}
public IncrementalCollection<Chat> Items { get; private set; }
public async Task<IncrementalLoadResult> LoadMoreItemsAsync(uint count)
{
Logger.Info();
var total = 0u;
var response = await ClientService.SendAsync(new GetGroupsInCommon(_userId, _nextOffsetId, 20));
if (response is Telegram.Td.Api.Chats chats)
{
foreach (var chat in ClientService.GetChats(chats.ChatIds))
{
_nextOffsetId = chat.Id;
Items.Add(chat);
total++;
}
}
return new IncrementalLoadResult(total, total > 0);
}
}
}