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

Commit

Permalink
Fixed #7
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Jan 1, 2018
1 parent 9ab0040 commit 1cd126a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
12 changes: 8 additions & 4 deletions Data_Manager2/Classes/DBManager/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class ChatManager : AbstractManager

public delegate void NewChatMessageHandler(ChatManager handler, NewChatMessageEventArgs args);
public delegate void ChatChangedHandler(ChatManager handler, ChatChangedEventArgs args);
public delegate void ChatMessagesChangedHandler(ChatManager handler, ChatChangedEventArgs args);
public delegate void ChatMessageChangedHandler(ChatManager handler, ChatMessageChangedEventArgs args);

public event NewChatMessageHandler NewChatMessage;
public event ChatChangedHandler ChatChanged;
public event ChatMessagesChangedHandler ChatMessagesChanged;
public event ChatMessageChangedHandler ChatMessageChanged;

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
Expand Down Expand Up @@ -127,6 +127,10 @@ public void updateChatMessageState(string msgId, MessageState state)
{
dB.Execute("UPDATE ChatMessageTable SET state = ? WHERE id = ?", state, msgId);
List<ChatMessageTable> list = dB.Query<ChatMessageTable>("SELECT * FROM ChatMessageTable WHERE id = ?;", msgId);
Parallel.ForEach(list, (msg) =>
{
ChatMessageChanged?.Invoke(this, new ChatMessageChangedEventArgs(msg));
});
}

public void deleteAllChatMessagesForAccount(ChatTable chat)
Expand All @@ -137,15 +141,15 @@ public void deleteAllChatMessagesForAccount(ChatTable chat)
public void markAllMessagesAsRead(ChatTable chat)
{
List<ChatMessageTable> list = getAllUnreadMessages(chat);
if(list.Count > 0)
if (list.Count > 0)
{
Parallel.ForEach(list, (msg) =>
{
msg.state = MessageState.READ;
update(msg);
msg.onChanged();
ChatMessageChanged?.Invoke(this, new ChatMessageChangedEventArgs(msg));
});
ChatMessagesChanged?.Invoke(this, new ChatChangedEventArgs(chat, false));
}
}

Expand Down
53 changes: 53 additions & 0 deletions Data_Manager2/Classes/Events/ChatMessageChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Data_Manager2.Classes.DBTables;
using System;

namespace Data_Manager.Classes.Events
{
public class ChatMessageChangedEventArgs : EventArgs
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--
public readonly ChatMessageTable MESSAGE;

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
#region --Constructors--
/// <summary>
/// Basic Constructor
/// </summary>
/// <history>
/// 01/01/2018 Created [Fabian Sauter]
/// </history>
public ChatMessageChangedEventArgs(ChatMessageTable message)
{
this.MESSAGE = message;
}

#endregion
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
#region --Set-, Get- Methods--


#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--


#endregion

#region --Misc Methods (Private)--


#endregion

#region --Misc Methods (Protected)--


#endregion
//--------------------------------------------------------Events:---------------------------------------------------------------------\\
#region --Events--


#endregion
}
}
1 change: 1 addition & 0 deletions Data_Manager2/Data_Manager2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<Compile Include="Classes\Events\ClientConnectedEventArgs.cs" />
<Compile Include="Classes\Events\AccountChangedEventArgs.cs" />
<Compile Include="Classes\Events\ChatChangedEventArgs.cs" />
<Compile Include="Classes\Events\ChatMessageChangedEventArgs.cs" />
<Compile Include="Classes\Events\NewChatMessageEventArgs.cs" />
<Compile Include="Classes\MessageState.cs" />
<Compile Include="Classes\Settings.cs" />
Expand Down
10 changes: 5 additions & 5 deletions UWP XMPP Client/Controls/ChatMasterControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public ChatMasterControl()
this.lastChatMessage = null;
ChatManager.INSTANCE.ChatChanged -= INSTANCE_ChatChanged;
ChatManager.INSTANCE.ChatChanged += INSTANCE_ChatChanged;
ChatManager.INSTANCE.ChatMessagesChanged -= INSTANCE_ChatMessagesChanged;
ChatManager.INSTANCE.ChatMessagesChanged += INSTANCE_ChatMessagesChanged;
ChatManager.INSTANCE.ChatMessageChanged -= INSTANCE_ChatMessageChanged;
ChatManager.INSTANCE.ChatMessageChanged += INSTANCE_ChatMessageChanged;
}

#endregion
Expand Down Expand Up @@ -380,13 +380,13 @@ private void ChatMessage_ChatMessageChanged(object sender, EventArgs e)
showLastChatMessage(lastChatMessage);
}

private async void INSTANCE_ChatMessagesChanged(ChatManager handler, Data_Manager.Classes.Events.ChatChangedEventArgs args)
private async void INSTANCE_ChatMessageChanged(ChatManager handler, Data_Manager.Classes.Events.ChatMessageChangedEventArgs args)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
if (Chat != null && Equals(args.CHAT.id, Chat.id))
if (Chat != null && lastChatMessage != null && Equals(args.MESSAGE.chatId, Chat.id) && Equals(lastChatMessage.id, args.MESSAGE.id))
{
showLastChatMessage(ChatManager.INSTANCE.getLastChatMessageForChat(Chat));
showLastChatMessage(args.MESSAGE);
}
});
}
Expand Down

0 comments on commit 1cd126a

Please sign in to comment.