예제 #1
0
        public async Task <ResultReturn <DTO_UserSession> > CreateGroupSession(
            [FromServices] HubCallerContext callContext,
            [FromServices] IHubContext <ChatHub> hubContext,
            [FromServices] IMemoryCache cache,
            [FromServices] SessionService session,
            string[] toUserIds)
        {
            var sessionId = await session.CreateGroupSession(CurrentUserId, toUserIds);

            var sessionInfo = await session.GetSessionInfoById(sessionId);

            await hubContext.Groups.AddToGroupAsync(callContext.ConnectionId, sessionId.ToStringEx());

            foreach (var userId in toUserIds)
            {
                if (cache.TryGetValue(userId, out var tmp))
                {
                    await hubContext.Groups.AddToGroupAsync(tmp.ToStringEx(), sessionId.ToStringEx());
                }
            }

            return(new SuccessResultReturn <DTO_UserSession>(sessionInfo));
        }