feat: add chat messages
This commit is contained in:
26
Client/Domain/Enums/ChatChannelEnum.cs
Normal file
26
Client/Domain/Enums/ChatChannelEnum.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Enums
|
||||
{
|
||||
public enum ChatChannelEnum
|
||||
{
|
||||
All,
|
||||
Shout,
|
||||
Tell,
|
||||
Party,
|
||||
Clan,
|
||||
Gm,
|
||||
PetitionPlayer,
|
||||
PetitionGm,
|
||||
Trade,
|
||||
Alliance,
|
||||
Announcement,
|
||||
PartyroomCommander = 15,
|
||||
PartyroomAll,
|
||||
HeroVoice
|
||||
}
|
||||
}
|
14
Client/Domain/Factories/ChatMessageFactoryInterface.cs
Normal file
14
Client/Domain/Factories/ChatMessageFactoryInterface.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Factories
|
||||
{
|
||||
public interface ChatMessageFactoryInterface
|
||||
{
|
||||
ChatMessage Create(string data);
|
||||
}
|
||||
}
|
@@ -7,8 +7,8 @@ using Client.Domain.Entities;
|
||||
|
||||
namespace Client.Domain.Factories
|
||||
{
|
||||
public interface EntityFactoryInterface<T>
|
||||
{
|
||||
public interface EntityFactoryInterface<T> where T: class
|
||||
{
|
||||
public T? Create(string data);
|
||||
public void Update(T entity, string data);
|
||||
}
|
||||
|
37
Client/Domain/Service/ChatMessageHandler.cs
Normal file
37
Client/Domain/Service/ChatMessageHandler.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Client.Domain.DTO;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Enums;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Domain.ValueObjects;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
public class ChatMessageHandler : HandlerInterface
|
||||
{
|
||||
public void Update(MessageOperationEnum operation, string content)
|
||||
{
|
||||
var message = factory.Create(content);
|
||||
if (operation == MessageOperationEnum.Create)
|
||||
{
|
||||
if (message == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
messages.Add(message);
|
||||
}
|
||||
}
|
||||
|
||||
public ChatMessageHandler(EntityFactoryInterface<ChatMessage> factory)
|
||||
{
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
private readonly EntityFactoryInterface<ChatMessage> factory;
|
||||
private List<ChatMessage> messages = new List<ChatMessage>();
|
||||
}
|
||||
}
|
@@ -10,7 +10,7 @@ using Client.Domain.Factories;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
public class EntityHandler<T> : HandlerInterface where T : EntityInterface
|
||||
public class EntityHandler<T> : HandlerInterface where T : class, EntityInterface
|
||||
{
|
||||
public void Update(MessageOperationEnum operation, string content)
|
||||
{
|
||||
|
25
Client/Domain/ValueObjects/ChatMessage.cs
Normal file
25
Client/Domain/ValueObjects/ChatMessage.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Client.Domain.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.ValueObjects
|
||||
{
|
||||
public class ChatMessage
|
||||
{
|
||||
public uint ObjectId { get; set; }
|
||||
public ChatChannelEnum Channel { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Text { get; set; }
|
||||
|
||||
public ChatMessage(uint objectId, ChatChannelEnum channel, string name, string text)
|
||||
{
|
||||
ObjectId = objectId;
|
||||
Channel = channel;
|
||||
Name = name;
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user