Skip to content

Commit

Permalink
Performance optimization for managing message creation events (writin…
Browse files Browse the repository at this point in the history
…g, sending file).
  • Loading branch information
Luis committed Nov 15, 2020
1 parent 121f6f4 commit 58e6606
Show file tree
Hide file tree
Showing 12 changed files with 814 additions and 138 deletions.
18 changes: 12 additions & 6 deletions Khernet.UI/Khernet.UI.Presentation/Engine/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public static Task Start(PeerIdentity currentUser)
IoCContainer.Configure<ChatMessageListViewModel>();

IoCContainer.Configure<UserListViewModel>();
IoCContainer.Configure<MessageWritingChecker>();
IoCContainer.Configure<MessageProcessingEventManager>();

StartClient();

Expand Down Expand Up @@ -212,24 +214,26 @@ private static void Listener_ProcessingMessage(object sender, MessageProcessingE
if (State != EngineState.Executing)
return;

var user = IoCContainer.Get<UserListViewModel>().FindUser(e.Notification.SenderToken);
if (user == null)
return;
MessageEventData messageEvent = new MessageEventData();

switch (e.Notification.Process)
{
case MessageProcessing.WritingText:
user.ShowUserWriting();
messageEvent.EventType = MessageEvent.BeginWriting;
break;

case MessageProcessing.BeginSendingFile:
user.ShowUserSendingFile();
messageEvent.EventType = MessageEvent.BeginSendingFile;
break;

case MessageProcessing.EndSendingFile:
user.HideUserSendingFile();
messageEvent.EventType = MessageEvent.EndSendingFile;
break;
}
messageEvent.ArriveDate = DateTime.Now;
messageEvent.SenderPeer = e.Notification.SenderToken;

IoCContainer.Get<MessageProcessingEventManager>().ProcessMessageEvent(messageEvent);
}

public static void Stop()
Expand Down Expand Up @@ -290,6 +294,8 @@ private static void StopClient()
IoCContainer.UnConfigure<UserManager>();

IoCContainer.UnConfigure<UserListViewModel>();
IoCContainer.UnConfigure<MessageProcessingEventManager>();
IoCContainer.UnConfigure<MessageWritingChecker>();

IoCContainer.UnBind<IChatList>();
IoCContainer.UnBind<IIdentity>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,10 @@
<Compile Include="Managers\AudioManager.cs" />
<Compile Include="Managers\AudioObservers.cs" />
<Compile Include="Managers\ChatMessageStateManager.cs" />
<Compile Include="Managers\MessageWritingChecker.cs" />
<Compile Include="Managers\PresentationApplicationDialog.cs" />
<Compile Include="Managers\MessageProcessingEventManager.cs" />
<Compile Include="Managers\MessageEvents.cs" />
<Compile Include="Managers\TextRequest.cs" />
<Compile Include="Managers\TextManager.cs" />
<Compile Include="Managers\FileManager.cs" />
Expand Down
51 changes: 51 additions & 0 deletions Khernet.UI/Khernet.UI.Presentation/Managers/MessageEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Diagnostics;

namespace Khernet.UI.Managers
{
public enum MessageEvent
{
/// <summary>
/// Message is staring to be written.
/// </summary>
BeginWriting = 0,

/// <summary>
/// Message has finished written.
/// </summary>
EndWriting = 1,

/// <summary>
/// File is starting to be sent.
/// </summary>
BeginSendingFile = 2,

/// <summary>
/// File has finished sending.
/// </summary>
EndSendingFile = 3
}

public class MessageEventData
{
/// <summary>
/// The type action that is being performing when creating a message.
/// </summary>
public MessageEvent EventType { get; set; }

/// <summary>
/// The peer that is creating the message.
/// </summary>
public string SenderPeer { get; set; }

/// <summary>
/// The peer that receive the event.
/// </summary>
public string ReceiverPeer { get; set; }

/// <summary>
/// The date when this event arrived to UI.
/// </summary>
public DateTime ArriveDate { get; set; }
}
}
Loading

0 comments on commit 58e6606

Please sign in to comment.