-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathChatNotificationsViewModel.cs
124 lines (109 loc) · 3.65 KB
/
ChatNotificationsViewModel.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// 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.Linq;
using System.Threading.Tasks;
using Telegram.Navigation.Services;
using Telegram.Services;
using Telegram.Td.Api;
using Windows.UI.Xaml.Navigation;
namespace Telegram.ViewModels
{
public partial class ChatNotificationsViewModel : ChooseSoundViewModel
{
public ChatNotificationsViewModel(IClientService clientService, ISettingsService settingsService, IEventAggregator aggregator)
: base(clientService, settingsService, aggregator)
{
}
private long _chatId;
private string _title;
public string Title
{
get => _title;
set => Set(ref _title, value);
}
private bool _alwaysAlert;
public bool AlwaysAlert
{
get => _alwaysAlert;
set => Set(ref _alwaysAlert, value);
}
private bool? _alwaysPreview;
public bool? AlwaysPreview
{
get => _alwaysPreview;
set => Set(ref _alwaysPreview, value);
}
private bool _useNoSound;
public bool UseNoSound
{
get => _useNoSound;
set => Set(ref _useNoSound, value);
}
private bool _useDefault;
public bool UseDefault
{
get => _useDefault;
set => Set(ref _useDefault, value);
}
protected override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, NavigationState state)
{
await base.OnNavigatedToAsync(parameter, mode, state);
if (parameter is long chatId && ClientService.TryGetChat(chatId, out Chat chat))
{
_chatId = chat.Id;
Title = ClientService.GetTitle(chat);
AlwaysAlert = !Settings.Notifications.IsMuted(chat);
if (chat.NotificationSettings.UseDefaultShowPreview)
{
AlwaysPreview = null;
}
else
{
AlwaysPreview = chat.NotificationSettings.ShowPreview;
}
var soundId = Settings.Notifications.GetSoundId(chat);
if (soundId == -1)
{
UseDefault = true;
}
else if (soundId == 0)
{
UseNoSound = true;
}
else
{
var sound = Items.FirstOrDefault(x => x.Id == soundId);
if (sound != null)
{
sound.IsSelected = true;
}
}
}
}
public void Confirm(long? soundId)
{
var defaultPreview = true;
var preview = true;
if (AlwaysPreview is bool alwaysPreview)
{
defaultPreview = false;
preview = alwaysPreview;
}
ClientService.Send(new SetChatNotificationSettings(_chatId, new ChatNotificationSettings
{
UseDefaultMuteFor = false,
MuteFor = AlwaysAlert ? 0 : int.MaxValue,
UseDefaultShowPreview = defaultPreview,
ShowPreview = preview,
UseDefaultSound = soundId == null,
SoundId = soundId ?? 0,
UseDefaultDisableMentionNotifications = true,
UseDefaultDisablePinnedMessageNotifications = true,
}));
}
}
}