Пример #1
0
        public async Task Join(GroupChangeEvent evt)
        {
            //todo add all user connections to group(s)
            var userId = await _userStore.GetUserIdForConnectionAsync(Context.ConnectionId);

            var connections = await _userStore.GetUserConnectionsAsync(userId);

            var tasks = evt.Groups
                        .Select(group => Groups.AddToGroupAsync(Context.ConnectionId, group));

            await Task.WhenAll(tasks);

            await _userStore.AddUserToGroupsAsync(userId, evt.Groups);

            // send presence event
            var presenceEvents = evt.Groups.Select(g => new PresenceEvent
            {
                Action = PresenceAction.Join,
                Group  = g,
                Uuid   = userId
            });

            var presenceTasks = presenceEvents.Select(e => Clients.GroupExcept(e.Group, connections).Presence(e));

            await Task.WhenAll(presenceTasks);
        }