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

Commit 7f6e1dc

Browse files
authored
Merge pull request #134 from Unabashed-Development/bugfixing
Bugfixing
2 parents 68d7e59 + 897701a commit 7f6e1dc

8 files changed

Lines changed: 58 additions & 42 deletions

File tree

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
{

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: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,23 @@ private static void MatchOrLikeNotification(object matchOrLike)
116116
// If the amounts are different OR there is at least 1 new user...
117117
if (current.Count != previous.Count || current.Count > 0)
118118
{
119-
bool notificationsOn;
119+
bool notificationsOn = false;
120120
// ...reload the profiles
121121
if ((MatchOrLike)matchOrLike == MatchOrLike.Matched)
122122
{
123123
ViewModelMediators.Matches = MatchHelper.LoadProfilesOfMatches(Account.UserID.Value);
124-
notificationsOn = Account.NotificationSettings.Matches;
124+
if (Account.NotificationSettings != null)
125+
{
126+
notificationsOn = Account.NotificationSettings.Matches;
127+
}
125128
}
126129
else
127130
{
128131
ViewModelMediators.Likes = MatchHelper.LoadProfilesOfLikes(Account.UserID.Value);
129-
notificationsOn = Account.NotificationSettings.Likes;
132+
if (Account.NotificationSettings != null)
133+
{
134+
notificationsOn = Account.NotificationSettings.Likes;
135+
}
130136
}
131137

132138
// 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 +178,31 @@ private static void ChatNotifications(object state)
172178
unreadChatMessages.Add(c);
173179
}
174180
}
181+
Account.NotifiedChatMessages = newChatMessages; // Set the NotifiedChatMessages to the newly obtained chat messages list
175182

176183
// Reload the profiles of matches if there have been new unread chat messages (for chat notification indicator)
177184
if (unreadChatMessages.Count > 0)
178185
{
179186
ViewModelMediators.Matches = MatchHelper.LoadProfilesOfMatches(Account.UserID.Value);
180-
}
181187

182-
// Throw notifications for every new chat message if notifications are on
183-
if (Account.NotificationSettings.Chat)
184-
{
185-
foreach (ChatMessage c in unreadChatMessages)
188+
// Throw notifications for every new chat message if notifications are on
189+
if (Account.NotificationSettings != null && Account.NotificationSettings.Chat)
186190
{
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;
191+
foreach (ChatMessage c in unreadChatMessages)
192+
{
193+
if (!ViewModelMediators.ChatWindowFocus[c.FromUserId])
194+
{
195+
Profile chatProfile = Account.Matches.FirstOrDefault(p => p.UserID == c.FromUserId);
196+
ThrowChatMessageNotification(chatProfile.FirstName,
197+
chatProfile.LastName,
198+
chatProfile.FirstUserMedia,
199+
c.Content,
200+
chatProfile.UserID);
201+
}
202+
c.Seen = true;
203+
}
194204
}
195205
}
196-
197-
// Set the NotifiedChatMessages to the newly obtained chat messages list
198-
Account.NotifiedChatMessages = newChatMessages;
199206
}
200207
}
201208
#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)