diff --git a/Chiota/Chiota.Android/Services/NotificationsTask.cs b/Chiota/Chiota.Android/Services/NotificationsTask.cs index a0cb9ea..6b87670 100644 --- a/Chiota/Chiota.Android/Services/NotificationsTask.cs +++ b/Chiota/Chiota.Android/Services/NotificationsTask.cs @@ -35,22 +35,31 @@ private async Task LookForNewNotifications() var contactApprovedList = await user.TangleMessenger.GetJsonMessageAsync>(user.ApprovedAddress); // currently no messages for contact request due to perfomance issues + // show only one new message + var contactNotificationId = 0; foreach (var contact in contactApprovedList.Where(c => !c.Data.Rejected)) { var encryptedMessages = await user.TangleMessenger.GetMessagesAsync(contact.Data.ChatAdress); - foreach (var unused in encryptedMessages.Where(c => !c.Stored)) + // don't send a reminder for every new message + if (encryptedMessages.Any(c => !c.Stored)) { + var intent = Application.Context.PackageManager.GetLaunchIntentForPackage(Application.Context.PackageName); + intent.AddFlags(ActivityFlags.ClearTop); + var pendingIntent = PendingIntent.GetActivity(Application.Context, 0, intent, PendingIntentFlags.UpdateCurrent); var builder = new NotificationCompat.Builder(Application.Context) .SetAutoCancel(true) // Dismiss from the notif. area when clicked + .SetContentIntent(pendingIntent) .SetContentTitle(contact.Data.Name) // Set its title .SetContentText("New Message from " + contact.Data.Name) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) .SetSmallIcon(Resource.Drawable.reminder); var notification = builder.Build(); var notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager; - notificationManager?.Notify(0, notification); + notificationManager?.Notify(contactNotificationId, notification); } + + contactNotificationId++; } } } diff --git a/Chiota/Chiota/IOTAServices/RepositoryFactory.cs b/Chiota/Chiota/IOTAServices/RepositoryFactory.cs index 28c82bb..be70a7b 100644 --- a/Chiota/Chiota/IOTAServices/RepositoryFactory.cs +++ b/Chiota/Chiota/IOTAServices/RepositoryFactory.cs @@ -1,6 +1,8 @@ namespace Chiota.IOTAServices { + using System; using System.Collections.Generic; + using System.Threading.Tasks; using RestSharp; @@ -51,8 +53,15 @@ private static bool NoteIsHealthy(IIotaNodeRepository node) { try { - var nodeInfo = node.GetNodeInfo(); - return nodeInfo.LatestMilestoneIndex == nodeInfo.LatestSolidSubtangleMilestoneIndex; + // Timeout after 5 seconds + var task = Task.Run(() => node.GetNodeInfo()); + if (task.Wait(TimeSpan.FromSeconds(5))) + { + var nodeInfo = task.Result; + return nodeInfo.LatestMilestoneIndex == nodeInfo.LatestSolidSubtangleMilestoneIndex; + } + + return false; } catch { diff --git a/Chiota/Chiota/ViewModels/ChatViewModel.cs b/Chiota/Chiota/ViewModels/ChatViewModel.cs index 4085165..13900c9 100644 --- a/Chiota/Chiota/ViewModels/ChatViewModel.cs +++ b/Chiota/Chiota/ViewModels/ChatViewModel.cs @@ -46,7 +46,6 @@ public ChatViewModel(ListView messagesListView, Contact contact, User user) this.user = user; this.contact = contact; this.messagesListView = messagesListView; - this.PageIsShown = true; this.OutGoingText = null; // reset hash short storage, because it's different for every chat @@ -81,7 +80,7 @@ public ObservableCollection Messages public async void OnAppearing() { - // cancel if there is no interent + this.PageIsShown = true; this.contact.PublicNtruKey = await this.GetContactPublicKey(); if (this.contact.PublicNtruKey == null) { diff --git a/Chiota/Chiota/Views/ChatPage.xaml.cs b/Chiota/Chiota/Views/ChatPage.xaml.cs index 377d9e5..2d7857b 100644 --- a/Chiota/Chiota/Views/ChatPage.xaml.cs +++ b/Chiota/Chiota/Views/ChatPage.xaml.cs @@ -14,7 +14,7 @@ [XamlCompilation(XamlCompilationOptions.Compile)] public partial class ChatPage : ContentPage { - private ChatViewModel vm; + private readonly ChatViewModel vm; public ChatPage(Contact contact, User user) { @@ -34,15 +34,14 @@ public ChatPage(Contact contact, User user) protected override void OnAppearing() { - this.vm.OnAppearing(); + this.vm?.OnAppearing(); base.OnAppearing(); } protected override void OnDisappearing() { this.vm.PageIsShown = false; - this.vm = null; - this.Navigation.PopAsync(); + base.OnDisappearing(); } private void OnTextChanged(object sender, EventArgs e) diff --git a/Chiota/Chiota/Views/ContactPage.xaml b/Chiota/Chiota/Views/ContactPage.xaml index 8ed9467..adb53c9 100644 --- a/Chiota/Chiota/Views/ContactPage.xaml +++ b/Chiota/Chiota/Views/ContactPage.xaml @@ -15,7 +15,7 @@ - +