新增私聊相关
This commit is contained in:
55
Hotfix/Social/Mail/Helper/MailBoxFactory.cs
Normal file
55
Hotfix/Social/Mail/Helper/MailBoxFactory.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Helper;
|
||||
using NB.Game;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public static class MailBoxFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建一个邮件箱
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="sendAccountId"></param>
|
||||
/// <param name="mail"></param>
|
||||
/// <param name="expireTime"></param>
|
||||
/// <param name="accountIds"></param>
|
||||
/// <returns></returns>
|
||||
public static MailBox Create(Scene scene, long sendAccountId, Mail mail, int expireTime, List<long> accountIds)
|
||||
{
|
||||
var mailBox = Entity.Create<MailBox>(scene, true, true);
|
||||
mailBox.SendAccountId = sendAccountId;
|
||||
mailBox.Mail = mail;
|
||||
mailBox.ExpireTime = TimeHelper.Now + expireTime;
|
||||
mailBox.CreateTime = TimeHelper.Now;
|
||||
if (accountIds == null || accountIds.Count <= 0)
|
||||
{
|
||||
return mailBox;
|
||||
}
|
||||
|
||||
foreach (var accountId in accountIds)
|
||||
{
|
||||
mailBox.AccountId.Add(accountId);
|
||||
}
|
||||
|
||||
return mailBox;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个邮件箱
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="sendAccountId"></param>
|
||||
/// <param name="expireTime"></param>
|
||||
/// <param name="accountIds"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="items"></param>
|
||||
/// <returns></returns>
|
||||
public static MailBox Create(Scene scene, long sendAccountId, int expireTime, List<long> accountIds,
|
||||
string content, List<AwardItem> items = null)
|
||||
{
|
||||
var mail = MailFactory.Create(scene, content, items);
|
||||
return Create(scene, sendAccountId, mail, expireTime, accountIds);
|
||||
}
|
||||
}
|
||||
38
Hotfix/Social/Mail/Helper/MailConversationHelper.cs
Normal file
38
Hotfix/Social/Mail/Helper/MailConversationHelper.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using NB.Game;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public static class MailConversationHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 从数据库中读取GameAccount
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="firstId"></param>
|
||||
/// <param name="secondId"></param>
|
||||
/// <returns></returns>
|
||||
public static async FTask<MailConversation> LoadDataBase(Scene scene, long firstId, long secondId)
|
||||
{
|
||||
var conversation =
|
||||
await scene.World.DataBase.First<MailConversation>(d => d.FirstId == firstId && d.SecondId == secondId);
|
||||
if (conversation == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
conversation.Deserialize(scene);
|
||||
return conversation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库中移除
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="id"></param>
|
||||
public static async FTask DeleteDataBase(Scene scene,long id)
|
||||
{
|
||||
await scene.World.DataBase.Remove<MailConversation>(id);
|
||||
}
|
||||
}
|
||||
30
Hotfix/Social/Mail/Helper/MailFactory.cs
Normal file
30
Hotfix/Social/Mail/Helper/MailFactory.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Helper;
|
||||
using Fantasy.Serialize;
|
||||
using NB.Game;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public static class MailFactory
|
||||
{
|
||||
private static readonly ISerialize _serializer = SerializerManager.GetSerializer(FantasySerializerType.Bson);
|
||||
|
||||
public static Mail Create(Scene scene, string content, List<AwardItem> items = null)
|
||||
{
|
||||
var mail = Entity.Create<Mail>(scene, true, true);
|
||||
mail.Content = content;
|
||||
mail.State = MailState.Unread;
|
||||
mail.CreateTime = TimeHelper.Now;
|
||||
|
||||
if (items != null && items.Count > 0)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
mail.Items.Add(_serializer.Clone(item));
|
||||
}
|
||||
}
|
||||
|
||||
return mail;
|
||||
}
|
||||
}
|
||||
32
Hotfix/Social/Mail/Helper/MailHelper.cs
Normal file
32
Hotfix/Social/Mail/Helper/MailHelper.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// 发送邮件接口
|
||||
/// </summary>
|
||||
public static class MailHelper
|
||||
{
|
||||
|
||||
public static async FTask Send(Scene scene, MailBox mailBox)
|
||||
{
|
||||
if (mailBox.BoxType == MailBoxType.None)
|
||||
{
|
||||
Log.Error("不支持的邮件类型");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mailBox.BoxType)
|
||||
{
|
||||
case MailBoxType.All:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case MailBoxType.Specify:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user