public async Task <Unit> Handle(UpdateSynchronizedObjectRequest request, CancellationToken cancellationToken) { var(conferenceId, synchronizedObjectId) = request; var provider = GetProvider(synchronizedObjectId); var subscribedParticipants = await _mediator.Send(new FetchSubscribedParticipantsRequest(conferenceId, synchronizedObjectId), cancellationToken); _logger.LogDebug("Update synchronized object {syncObj} ({count} subscribers)", synchronizedObjectId, subscribedParticipants.Count); if (!subscribedParticipants.Any()) { await _synchronizedObjectRepository.Remove(conferenceId, synchronizedObjectId.ToString()); return(Unit.Value); } var newValue = await provider.FetchValue(conferenceId, synchronizedObjectId); var previousValue = await _synchronizedObjectRepository.Create(conferenceId, synchronizedObjectId.ToString(), newValue, provider.Type); if (Equals(newValue, previousValue)) { return(Unit.Value); } await _mediator.Publish( new SynchronizedObjectUpdatedNotification(subscribedParticipants, synchronizedObjectId.ToString(), newValue, previousValue), cancellationToken); return(Unit.Value); }
public async Task Handle(ParticipantSubscriptionsUpdatedNotification notification, CancellationToken cancellationToken) { var((conferenceId, _), removedSubscriptions, _) = notification; if (!removedSubscriptions.Any()) { return; } var conferenceSubscriptions = await _subscriptionsRepository.GetOfConference(conferenceId); var activeSyncObjects = conferenceSubscriptions.SelectMany(x => x.Value ?? ImmutableList <string> .Empty) .ToHashSet(); var inactiveSyncObjects = removedSubscriptions.Select(x => x.ToString()).Except(activeSyncObjects); foreach (var inactiveSubscription in inactiveSyncObjects) { await _synchronizedObjectRepository.Remove(conferenceId, inactiveSubscription); } }