From dff3615ac28f7c37894588406bd45faf90a32588 Mon Sep 17 00:00:00 2001 From: shaed-parkar <41630528+shaed-parkar@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:24:38 +0000 Subject: [PATCH] VIH-11137 inform deleted participant of updated conference to refresh their hearing list (#2300) --- .../DeleteParticipantTests.cs | 9 ++++++++- .../Controllers/ParticipantsController.cs | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/VideoWeb/VideoWeb.UnitTests/Controllers/ParticipantController/DeleteParticipantTests.cs b/VideoWeb/VideoWeb.UnitTests/Controllers/ParticipantController/DeleteParticipantTests.cs index abb702e221..44bddf9cde 100644 --- a/VideoWeb/VideoWeb.UnitTests/Controllers/ParticipantController/DeleteParticipantTests.cs +++ b/VideoWeb/VideoWeb.UnitTests/Controllers/ParticipantController/DeleteParticipantTests.cs @@ -53,6 +53,10 @@ public async Task Should_return_ok() var participant = conference.Participants.First(x=> x.Role == Role.QuickLinkParticipant); participant.ParticipantStatus = ParticipantStatus.Disconnected; + // expected notification list should be all participants except the one being removed (after cache object updated) who will be added at the end + var expectedNotificationList = conference.Participants.Where(x => x.Id != participant.Id).ToList(); + expectedNotificationList.Add(participant); + _mocker.Mock() .Setup(x => x.RemoveParticipantFromConferenceAsync(conference.Id, participant.Id, It.IsAny())) .Returns(Task.CompletedTask); @@ -71,7 +75,10 @@ public async Task Should_return_ok() It.IsAny()), Times.Once); conference.Participants.Should().NotContain(x=> x.Id == participant.Id); _mocker.Mock().Verify( - x => x.PushParticipantsUpdatedEvent(It.IsAny(), It.IsAny>()), Times.Once); + x => x.PushParticipantsUpdatedEvent( + It.Is(c=> c.Id == conference.Id), + expectedNotificationList), + Times.Once); } [Test] diff --git a/VideoWeb/VideoWeb/Controllers/ParticipantsController.cs b/VideoWeb/VideoWeb/Controllers/ParticipantsController.cs index d2ac11a939..d1743a0a64 100644 --- a/VideoWeb/VideoWeb/Controllers/ParticipantsController.cs +++ b/VideoWeb/VideoWeb/Controllers/ParticipantsController.cs @@ -125,7 +125,7 @@ public async Task UpdateParticipantDisplayNameAsync(Guid conferen }, cancellationToken); var conference = await conferenceService.GetConference(conferenceId, cancellationToken); conference.GetParticipant(participantId).DisplayName = participantRequest.DisplayName; - await UpdateCacheAndPublishUpdatedParticipantList(conference, cancellationToken); + await UpdateCacheAndPublishUpdatedParticipantList(conference, null, cancellationToken); return NoContent(); } @@ -212,7 +212,7 @@ public async Task GetCurrentParticipantAsync(Guid conferenceId, C }; if (!profile.Roles.Exists(role => participantsRoles.Contains(role))) return Ok(response); - + var conference = await conferenceService.GetConference(conferenceId, cancellationToken); var participantFromCache = conference.Participants .SingleOrDefault( @@ -292,6 +292,7 @@ public async Task RemoveParticipantFromConferenceAsync(Guid confe CancellationToken cancellationToken) { var conference = await conferenceService.GetConference(conferenceId, cancellationToken); + var participantToRemove = conference.GetParticipant(participantId); if (conference.GetParticipant(participantId).ParticipantStatus is not ParticipantStatus.Disconnected) { ModelState.AddModelError(nameof(participantId), "Participant is not disconnected"); @@ -301,16 +302,21 @@ public async Task RemoveParticipantFromConferenceAsync(Guid confe await videoApiClient.RemoveParticipantFromConferenceAsync(conferenceId, participantId, cancellationToken); conference.RemoveParticipantById(participantId); - await UpdateCacheAndPublishUpdatedParticipantList(conference, cancellationToken); + await UpdateCacheAndPublishUpdatedParticipantList(conference, participantToRemove, cancellationToken); return NoContent(); } - private async Task UpdateCacheAndPublishUpdatedParticipantList(Conference conference, + private async Task UpdateCacheAndPublishUpdatedParticipantList(Conference conference, Participant removedParticipant, CancellationToken cancellationToken) { await conferenceService.UpdateConferenceAsync(conference, cancellationToken); - await participantsUpdatedEventNotifier.PushParticipantsUpdatedEvent(conference, - conference.Participants.ToList()); + var participantsToNotify = conference.Participants.ToList(); + if (removedParticipant != null) + { + // removed participant needs an updated object without themselves in it + participantsToNotify.Add(removedParticipant); + } + await participantsUpdatedEventNotifier.PushParticipantsUpdatedEvent(conference, participantsToNotify); } private Guid GetIdForParticipantByUsernameInConference(Conference conference)