using System.Diagnostics;
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;

namespace NB.Chat;

public class
    C2S_GetConversationsRequestHandler : RouteRPC<SocialUnit, C2S_GetConversationsRequest, S2C_GetConversationsResponse>
{
    protected override async FTask Run(SocialUnit entity, C2S_GetConversationsRequest request,
        S2C_GetConversationsResponse response, Action reply)
    {
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        var mailManageComponent = entity.Scene.GetComponent<MailManageComponent>();
        var list = await mailManageComponent.GetConversations(entity.Id);
        response.List = await list.ToInfo(entity.Scene, entity.Id);
        stopwatch.Stop();
        Log.Info($"查询会话列表耗时={stopwatch.ElapsedMilliseconds}");
    }
}