public async Task Handle(GroupRoomUpdatedIntegrationEvent @event) { var roomSubscription = new RoomSubscription(@event.RoomId); var method = GroupRoomUpdatedMethod.WithArgs(@event.RoomId, @event.Name, @event.OwnerId); await _publisherService.PublishAsync(roomSubscription, method); }
public override async Task <Empty> SubscribeToRoomsUpdates(RoomsUpdatesRequest request, ServerCallContext context) { _logger.LogInformation( "Begin grpc call from method {Method} to subscribe to Rooms {RoomsIds} with connectionId {ConnectionId}", context.Method, string.Join(',', request.Rooms.Select(r => r.Id)), request.ConnectionId); var verifiedConnection = await _userConnectionService.VerifyConnectionAsync(request.UserId, request.ConnectionId); if (!verifiedConnection) { context.Status = new Status(StatusCode.InvalidArgument, "Invalid connection id."); return(new Empty()); } foreach (var dm in request.Rooms) { var dmSubscription = new RoomSubscription(dm.Id); await _subscriptionService.SubscribeAsync(request.ConnectionId, dmSubscription); foreach (var member in dm.MembersIds) { var userSubscription = new UserSubscription(member); await _subscriptionService.SubscribeAsync(request.ConnectionId, userSubscription); } } return(new Empty()); }
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); } }
private void HandleUpdateSubscription(Guid userId, Guid roomId, DateTime timeStamp, RoomSubscription subscriber) { visitRepository.Update(new UserRoom { UserId = userId, RoomId = roomId, LastVisitTimeStamp = timeStamp }); subscriber.LastVisit = timeStamp; }