-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathPushUtils.cs
executable file
·764 lines (662 loc) · 28.2 KB
/
PushUtils.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
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
//
// This is the source code of Telegram for Windows Phone v. 3.x.x.
// It is licensed under GNU GPL v. 2 or later.
// You should have received a copy of the license in this archive (see LICENSE).
//
// Copyright Evgeny Nadymov, 2013-present.
//
#define INTERACTIVE_NOTIFICATIONS
//#endif
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Windows.ApplicationModel.Resources;
using Windows.ApplicationModel.Resources.Core;
using Windows.Data.Xml.Dom;
using Windows.Storage;
using Windows.Storage.Search;
#if WNS_PUSH_SERVICE
using Windows.Networking.PushNotifications;
using Windows.UI.Notifications;
#endif
using Telegram.Api.Helpers;
using Telegram.Api.Services.Cache;
using Telegram.Api.TL;
namespace TelegramClient.Tasks
{
public static class PushUtils
{
#if WNS_PUSH_SERVICE
public static void UpdateToastAndTiles(RawNotification rawNotification)
{
var payload = rawNotification != null ? rawNotification.Content : null;
if (payload == null) return;
var rootObject = GetRootObject(payload);
if (rootObject == null) return;
if (rootObject.data == null) return;
if (rootObject.data.loc_key == null)
{
var groupname = GetGroup(rootObject.data);
RemoveToastGroup(groupname);
return;
}
var caption = GetCaption(rootObject.data);
var message = GetMessage(rootObject.data);
var sound = GetSound(rootObject.data);
var launch = GetLaunch(rootObject.data);
var tag = GetTag(rootObject.data);
var group = GetGroup(rootObject.data);
if (!IsMuted(rootObject.data) && !Notifications.IsDisabled)
{
AddToast(rootObject, caption, message, sound, launch, tag, group);
}
if (!IsServiceNotification(rootObject.data))
{
UpdateTile(caption, message);
}
UpdateBadge(rootObject.data.badge);
}
#endif
private static bool IsMuted(Data data)
{
return data.mute == "1";
}
private static bool IsServiceNotification(Data data)
{
return data.loc_key == "DC_UPDATE";
}
public static RootObject GetRootObject(string payload)
{
var serializer = new DataContractJsonSerializer(typeof(RootObject));
RootObject rootObject;
using (var stream = new MemoryStream(Encoding.Unicode.GetBytes(payload)))
{
rootObject = serializer.ReadObject(stream) as RootObject;
}
return rootObject;
}
private static string GetCaption(Data data)
{
var locKey = data.loc_key;
if (locKey == null)
{
return "locKey=null";
}
if (locKey.StartsWith("CHAT") || locKey.StartsWith("GEOCHAT"))
{
return data.loc_args[1];
}
if (locKey.StartsWith("MESSAGE"))
{
return data.loc_args[0];
}
if (locKey.StartsWith("CHANNEL"))
{
return data.loc_args[0];
}
if (locKey.StartsWith("PINNED"))
{
return data.loc_args[0];
}
if (locKey.StartsWith("AUTH")
|| locKey.StartsWith("CONTACT")
|| locKey.StartsWith("ENCRYPTED")
|| locKey.StartsWith("ENCRYPTION")
|| locKey.StartsWith("PHONE"))
{
return "Telegram";
}
#if DEBUG
return locKey;
#else
return "Telegram";
#endif
}
private static string GetSound(Data data)
{
return data.sound;
}
private static string GetGroup(Data data)
{
return data.group;
}
private static string GetTag(Data data)
{
return data.tag;
}
private static string GetLaunch(Data data)
{
var locKey = data.loc_key;
if (locKey == null) return null;
var path = "/Views/ShellView.xaml";
if (locKey == "DC_UPDATE")
{
path = "/Views/Additional/SettingsView.xaml";
}
var customParams = new List<string> {"Action=" + locKey};
if (data.custom != null)
{
customParams.AddRange(data.custom.GetParams());
}
return string.Format("{0}?{1}", path, string.Join("&", customParams));
}
private static string GetMessage(Data data)
{
var locKey = data.loc_key;
if (locKey == null)
{
Telegram.Logs.Log.Write("::PushNotificationsBackgroundTask locKey=null text=" + data.text);
return string.Empty;
}
string locValue;
var resourceLoader = ResourceLoader.GetForViewIndependentUse("TelegramClient.Tasks/Resources");
locValue = resourceLoader.GetString(locKey);
if (locValue != "")
{
return string.Format(locValue, data.loc_args).Replace("\r\n", "\n").Replace("\n", " ");
}
var builder = new StringBuilder();
if (data.loc_args != null)
{
builder.AppendLine("loc_args");
foreach (var locArg in data.loc_args)
{
builder.AppendLine(locArg);
}
}
Telegram.Logs.Log.Write(string.Format("::PushNotificationsBackgroundTask missing locKey={0} locArgs={1}", locKey, builder.ToString()));
//if (locKey.StartsWith("CHAT") || locKey.StartsWith("GEOCHAT"))
//{
// return data.text;
//}
//if (locKey.StartsWith("MESSAGE"))
//{
// if (locKey == "MESSAGE_TEXT")
// {
// return data.loc_args[1];
// }
// return data.text; //add localization string here
//}
#if DEBUG
return data.text;
#else
return string.Empty;
#endif
}
private static void UpdateBadge(int badgeNumber)
{
#if WNS_PUSH_SERVICE
var badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
if (badgeNumber == 0)
{
badgeUpdater.Clear();
return;
}
var badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
var badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
badgeElement.SetAttribute("value", badgeNumber.ToString());
try
{
badgeUpdater.Update(new BadgeNotification(badgeXml));
}
catch (Exception ex)
{
Telegram.Logs.Log.Write(ex.ToString());
}
#endif
}
private static async Task<bool> IsFileExists(string fileName)
{
bool fileExists = true;
Stream fileStream = null;
StorageFile file = null;
try
{
file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
fileStream = await file.OpenStreamForReadAsync();
fileStream.Dispose();
}
catch (FileNotFoundException)
{
// If the file dosn't exits it throws an exception, make fileExists false in this case
fileExists = false;
}
finally
{
if (fileStream != null)
{
fileStream.Dispose();
}
}
return fileExists;
}
public static void AddToast(RootObject rootObject, string caption, string message, string sound, string launch, string tag, string group)
{
#if WNS_PUSH_SERVICE
#if INTERACTIVE_NOTIFICATIONS
var toastNotifier = ToastNotificationManager.CreateToastNotifier();
Version version = null;
if (rootObject.data.system != null && rootObject.data.system != null)
{
Version.TryParse(rootObject.data.system, out version);
}
var toastXml = new XmlDocument();
if (version != null && version.Major >= 10)
{
string arguments;
string imageSource;
GetArgumentsAndImageSource(rootObject, out arguments, out imageSource);
var xml =
"<toast>" +
"<visual>" +
"<binding template=\"ToastImageAndText02\">" +
"<text id=\"1\"></text>" +
"<text id=\"2\"></text>" +
"<image id=\"1\" placement=\"appLogoOverride\" src=\"\" hint-crop=\"circle\" />" +
"</binding>" +
"</visual>" +
"</toast>";
//"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
//+ "<wp:Notification xmlns:wp=\"WPNotification\">"
//+ "<wp:Toast>"
//+ "<wp:Text1>Text1</wp:Text1>"
//+ "<wp:Text2>Text2</wp:Text2>"
//+ "<wp:Param>/Page1.xaml</wp:Param>"
//+ "</wp:Toast>"
//+ "</wp:Notification>";
toastXml.LoadXml(xml);
SetToastImage(toastXml, imageSource, arguments != null && arguments.StartsWith("from_id"));
SetActions(toastXml, arguments);
}
else
{
toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
}
SetText(toastXml, caption, message);
SetLaunch(toastXml, launch);
if (!string.IsNullOrEmpty(sound)
&& !string.Equals(sound, "default", StringComparison.OrdinalIgnoreCase))
{
SetSound(toastXml, sound);
}
try
{
var toast = new ToastNotification(toastXml);
if (tag != null) toast.Tag = tag;
if (group != null) toast.Group = group;
//RemoveToastGroup(group);
toastNotifier.Show(toast);
}
catch (Exception ex)
{
Telegram.Logs.Log.Write(ex.ToString());
}
#else
var toastNotifier = ToastNotificationManager.CreateToastNotifier();
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
SetText(toastXml, caption, message);
SetLaunch(toastXml, launch);
if (!string.IsNullOrEmpty(sound)
&& !string.Equals(sound, "default", StringComparison.OrdinalIgnoreCase))
{
SetSound(toastXml, sound);
}
try
{
var toast = new ToastNotification(toastXml);
if (tag != null) toast.Tag = tag;
if (group != null) toast.Group = group;
//RemoveToastGroup(group);
toastNotifier.Show(toast);
}
catch (Exception ex)
{
Telegram.Logs.Log.Write(ex.ToString());
}
#endif
#endif
}
private static void GetArgumentsAndImageSource(RootObject rootObject, out string arguments, out string imageSource)
{
arguments = null;
imageSource = null;
if (rootObject != null)
{
var data = rootObject.data;
if (data != null)
{
var custom = data.custom;
if (custom != null)
{
if (custom.from_id != null)
{
int fromId;
if (Int32.TryParse(custom.from_id, out fromId))
{
arguments = GetArguments("from_id", custom.from_id, true, custom);
}
}
else if (custom.chat_id != null)
{
int chatId;
if (Int32.TryParse(custom.chat_id, out chatId))
{
arguments = GetArguments("chat_id", custom.chat_id, false, custom);
}
}
else if (custom.channel_id != null)
{
int channelId;
if (Int32.TryParse(custom.channel_id, out channelId))
{
if (data.loc_key != null
&& data.loc_key.StartsWith("CHAT"))
{
arguments = GetArguments("channel_id", custom.channel_id, true, custom);
}
}
}
imageSource = GetImageSource(custom);
}
}
}
}
private static string GetImageSource(Custom custom)
{
string imageSource = null;
if (custom.mtpeer != null)
{
var location = custom.mtpeer.ph;
if (location != null)
{
var fileName = String.Format("{0}_{1}_{2}.jpg",
location.volume_id,
location.local_id,
location.secret);
if (IsFileExists(fileName).Result)
{
imageSource = fileName;
}
}
}
return imageSource;
}
private static string GetArguments(string peer, string peerId, bool needAccessHash, Custom custom)
{
string arguments = null;
if (custom.mtpeer != null && custom.mtpeer.ah != null || !needAccessHash)
{
arguments = string.Format("{0}={1}", peer, peerId);
if (custom.mtpeer != null && custom.mtpeer.ah != null)
{
arguments += string.Format(" access_hash={0}", custom.mtpeer.ah);
}
if (custom.msg_id != null)
{
arguments += string.Format(" msg_id={0}", custom.msg_id);
}
}
return arguments;
}
private static void RemoveToastGroup(string groupname)
{
#if WNS_PUSH_SERVICE
ToastNotificationManager.History.RemoveGroup(groupname);
#endif
}
private static void UpdateTile(string caption, string message)
{
#if WNS_PUSH_SERVICE
var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
//tileUpdater.EnableNotificationQueue(false);
tileUpdater.EnableNotificationQueue(true);
tileUpdater.EnableNotificationQueueForSquare150x150(false);
//tileUpdater.EnableNotificationQueueForWide310x150(true);
var wideTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150IconWithBadgeAndText);
SetImage(wideTileXml, "IconicSmall110.png");
SetText(wideTileXml, caption, message);
var squareTile150Xml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150IconWithBadge);
SetImage(squareTile150Xml, "IconicTileMedium202.png");
AppendTile(wideTileXml, squareTile150Xml);
var squareTile71Xml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare71x71IconWithBadge);
SetImage(squareTile71Xml, "IconicSmall110.png");
AppendTile(wideTileXml, squareTile71Xml);
try
{
tileUpdater.Update(new TileNotification(wideTileXml));
}
catch (Exception ex)
{
Telegram.Logs.Log.Write(ex.ToString());
}
#endif
}
private static void AppendTile(XmlDocument toTile, XmlDocument fromTile)
{
var fromTileNode = toTile.ImportNode(fromTile.GetElementsByTagName("binding").Item(0), true);
toTile.GetElementsByTagName("visual")[0].AppendChild(fromTileNode);
}
private static void SetText(XmlDocument document, string caption, string message)
{
var toastTextElements = document.GetElementsByTagName("text");
toastTextElements[0].InnerText = caption ?? string.Empty;
toastTextElements[1].InnerText = message ?? string.Empty;
}
private static void SetActions(XmlDocument document, string arguments)
{
if (arguments == null) return;
var resourceLoader = ResourceLoader.GetForViewIndependentUse("TelegramClient.Tasks/Resources");
//"<actions>" +
//"<input id=\"message\" type=\"text\" placeHolderContent=\"Type a reply\" />" +
//"<action activationType=\"background\" content=\"Reply\" arguments=\"{0}\" hint-inputId=\"message\" imageUri=\"Assets/Icons/send.png\"/>" +
//"</actions>"
var toastNode = document.SelectSingleNode("/toast");
var actionsElement = document.CreateElement("actions");
var inputElement = document.CreateElement("input");
inputElement.SetAttribute("id", "message");
inputElement.SetAttribute("type", "text");
inputElement.SetAttribute("placeHolderContent", resourceLoader.GetString("TypeReply"));
actionsElement.AppendChild(inputElement);
var replyAction = document.CreateElement("action");
replyAction.SetAttribute("activationType", "background");
replyAction.SetAttribute("content", resourceLoader.GetString("Reply"));
replyAction.SetAttribute("arguments", "action=reply " + arguments);
replyAction.SetAttribute("hint-inputId", "message");
replyAction.SetAttribute("imageUri", "Images/W10M/ic_send_2x.png");
actionsElement.AppendChild(replyAction);
var muteAction = document.CreateElement("action");
muteAction.SetAttribute("activationType", "background");
muteAction.SetAttribute("content", resourceLoader.GetString("Mute1Hour"));
muteAction.SetAttribute("arguments", "action=mute " + arguments);
actionsElement.AppendChild(muteAction);
var disableAction = document.CreateElement("action");
disableAction.SetAttribute("activationType", "background");
disableAction.SetAttribute("content", resourceLoader.GetString("Disable"));
disableAction.SetAttribute("arguments", "action=disable " + arguments);
actionsElement.AppendChild(disableAction);
toastNode.AppendChild(actionsElement);
}
private static void SetToastImage(XmlDocument document, string imageSource, bool isUserPlaceholder)
{
var imageElements = document.GetElementsByTagName("image");
if (imageSource == null)
{
((XmlElement)imageElements[0]).SetAttribute("src", isUserPlaceholder ? "ms-appx:///Images/W10M/user_placeholder.png" : "ms-appx:///Images/W10M/group_placeholder.png");
}
else
{
((XmlElement)imageElements[0]).SetAttribute("src", "ms-appdata:///local/" + imageSource);
}
}
private static void SetImage(XmlDocument document, string imageSource)
{
var imageElements = document.GetElementsByTagName("image");
((XmlElement)imageElements[0]).SetAttribute("src", imageSource);
}
private static void SetSound(XmlDocument document, string soundSource)
{
//return;
if (!Regex.IsMatch(soundSource, @"^sound[1-6]$", RegexOptions.IgnoreCase))
{
return;
}
var toastNode = document.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("duration", "long");
var audioElement = document.CreateElement("audio");
audioElement.SetAttribute("src", "ms-appx:///Sounds/" + soundSource + ".wav");
audioElement.SetAttribute("loop", "false");
toastNode.AppendChild(audioElement);
}
private static void SetLaunch(XmlDocument document, string launch)
{
if (string.IsNullOrEmpty(launch))
{
return;
}
if (PushNotificationsBackgroundTask.SystemVersion != null
&& PushNotificationsBackgroundTask.SystemVersion.StartsWith("10")) //10.0.10572.0 or less
{
try
{
var currentVersion = new Version(PushNotificationsBackgroundTask.SystemVersion);
var minVersion = new Version("10.0.10572.0");
if (currentVersion < minVersion)
{
return;
}
}
catch (Exception ex)
{
Telegram.Logs.Log.Write(ex.ToString());
}
}
//launch = "/Views/ShellView.xaml";
var toastNode = document.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("launch", launch);
}
//private static readonly Dictionary<string, string> _locKeys = new Dictionary<string, string>
//{
// {"MESSAGE_FWDS", "forwarded you {1} messages"},
// {"MESSAGE_TEXT", "{1}"},
// {"MESSAGE_NOTEXT", "sent you a message"},
// {"MESSAGE_PHOTO", "sent you a photo"},
// {"MESSAGE_VIDEO", "sent you a video"},
// {"MESSAGE_DOC", "sent you a document"},
// {"MESSAGE_GIF", "sent you a GIF"},
// {"MESSAGE_AUDIO", "sent you a voice message"},
// {"MESSAGE_CONTACT", "shared a contact with you"},
// {"MESSAGE_GEO", "sent you a map"},
// {"MESSAGE_STICKER", "sent you a sticker"},
// {"CHAT_MESSAGE_FWDS", "{0} forwarded {2} messages to the group"},
// {"CHAT_MESSAGE_TEXT", "{0}: {2}"},
// {"CHAT_MESSAGE_NOTEXT", "{0} sent a message to the group"},
// {"CHAT_MESSAGE_PHOTO", "{0} sent a photo to the group"},
// {"CHAT_MESSAGE_VIDEO", "{0} sent a video to the group"},
// {"CHAT_MESSAGE_DOC", "{0} sent a document to the group"},
// {"CHAT_MESSAGE_GIF", "{0} sent a GIF to the group"},
// {"CHAT_MESSAGE_AUDIO", "{0} sent a voice message to the group"},
// {"CHAT_MESSAGE_CONTACT", "{0} shared a contact in the group"},
// {"CHAT_MESSAGE_GEO", "{0} sent a map to the group"},
// {"CHAT_MESSAGE_STICKER", "{0} sent a sticker to the group"},
// {"CHANNEL_MESSAGE_FWDS", "posted {1} forwarded messages"},
// {"CHANNEL_MESSAGE_TEXT", "{1}"},
// {"CHANNEL_MESSAGE_NOTEXT", "posted a message"},
// {"CHANNEL_MESSAGE_PHOTO", "posted a photo"},
// {"CHANNEL_MESSAGE_VIDEO", "posted a video"},
// {"CHANNEL_MESSAGE_DOC", "posted a document"},
// {"CHANNEL_MESSAGE_GIF", "posted a GIF"},
// {"CHANNEL_MESSAGE_AUDIO", "posted a voice message"},
// {"CHANNEL_MESSAGE_CONTACT", "posted a contact"},
// {"CHANNEL_MESSAGE_GEO", "posted a map"},
// {"CHANNEL_MESSAGE_STICKER", "posted a sticker"},
// {"CHAT_CREATED", "{0} invited you to the group"},
// {"CHAT_TITLE_EDITED", "{0} edited the group's name"},
// {"CHAT_PHOTO_EDITED", "{0} edited the group's photo"},
// {"CHAT_ADD_MEMBER", "{0} invited {2} to the group"},
// {"CHAT_ADD_YOU", "{0} invited you to the group"},
// {"CHAT_DELETE_MEMBER", "{0} kicked {2} from the group"},
// {"CHAT_DELETE_YOU", "{0} kicked you from the group"},
// {"CHAT_LEFT", "{0} has left the group"},
// {"CHAT_RETURNED", "{0} has returned to the group"},
// {"GEOCHAT_CHECKIN", "{0} has checked-in"},
// {"CHAT_JOINED", "{0} has joined the group"},
// {"CONTACT_JOINED", "{0} joined the App!"},
// {"AUTH_UNKNOWN", "New login from unrecognized device {0}"},
// {"AUTH_REGION", "New login from unrecognized device {0}, location: {1}"},
// {"CONTACT_PHOTO", "updated profile photo"},
// {"ENCRYPTION_REQUEST", "You have a new message"},
// {"ENCRYPTION_ACCEPT", "You have a new message"},
// {"ENCRYPTED_MESSAGE", "You have a new message"},
// {"DC_UPDATE", "Open this notification to update app settings"},
// {"LOCKED_MESSAGE", "You have a new message"}
//};
}
public sealed class Photo
{
public string volume_id { get; set; }
public string local_id { get; set; }
public string secret { get; set; }
public int dc_id { get; set; }
}
public sealed class MTPeer
{
public string ah { get; set; }
public Photo ph { get; set; }
}
public sealed class Custom
{
public string msg_id { get; set; }
public string from_id { get; set; }
public string chat_id { get; set; }
public string channel_id { get; set; }
public MTPeer mtpeer { get; set; }
public string call_id { get; set; }
public string call_ah { get; set; }
public string group
{
get
{
if (chat_id != null) return "c" + chat_id;
if (channel_id != null) return "c" + chat_id;
if (from_id != null) return "u" + from_id;
return null;
}
}
public string tag { get { return msg_id; } }
public IEnumerable<string> GetParams()
{
if (msg_id != null) yield return "msg_id=" + msg_id;
if (from_id != null) yield return "from_id=" + from_id;
if (chat_id != null) yield return "chat_id=" + chat_id;
if (channel_id != null) yield return "channel_id=" + channel_id;
}
}
public sealed class Data
{
public Custom custom { get; set; }
public string sound { get; set; }
public string mute { get; set; }
public int badge { get; set; }
public string loc_key { get; set; }
public string[] loc_args { get; set; }
public int random_id { get; set; }
public int user_id { get; set; }
public string text { get; set; }
public string system { get; set; }
public string group { get { return custom != null ? custom.group : null; } }
public string tag { get { return custom != null ? custom.tag : null; } }
}
public sealed class RootObject
{
public int date { get; set; }
public Data data { get; set; }
}
}