Esempio n. 1
0
        public async Task Handle(RoomCreatedIntegrationEvent @event)
        {
            var roomSubscription = new RoomSubscription(@event.RoomId);

            var roomType = @event.Members.Count > 2 ? RoomCreatedIntegrationEvent.RoomType.Group : RoomCreatedIntegrationEvent.RoomType.Private;
            var method   = RoomCreatedMethod.WithArgs(@event.RoomId, (int)roomType, null, @event.OwnerId, @event.Members);

            foreach (var recipient in @event.Members)
            {
                var connections = await _userConnectionService.GetConnectionsAsync(recipient.Id);

                foreach (var connectionId in connections)
                {
                    await _subscriptionService.SubscribeAsync(connectionId, roomSubscription);
                }
            }

            await _publisherService.PublishAsync(roomSubscription, method);
        }
        public async Task Handle(GroupRoomMemberAddedIntegrationEvent @event)
        {
            var roomSubscription = new RoomSubscription(@event.RoomId);
            var method           = GroupRoomMemberAddedMethod.WithArgs(
                @event.RoomId, @event.AddedMember.Id, @event.AddedMember.Name, @event.AddedMember.Tag);

            await _publisherService.PublishAsync(roomSubscription, method);

            var connectionIds = await _userConnectionService.GetConnectionsAsync(@event.AddedMember.Id);

            foreach (var connectionId in connectionIds)
            {
                await _subscriptionService.SubscribeAsync(connectionId, roomSubscription);

                var createdMethod = RoomCreatedMethod.WithArgs(
                    @event.RoomId, (int)RoomCreatedIntegrationEvent.RoomType.Group, @event.Room.Name, @event.Room.OwnerId, @event.Room.Members);

                await _publisherService.PublishAsync(connectionId, createdMethod);
            }
        }