using Fantasy.Entitas;
using Fantasy.Helper;
namespace NB.Chat;
public static class ChatChannelCenterComponentSystem
{
///
/// 申请创建一个频道
///
///
///
///
///
public static ChatChannel Apply(this ChatChannelCenterComponent self, ChatUnit unit, long channelId)
{
if (self.Channels.TryGetValue(channelId, out var channel))
{
return channel;
}
channel = Entity.Create(self.Scene, channelId, true, true);
channel.Creator = unit.Role.RoleId;
channel.CreateTime = TimeHelper.Now;
self.Channels.Add(channelId, channel);
return channel;
}
///
/// 获取
///
///
///
///
///
public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannel? channel)
{
return self.Channels.TryGetValue(channelId, out channel);
}
///
/// 解散
///
///
///
public static void Disband(this ChatChannelCenterComponent self, long channelId)
{
if (self.Channels.Remove(channelId, out var channel))
{
return;
}
channel?.Dispose();
}
}