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

Commit 0ecfe07

Browse files
authored
Merge pull request #138 from Unabashed-Development/development
Some final bug fixes!
2 parents d5fc844 + e4444b4 commit 0ecfe07

File tree

10 files changed

+76
-47
lines changed

10 files changed

+76
-47
lines changed

Gateway/Helpers/FiddleHelper.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ namespace Gateway
55
public static class FiddleHelper
66
{
77
/// <summary>
8-
/// Assigns the right connection name to the connection string.
8+
/// Assigns the right connection name to the connection string using the randomized port.
99
/// </summary>
1010
/// <param name="name">The name of the connection.</param>
1111
/// <returns>A string of the ConfigurationManager.</returns>
12-
public static string GetConnectionStringSql(string name) => ConfigurationManager.ConnectionStrings[name].ConnectionString;
12+
public static string GetConnectionStringSql(string name)
13+
{
14+
string connectionString = ConfigurationManager.ConnectionStrings[name].ConnectionString;
15+
int indexOfServer = connectionString.IndexOf(';');
16+
return connectionString.Insert(indexOfServer, ',' + SSHService.SshPort.ToString());
17+
}
1318
}
1419
}

Gateway/ProfileDataAccess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static Profile LoadProfile(int id)
8080
MoralsData moralsData = LoadMoralsData(id);
8181
studentData.MoralsData = moralsData;
8282
studentData.UserMedia = new System.Collections.ObjectModel.ObservableCollection<Uri>(MediaDataAccess.GetUserMediaUris(id));
83-
studentData.FirstUserMedia = studentData.UserMedia?.FirstOrDefault();
83+
studentData.FirstUserMedia = studentData.UserMedia?.DefaultIfEmpty(new Uri("http://www.stugether.wafoe.nl/media/blank_profile_stugether.png")).First();
8484
studentData.MatchRelationType = LoadRelationshipTypeMatch(studentData.UserID);
8585
return studentData;
8686
}

Gateway/Services/SSHService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ private static Tuple<SshClient, uint> ConnectSsh(string sshHostName, string sshU
7070
sshClient.Connect();
7171

7272
// Forward a local port to the database server and port, using the SSH server
73-
//ForwardedPortLocal forwardedPort = new ForwardedPortLocal("127.0.0.1", databaseServer, (uint)databasePort); // Uses a random port
74-
ForwardedPortLocal forwardedPort = new ForwardedPortLocal("127.0.0.1", (uint)databasePort, databaseServer, (uint)databasePort); // Makes port same as database port
73+
ForwardedPortLocal forwardedPort = new ForwardedPortLocal("127.0.0.1", databaseServer, (uint)databasePort); // Uses a random port
7574
sshClient.AddForwardedPort(forwardedPort);
7675
forwardedPort.Start();
7776

View/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
mc:Ignorable="d"
1313
WindowStartupLocation="CenterScreen"
1414
Style="{StaticResource {x:Type Window}}"
15-
Title="Stugether" Height="450" Width="800">
15+
Title="Stugether" Height="563" Width="1000">
1616
<Window.DataContext>
1717
<vm:MainPageViewModel/>
1818
</Window.DataContext>

View/OverviewMatches.xaml.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ public OverviewMatches()
2121
/// </summary>
2222
private void Profile_Click(object sender, RoutedEventArgs e)
2323
{
24-
Profile profile = ((Button)sender).DataContext as Profile;
25-
if (!FocusOpenedWindow<ProfileWindow>(profile))
24+
if (((Button)sender).DataContext is Profile profile && !FocusOpenedWindow<ProfileWindow>(profile))
2625
{
2726
ProfileWindow profileWindow = new ProfileWindow();
2827
profileWindow.ProfileWindowFrame.Content = new ProfilePage(new ProfilePageViewModel(profile));
2928

30-
profileWindow.Show(); // Show the authentication window
29+
profileWindow.Show();
3130
}
3231
}
3332

@@ -39,13 +38,12 @@ private void MatchingProfile_Click(object sender, RoutedEventArgs e)
3938
ProfileWindow profileWindow = new ProfileWindow();
4039
profileWindow.ProfileWindowFrame.Content = new MatchingProfilePage(new MatchingProfilePageViewModel(((Button)sender).DataContext as Profile));
4140

42-
profileWindow.Show(); // Show the authentication window
41+
profileWindow.Show();
4342
}
4443

