Esempio n. 1
0
        public static void OnMessageReceived(object sender, PushReceivedEventArgs args)
        {
            var notificationContent = args.NotificationContent;
            var igAction            = notificationContent.IgAction;
            var querySeparatorIndex = igAction.IndexOf('?');
            var targetType          = igAction.Substring(0, querySeparatorIndex);
            var queryParams         = HttpUtility.ParseQueryString(igAction.Substring(querySeparatorIndex));
            var threadId            = queryParams["id"];
            var itemId       = queryParams["x"];
            var toastContent = new ToastContent()
            {
                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = notificationContent.Message
                            }
                        },
                        AppLogoOverride = string.IsNullOrEmpty(args.NotificationContent.OptionalAvatarUrl)
                            ? null
                            : new ToastGenericAppLogo()
                        {
                            Source        = args.NotificationContent.OptionalAvatarUrl,
                            HintCrop      = ToastGenericAppLogoCrop.Circle,
                            AlternateText = "Profile picture"
                        }
                    }
                }
            };

            // Create the toast notification
            var toast = new ToastNotification(toastContent.GetXml())
            {
                Group           = threadId,
                Tag             = itemId,
                ExpiresOnReboot = false
            };

            // And send the notification
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
Esempio n. 2
0
 static void PushClientMessageReceived(object sender, PushReceivedEventArgs e)
 {
     //if (MainView.Current != null)
     //    if (MainView.Current.DebugText != null)
     //        MainView.Current.DebugText.Text += "NOTIFY RECEIVED :>   " + JsonConvert.SerializeObject(e) + Environment.NewLine;
     System.Diagnostics.Debug.WriteLine(e?.Json);
     if (NavigationService.IsDirect())
     {
         try
         {
             if (sender is IInstaApi api && Helper.CurrentUser.Pk == api.GetLoggedUser().LoggedInUser.Pk)
             {
                 if (!e.CollapseKey.Contains("direct"))
                 {
                     PushHelper.HandleNotify(e.NotificationContent, Helper.InstaApiList);
                 }
             }
             else
             {
                 PushHelper.HandleNotify(e.NotificationContent, Helper.InstaApiList);
             }
         }
Esempio n. 3
0
 static void PushClientMessageReceived(object sender, PushReceivedEventArgs e)
 {
     System.Diagnostics.Debug.WriteLine(e?.Json);
     if (e != null)
     {
         System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(ToPn2(e.NotificationContent)));
     }
     if (NavigationService.IsDirect())
     {
         try
         {
             if (sender is IInstaApi api && Helper.CurrentUser.Pk == api.GetLoggedUser().LoggedInUser.Pk)
             {
                 if (!e.CollapseKey.Contains("direct"))
                 {
                     PushHelper.HandleNotify(e.NotificationContent, Helper.InstaApiList);
                 }
             }
             else
             {
                 PushHelper.HandleNotify(e.NotificationContent, Helper.InstaApiList);
             }
         }
Esempio n. 4
0
 public static void OnMessageReceived(object sender, PushReceivedEventArgs e)
 {
     PushHelper.HandleNotify(e.NotificationContent, InstaApiList);
 }
Esempio n. 5
0
        public static void OnMessageReceived(object sender, PushReceivedEventArgs args)
        {
            var notificationContent = args.NotificationContent;
            var igAction            = notificationContent.IgAction;
            var querySeparatorIndex = igAction.IndexOf('?');
            var targetType          = igAction.Substring(0, querySeparatorIndex);
            var queryParams         = HttpUtility.ParseQueryString(igAction.Substring(querySeparatorIndex));
            var threadId            = queryParams["id"];
            var itemId      = queryParams["x"];
            var threadTitle = GetThreadTitleFromAppSettings(threadId);

            if (string.IsNullOrEmpty(threadTitle))
            {
                threadTitle = notificationContent.Message.Substring(0, notificationContent.Message.IndexOf(' '));
            }
            var toastContent = new ToastContent
            {
                Header = new ToastHeader(threadId, threadTitle, string.Empty),
                Visual = new ToastVisual
                {
                    BindingGeneric = new ToastBindingGeneric
                    {
                        Children =
                        {
                            new AdaptiveText
                            {
                                Text = notificationContent.Message
                            }
                        },
                        HeroImage = string.IsNullOrEmpty(notificationContent.OptionalImage)
                            ? null
                            : new ToastGenericHeroImage
                        {
                            Source = notificationContent.OptionalImage
                        },
                        AppLogoOverride = string.IsNullOrEmpty(args.NotificationContent.OptionalAvatarUrl)
                            ? null
                            : new ToastGenericAppLogo
                        {
                            Source        = args.NotificationContent.OptionalAvatarUrl,
                            HintCrop      = ToastGenericAppLogoCrop.Circle,
                            AlternateText = "Profile picture"
                        }
                    }
                },
                Launch = $"action=openThread&threadId={threadId}"
            };

            // Create the toast notification
            var toast = new ToastNotification(toastContent.GetXml())
            {
                Group           = threadId,
                Tag             = itemId,
                ExpiresOnReboot = false
            };

            if (ApiInformation.IsPropertyPresent("Windows.UI.Notifications.ToastNotification", "RemoteId"))
            {
                toast.RemoteId = notificationContent.PushId;
            }

            QueueRapidToast(toast);
        }