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

Commit

Permalink
Merge pull request #138 from Unabashed-Development/development
Browse files Browse the repository at this point in the history
Some final bug fixes!
  • Loading branch information
RillJ authored Jan 15, 2022
2 parents d5fc844 + e4444b4 commit 0ecfe07
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 47 deletions.
9 changes: 7 additions & 2 deletions Gateway/Helpers/FiddleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ namespace Gateway
public static class FiddleHelper
{
/// <summary>
/// Assigns the right connection name to the connection string.
/// Assigns the right connection name to the connection string using the randomized port.
/// </summary>
/// <param name="name">The name of the connection.</param>
/// <returns>A string of the ConfigurationManager.</returns>
public static string GetConnectionStringSql(string name) => ConfigurationManager.ConnectionStrings[name].ConnectionString;
public static string GetConnectionStringSql(string name)
{
string connectionString = ConfigurationManager.ConnectionStrings[name].ConnectionString;
int indexOfServer = connectionString.IndexOf(';');
return connectionString.Insert(indexOfServer, ',' + SSHService.SshPort.ToString());
}
}
}
2 changes: 1 addition & 1 deletion Gateway/ProfileDataAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static Profile LoadProfile(int id)
MoralsData moralsData = LoadMoralsData(id);
studentData.MoralsData = moralsData;
studentData.UserMedia = new System.Collections.ObjectModel.ObservableCollection<Uri>(MediaDataAccess.GetUserMediaUris(id));
studentData.FirstUserMedia = studentData.UserMedia?.FirstOrDefault();
studentData.FirstUserMedia = studentData.UserMedia?.DefaultIfEmpty(new Uri("http://www.stugether.wafoe.nl/media/blank_profile_stugether.png")).First();
studentData.MatchRelationType = LoadRelationshipTypeMatch(studentData.UserID);
return studentData;
}
Expand Down
3 changes: 1 addition & 2 deletions Gateway/Services/SSHService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ private static Tuple<SshClient, uint> ConnectSsh(string sshHostName, string sshU
sshClient.Connect();

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

Expand Down
2 changes: 1 addition & 1 deletion View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Style="{StaticResource {x:Type Window}}"
Title="Stugether" Height="450" Width="800">
Title="Stugether" Height="563" Width="1000">
<Window.DataContext>
<vm:MainPageViewModel/>
</Window.DataContext>
Expand Down
14 changes: 6 additions & 8 deletions View/OverviewMatches.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ public OverviewMatches()
/// </summary>
private void Profile_Click(object sender, RoutedEventArgs e)
{
Profile profile = ((Button)sender).DataContext as Profile;
if (!FocusOpenedWindow<ProfileWindow>(profile))
if (((Button)sender).DataContext is Profile profile && !FocusOpenedWindow<ProfileWindow>(profile))
{
ProfileWindow profileWindow = new ProfileWindow();
profileWindow.ProfileWindowFrame.Content = new ProfilePage(new ProfilePageViewModel(profile));

profileWindow.Show(); // Show the authentication window
profileWindow.Show();
}
}

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

profileWindow.Show(); // Show the authentication window
profileWindow.Show();
}

