Skip to content

Commit

Permalink
VIH-11137 inform deleted participant of updated conference to refresh…
Browse files Browse the repository at this point in the history
… their hearing list (#2300)
  • Loading branch information
shaed-parkar authored Nov 18, 2024
1 parent 405c282 commit dff3615
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IVideoApiClient>()
.Setup(x => x.RemoveParticipantFromConferenceAsync(conference.Id, participant.Id, It.IsAny<CancellationToken>()))
.Returns(Task.CompletedTask);
Expand All @@ -71,7 +75,10 @@ public async Task Should_return_ok()
It.IsAny<CancellationToken>()), Times.Once);
conference.Participants.Should().NotContain(x=> x.Id == participant.Id);
_mocker.Mock<IParticipantsUpdatedEventNotifier>().Verify(
x => x.PushParticipantsUpdatedEvent(It.IsAny<Conference>(), It.IsAny<IList<Participant>>()), Times.Once);
x => x.PushParticipantsUpdatedEvent(
It.Is<Conference>(c=> c.Id == conference.Id),
expectedNotificationList),
Times.Once);
}

[Test]
Expand Down
18 changes: 12 additions & 6 deletions VideoWeb/VideoWeb/Controllers/ParticipantsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public async Task<IActionResult> 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();
}
Expand Down Expand Up @@ -212,7 +212,7 @@ public async Task<IActionResult> 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(
Expand Down Expand Up @@ -292,6 +292,7 @@ public async Task<IActionResult> 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");
Expand All @@ -301,16 +302,21 @@ public async Task<IActionResult> 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)
Expand Down

0 comments on commit dff3615

Please sign in to comment.