Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

Commit ca7863a

Browse files
authored
Merge pull request #126 from Standaard-boos/Notifications
Bug fixes
2 parents 184e49f + 6451f54 commit ca7863a

5 files changed

Lines changed: 76 additions & 25 deletions

File tree

View/MainWindow.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public MainWindow()
4040

4141
// Subscribe for the opening of a chat window once a chat notification is clicked
4242
ToastNotificationManagerCompat.OnActivated += Chat_Notification;
43+
44+
// Clear all windows once the authentication has finished
45+
ViewModelMediators.AuthenticationStateChanged += CloseOpenProfileAndChatWindows;
4346
}
4447

4548
protected override void OnStateChanged(EventArgs e)
@@ -95,5 +98,19 @@ private void Chat_Notification(ToastNotificationActivatedEventArgsCompat toastAr
9598
}
9699
}
97100
}
101+
102+
/// <summary>
103+
/// Closes all open chat and profile windows.
104+
/// </summary>
105+
private void CloseOpenProfileAndChatWindows()
106+
{
107+
foreach (Window w in System.Windows.Application.Current.Windows)
108+
{
109+
if (w.GetType() == typeof(ChatWindow) || w.GetType() == typeof(ProfileWindow))
110+
{
111+
w.Close();
112+
}
113+
}
114+
}
98115
}
99116
}

View/ServerError.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Page x:Class="View.ServerError"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
mc:Ignorable="d"
7+
Title="Fout">
8+
9+
<Grid>
10+
<Label Content="Er ging iets mis met de verbinding met de server. Neem contact op met de administrators van Stugether." HorizontalAlignment="Center" VerticalAlignment="Center"/>
11+
</Grid>
12+
</Page>

View/ServerError.xaml.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Windows.Controls;
2+
3+
namespace View
4+
{
5+
/// <summary>
6+
/// Interaction logic for ServerError.xaml
7+
/// </summary>
8+
public partial class ServerError : Page
9+
{
10+
public ServerError()
11+
{
12+
InitializeComponent();
13+
}
14+
}
15+
}

ViewModel/Helpers/NotificationHelper.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,9 @@ public static void SetAllNotificationTimers(bool set, bool reRun)
5353
}
5454
if (set)
5555
{
56-
if (Account.NotificationSettings.Matches)
57-
{
58-
Account.BackgroundThreads[keyArray[0]] = new Timer(MatchOrLikeNotification, MatchOrLike.Matched, 0, 5000);
59-
}
60-
if (Account.NotificationSettings.Likes)
61-
{
62-
Account.BackgroundThreads[keyArray[1]] = new Timer(MatchOrLikeNotification, MatchOrLike.Liked, 0, 5000);
63-
}
64-
if (Account.NotificationSettings.Chat)
65-
{
66-
Account.BackgroundThreads[keyArray[2]] = new Timer(ChatNotifications, null, 0, 1000);
67-
}
56+
Account.BackgroundThreads[keyArray[0]] = new Timer(MatchOrLikeNotification, MatchOrLike.Matched, 0, 5000);
57+
Account.BackgroundThreads[keyArray[1]] = new Timer(MatchOrLikeNotification, MatchOrLike.Liked, 0, 5000);
58+
Account.BackgroundThreads[keyArray[2]] = new Timer(ChatNotifications, null, 0, 1000);
6859
}
6960
}
7061

@@ -125,18 +116,21 @@ private static void MatchOrLikeNotification(object matchOrLike)
125116
// If the amounts are different OR there is at least 1 new user...
126117
if (current.Count != previous.Count || current.Count > 0)
127118
{
119+
bool notificationsOn;
128120
// ...reload the profiles
129121
if ((MatchOrLike)matchOrLike == MatchOrLike.Matched)
130122
{
131123
ViewModelMediators.Matches = MatchHelper.LoadProfilesOfMatches(Account.UserID.Value);
124+
notificationsOn = Account.NotificationSettings.Matches;
132125
}
133126
else
134127
{
135128
ViewModelMediators.Likes = MatchHelper.LoadProfilesOfLikes(Account.UserID.Value);
129+
notificationsOn = Account.NotificationSettings.Likes;
136130
}
137131

138-
// If the current amount are more (so there is a new user instead of an user who removed you)...
139-
if (current.Count > 0)
132+
// If the current amount are more (so there is a new user instead of an user who removed you) and notifications are turned on...
133+
if (notificationsOn && current.Count > 0)
140134
{
141135
// Throw new notification with amount of new matches or likes
142136
ThrowMatchOrLikeNotification((MatchOrLike)matchOrLike, current.Count);
@@ -185,18 +179,22 @@ private static void ChatNotifications(object state)
185179
ViewModelMediators.Matches = MatchHelper.LoadProfilesOfMatches(Account.UserID.Value);
186180
}
187181

188-
// Throw notifications for every new chat message
189-
foreach (ChatMessage c in unreadChatMessages)
182+
// Throw notifications for every new chat message if notifications are on
183+
if (Account.NotificationSettings.Chat)
190184
{
191-
Profile chatProfile = Account.Matches.FirstOrDefault(p => p.UserID == c.FromUserId);
192-
ThrowChatMessageNotification(chatProfile.FirstName,
193-
chatProfile.LastName,
194-
chatProfile.FirstUserMedia,
195-
c.Content,
196-
chatProfile.UserID);
197-
c.Seen = true;
185+
foreach (ChatMessage c in unreadChatMessages)
186+
{
187+
Profile chatProfile = Account.Matches.FirstOrDefault(p => p.UserID == c.FromUserId);
188+
ThrowChatMessageNotification(chatProfile.FirstName,
189+
chatProfile.LastName,
190+
chatProfile.FirstUserMedia,
191+
c.Content,
192+
chatProfile.UserID);
193+
c.Seen = true;
194+
}
198195
}
199196

197+
// Set the NotifiedChatMessages to the newly obtained chat messages list
200198
Account.NotifiedChatMessages = newChatMessages;
201199
}
202200
}

ViewModel/MainPageViewModel.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@ public class MainPageViewModel : ObservableObject
2525
/// </summary>
2626
public MainPageViewModel()
2727
{
28-
SSHService.Initialize(); // Initialize SSH for the database connection and logging in
29-
MainNavigationItems = SetObservableCollection(false); // Initialize the default page list
28+
// Initialize the default page list
29+
MainNavigationItems = SetObservableCollection(false);
30+
31+
try
32+
{
33+
SSHService.Initialize(); // Initialize SSH for the database connection and logging in
34+
}
35+
catch (Exception)
36+
{
37+
MainWindowPage = "ServerError.xaml";
38+
}
3039

3140
// Subscribe a bunch of events to make certain other functions work
3241
ViewModelMediators.AuthenticationStateChanged += OnAuthenticationStateChanged;

0 commit comments

Comments
 (0)