4544
private void Chat_Click(object sender, RoutedEventArgs e)
4645
{
47-
Profile profile = ((Button)sender).DataContext as Profile;
48-
if (!FocusOpenedWindow<ChatWindow>(profile))
46+
if (((Button)sender).DataContext is Profile profile && !FocusOpenedWindow<ChatWindow>(profile))
4947
{
5048
ChatWindow chatWindow = new ChatWindow
5149
{
@@ -72,10 +70,10 @@ public static void Chat_Base(ChatWindow chatWindow)
7270
public static bool FocusOpenedWindow<T>(int userID) where T : Window
7371
{
7472
bool success = false;
75-
System.Windows.Application.Current.Dispatcher.Invoke(delegate // Dispatcher delegate for threads
73+
Application.Current.Dispatcher.Invoke(delegate // Dispatcher delegate for threads
7674
{
7775
// Check if a window is already open for the user, and if so, focus it instead of opening a new window
78-
foreach (T t in System.Windows.Application.Current.Windows.OfType<T>())
76+
foreach (T t in Application.Current.Windows.OfType<T>())
7977
{
8078
if (typeof(T) == typeof(ChatWindow))
8179
{

View/View.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
<UseWindowsForms>true</UseWindowsForms>
88
<ApplicationIcon>stugether_logo.ico</ApplicationIcon>
99
<AssemblyName>Stugether</AssemblyName>
10-
<Version>1.0.1</Version>
10+
<Version>1.0.2</Version>
1111
<Authors>Unabashed Development</Authors>
1212
<Company>Unabashed Development</Company>
1313
<Description>Your student matching application!</Description>
1414
<Copyright>Unabashed Development</Copyright>
1515
<PackageProjectUrl></PackageProjectUrl>
1616
<RepositoryUrl>https://github.com/Unabashed-Development/Stugether</RepositoryUrl>
17+
<AssemblyVersion>1.0.2.0</AssemblyVersion>
1718
</PropertyGroup>
1819

1920
<ItemGroup>

ViewModel/Authentication/HomePageAfterLoginViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ private void Logout()
1616
{
1717
Account.Email = null;
1818
Account.UserID = null;
19+
Account.NotifiedChatMessages = null;
1920
ViewModelMediators.Authenticated = false;
2021
}
2122

ViewModel/ChatWindowViewModel.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading;
88
using System.Windows.Input;
99
using ViewModel.Commands;
10+
using ViewModel.Mediators;
1011

1112
namespace ViewModel
1213
{
@@ -175,18 +176,21 @@ public void SeenChatMessages()
175176
}
176177
}
177178

178-
public bool ChatWindowHasFocus { internal get; set; }
179-
#endregion
180-
181-
#region Construction and destruction
182-
/// <summary>
183-
/// Creates an empty conversation
184-
/// </summary>
185-
public ChatWindowViewModel()
179+
public bool ChatWindowHasFocus
186180
{
187-
181+
get
182+
{
183+
if (!ViewModelMediators.ChatWindowFocus.ContainsKey(Receiver.UserID))
184+
{
185+
ViewModelMediators.ChatWindowFocus.Add(Receiver.UserID, true);
186+
}
187+
return ViewModelMediators.ChatWindowFocus[Receiver.UserID];
188+
}
189+
set => ViewModelMediators.ChatWindowFocus[Receiver.UserID] = value;
188190
}
191+
#endregion
189192

193+
#region Construction and destruction
190194
/// <summary>
191195
/// Creates a conversationViewModel with given userId
192196
/// </summary>
@@ -207,10 +211,11 @@ public ChatWindowViewModel(Profile otherUser)
207211
}
208212

209213
/// <summary>
210-
/// Destructs ChatWindowViewModel, and so stops the background timer for updating chats
214+
/// Destructs ChatWindowViewModel, and so stops the background timer for updating chats and cleans up ChatWindowFocus
211215
/// </summary>
212216
~ChatWindowViewModel()
213217
{
218+
ViewModelMediators.ChatWindowFocus.Remove(Receiver.UserID);
214219
Account.BackgroundThreads[backgroundThreadName].Dispose();
215220
Account.BackgroundThreads.Remove(backgroundThreadName);
216221
}

ViewModel/Helpers/NotificationHelper.cs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,20 @@ private static void MatchOrLikeNotification(object matchOrLike)
9393
List<Profile> profileList;
9494

9595
// Prepares data depending on the match or like handling
96-
if ((MatchOrLike)matchOrLike == MatchOrLike.Matched)
96+
if ((MatchOrLike)matchOrLike == MatchOrLike.Matched && Account.UserID != null)
9797
{
9898
current = new HashSet<int>(MatchDataAccess.GetAllMatchesFromUser(Account.UserID.Value, MatchOrLike.Matched));
9999
profileList = ViewModelMediators.Matches;
100100
}
101-
else
101+
else if ((MatchOrLike)matchOrLike == MatchOrLike.Liked && Account.UserID != null)
102102
{
103103
current = new HashSet<int>(MatchDataAccess.GetReceivedLikesFromUser(Account.UserID.Value));
104104
profileList = ViewModelMediators.Likes;
105105
}
106+
else
107+
{
108+
throw new Exception("Match or like notification MatchOrLike enum not set correctly");
109+
}
106110

107111
// Add the user ID's to the HashSet
108112
foreach (Profile p in profileList)
@@ -116,17 +120,29 @@ private static void MatchOrLikeNotification(object matchOrLike)
116120
// If the amounts are different OR there is at least 1 new user...
117121
if (current.Count != previous.Count || current.Count > 0)
118122
{
119-
bool notificationsOn;
123+
bool notificationsOn = false;
120124
// ...reload the profiles
121125
if ((MatchOrLike)matchOrLike == MatchOrLike.Matched)
122126
{
123-
ViewModelMediators.Matches = MatchHelper.LoadProfilesOfMatches(Account.UserID.Value);
124-
notificationsOn = Account.NotificationSettings.Matches;
127+
if (Account.UserID != null)
128+
{
129+
ViewModelMediators.Matches = MatchHelper.LoadProfilesOfMatches(Account.UserID.Value);
130+
}
131+
if (Account.NotificationSettings != null)
132+
{
133+
notificationsOn = Account.NotificationSettings.Matches;
134+
}
125135
}
126136
else
127137
{
128-
ViewModelMediators.Likes = MatchHelper.LoadProfilesOfLikes(Account.UserID.Value);
129-
notificationsOn = Account.NotificationSettings.Likes;
138+
if (Account.UserID != null)
139+
{
140+
ViewModelMediators.Likes = MatchHelper.LoadProfilesOfLikes(Account.UserID.Value);
141+
}
142+
if (Account.NotificationSettings != null)
143+
{
144+
notificationsOn = Account.NotificationSettings.Likes;
145+
}
130146
}
131147

132148
// If the current amount are more (so there is a new user instead of an user who removed you) and notifications are turned on...
@@ -172,30 +188,32 @@ private static void ChatNotifications(object state)
172188
unreadChatMessages.Add(c);
173189
}
174190
}
191+
Account.NotifiedChatMessages = newChatMessages; // Set the NotifiedChatMessages to the newly obtained chat messages list
175192

176193
// Reload the profiles of matches if there have been new unread chat messages (for chat notification indicator)
177194
if (unreadChatMessages.Count > 0)
178195
{
179196
ViewModelMediators.Matches = MatchHelper.LoadProfilesOfMatches(Account.UserID.Value);
180-
}
181197

182-
// Throw notifications for every new chat message if notifications are on
183-
if (Account.NotificationSettings.Chat)
184-
{
185-
foreach (ChatMessage c in unreadChatMessages)
198+
// Throw notifications for every new chat message if notifications are on
199+
if (Account.NotificationSettings != null && Account.NotificationSettings.Chat)
186200
{
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;
201+
foreach (ChatMessage c in unreadChatMessages)
202+
{
203+
bool dictionaryContainsUser = ViewModelMediators.ChatWindowFocus.ContainsKey(c.FromUserId);
204+
if ((dictionaryContainsUser && !ViewModelMediators.ChatWindowFocus[c.FromUserId]) || !dictionaryContainsUser)
205+
{
206+
Profile chatProfile = Account.Matches.FirstOrDefault(p => p.UserID == c.FromUserId);
207+
ThrowChatMessageNotification(chatProfile.FirstName,
208+
chatProfile.LastName,
209+
chatProfile.FirstUserMedia,
210+
c.Content,
211+
chatProfile.UserID);
212+
}
213+
c.Seen = true;
214+
}
194215
}
195216
}
196-
197-
// Set the NotifiedChatMessages to the newly obtained chat messages list
198-
Account.NotifiedChatMessages = newChatMessages;
199217
}
200218
}
201219
#endregion

ViewModel/Mediators/ViewModelMediators.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public static List<Profile> Likes
5757
LikesChanged?.Invoke();
5858
}
5959
}
60+
61+
public static Dictionary<int, bool> ChatWindowFocus { get; set; } = new Dictionary<int, bool>();
6062
#endregion
6163
}
6264
}

0 commit comments

Comments
 (0)