public async Task Handle(ConnectionUpdatedIntegrationEvent @event) { var connectionSubscription = new ConnectionSubscription(@event.UserId, @event.OtherId); var connectionMethod = ConnectionUpdatedMethod.WithArgs(@event.OtherId, @event.Notes, (int)@event.Relationship); await _publisherService.PublishAsync(connectionSubscription, connectionMethod); var statusSubscription = new UserStatusSubscription(@event.OtherId); var connections = await _connectionService.GetConnectionsAsync(@event.UserId); foreach (var connection in connections) { if (@event.Relationship == ConnectionUpdatedIntegrationEvent.RelationshipEnum.Friend) { await _subscriptionService.SubscribeAsync(connection, statusSubscription); var isOnline = await _connectionService.HasConnectionsAsync(@event.OtherId); var statusMethod = UserStatusUpdatedMethod.WithArgs(@event.OtherId, isOnline ? UserStatus.Online : UserStatus.Offline); await _publisherService.PublishAsync(connection, statusMethod); } else { await _subscriptionService.UnsubscribeAsync(connection, statusSubscription); var statusMethod = UserStatusUpdatedMethod.WithArgs(@event.OtherId, UserStatus.Unknown); await _publisherService.PublishAsync(connection, statusMethod); } } }
public async Task Handle(ConnectionCreatedIntegrationEvent @event) { var userSubscription = new UserSubscription(@event.OtherId); var connectionSubscription = new ConnectionSubscription(@event.UserId, @event.OtherId); var connectionIds = await _userConnectionService.GetConnectionsAsync(@event.UserId); foreach (var connectionId in connectionIds) { await _subscriptionService.SubscribeAsync(connectionId, userSubscription); await _subscriptionService.SubscribeAsync(connectionId, connectionSubscription); } var method = ConnectionCreatedMethod.WithArgs(@event.OtherId, @event.Name, @event.Tag); await _publisherService.PublishAsync(connectionSubscription, method); }
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); } }