private void Chat_Click(object sender, RoutedEventArgs e)
{
Profile profile = ((Button)sender).DataContext as Profile;
if (!FocusOpenedWindow<ChatWindow>(profile))
if (((Button)sender).DataContext is Profile profile && !FocusOpenedWindow<ChatWindow>(profile))
{
ChatWindow chatWindow = new ChatWindow
{
Expand All @@ -72,10 +70,10 @@ public static void Chat_Base(ChatWindow chatWindow)
public static bool FocusOpenedWindow<T>(int userID) where T : Window
{
bool success = false;
System.Windows.Application.Current.Dispatcher.Invoke(delegate // Dispatcher delegate for threads
Application.Current.Dispatcher.Invoke(delegate // Dispatcher delegate for threads
{
// Check if a window is already open for the user, and if so, focus it instead of opening a new window
foreach (T t in System.Windows.Application.Current.Windows.OfType<T>())
foreach (T t in Application.Current.Windows.OfType<T>())
{
if (typeof(T) == typeof(ChatWindow))
{
Expand Down
3 changes: 2 additions & 1 deletion View/View.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>stugether_logo.ico</ApplicationIcon>
<AssemblyName>Stugether</AssemblyName>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<Authors>Unabashed Development</Authors>
<Company>Unabashed Development</Company>
<Description>Your student matching application!</Description>
<Copyright>Unabashed Development</Copyright>
<PackageProjectUrl></PackageProjectUrl>
<RepositoryUrl>https://github.com/Unabashed-Development/Stugether</RepositoryUrl>
<AssemblyVersion>1.0.2.0</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions ViewModel/Authentication/HomePageAfterLoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private void Logout()
{
Account.Email = null;
Account.UserID = null;
Account.NotifiedChatMessages = null;
ViewModelMediators.Authenticated = false;
}

Expand Down
25 changes: 15 additions & 10 deletions ViewModel/ChatWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Windows.Input;
using ViewModel.Commands;
using ViewModel.Mediators;

namespace ViewModel
{
Expand Down Expand Up @@ -175,18 +176,21 @@ public void SeenChatMessages()
}
}

public bool ChatWindowHasFocus { internal get; set; }
#endregion

#region Construction and destruction
/// <summary>
/// Creates an empty conversation
/// </summary>
public ChatWindowViewModel()
public bool ChatWindowHasFocus
{

get
{
if (!ViewModelMediators.ChatWindowFocus.ContainsKey(Receiver.UserID))
{
ViewModelMediators.ChatWindowFocus.Add(Receiver.UserID, true);
}
return ViewModelMediators.ChatWindowFocus[Receiver.UserID];
}
set => ViewModelMediators.ChatWindowFocus[Receiver.UserID] = value;
}
#endregion

#region Construction and destruction
/// <summary>
/// Creates a conversationViewModel with given userId
/// </summary>
Expand All @@ -207,10 +211,11 @@ public ChatWindowViewModel(Profile otherUser)
}

/// <summary>
/// Destructs ChatWindowViewModel, and so stops the background timer for updating chats
/// Destructs ChatWindowViewModel, and so stops the background timer for updating chats and cleans up ChatWindowFocus
/// </summary>
~ChatWindowViewModel()
{
ViewModelMediators.ChatWindowFocus.Remove(Receiver.UserID);
Account.BackgroundThreads[backgroundThreadName].Dispose();
Account.BackgroundThreads.Remove(backgroundThreadName);
}
Expand Down
62 changes: 40 additions & 22 deletions ViewModel/Helpers/NotificationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,20 @@ private static void MatchOrLikeNotification(object matchOrLike)
List<Profile> profileList;

// Prepares data depending on the match or like handling
if ((MatchOrLike)matchOrLike == MatchOrLike.Matched)
if ((MatchOrLike)matchOrLike == MatchOrLike.Matched && Account.UserID != null)
{
current = new HashSet<int>(MatchDataAccess.GetAllMatchesFromUser(Account.UserID.Value, MatchOrLike.Matched));
profileList = ViewModelMediators.Matches;
}
else
else if ((MatchOrLike)matchOrLike == MatchOrLike.Liked && Account.UserID != null)
{
current = new HashSet<int>(MatchDataAccess.GetReceivedLikesFromUser(Account.UserID.Value));
profileList = ViewModelMediators.Likes;
}
else
{
throw new Exception("Match or like notification MatchOrLike enum not set correctly");
}

// Add the user ID's to the HashSet
foreach (Profile p in profileList)
Expand All @@ -116,17 +120,29 @@ private static void MatchOrLikeNotification(object matchOrLike)
// If the amounts are different OR there is at least 1 new user...
if (current.Count != previous.Count || current.Count > 0)
{
bool notificationsOn;
bool notificationsOn = false;
// ...reload the profiles
if ((MatchOrLike)matchOrLike == MatchOrLike.Matched)
{
ViewModelMediators.Matches = MatchHelper.LoadProfilesOfMatches(Account.UserID.Value);
notificationsOn = Account.NotificationSettings.Matches;
if (Account.UserID != null)
{
ViewModelMediators.Matches = MatchHelper.LoadProfilesOfMatches(Account.UserID.Value);
}
if (Account.NotificationSettings != null)
{
notificationsOn = Account.NotificationSettings.Matches;
}
}
else
{
ViewModelMediators.Likes = MatchHelper.LoadProfilesOfLikes(Account.UserID.Value);
notificationsOn = Account.NotificationSettings.Likes;
if (Account.UserID != null)
{
ViewModelMediators.Likes = MatchHelper.LoadProfilesOfLikes(Account.UserID.Value);
}
if (Account.NotificationSettings != null)
{
notificationsOn = Account.NotificationSettings.Likes;
}
}

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

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

// Throw notifications for every new chat message if notifications are on
if (Account.NotificationSettings.Chat)
{
foreach (ChatMessage c in unreadChatMessages)
// Throw notifications for every new chat message if notifications are on
if (Account.NotificationSettings != null && Account.NotificationSettings.Chat)
{
Profile chatProfile = Account.Matches.FirstOrDefault(p => p.UserID == c.FromUserId);
ThrowChatMessageNotification(chatProfile.FirstName,
chatProfile.LastName,
chatProfile.FirstUserMedia,
c.Content,
chatProfile.UserID);
c.Seen = true;
foreach (ChatMessage c in unreadChatMessages)
{
bool dictionaryContainsUser = ViewModelMediators.ChatWindowFocus.ContainsKey(c.FromUserId);
if ((dictionaryContainsUser && !ViewModelMediators.ChatWindowFocus[c.FromUserId]) || !dictionaryContainsUser)
{
Profile chatProfile = Account.Matches.FirstOrDefault(p => p.UserID == c.FromUserId);
ThrowChatMessageNotification(chatProfile.FirstName,
chatProfile.LastName,
chatProfile.FirstUserMedia,
c.Content,
chatProfile.UserID);
}
c.Seen = true;
}
}
}

// Set the NotifiedChatMessages to the newly obtained chat messages list
Account.NotifiedChatMessages = newChatMessages;
}
}
#endregion
Expand Down
2 changes: 2 additions & 0 deletions ViewModel/Mediators/ViewModelMediators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public static List<Profile> Likes
LikesChanged?.Invoke();
}
}

public static Dictionary<int, bool> ChatWindowFocus { get; set; } = new Dictionary<int, bool>();
#endregion
}
}

0 comments on commit 0ecfe07

Please sign in to comment.