Skip to content

Commit

Permalink
Switch signalR group to github Identity (#6860)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu authored Aug 28, 2023
1 parent 7e613f7 commit 7361064
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<ActionResult> Add(string reviewId, string revisionId, string e
if (string.IsNullOrEmpty(commentText))
{
var notifcation = new NotificationModel() { Message = "Comment Text cannot be empty. Please type your comment entry and try again.", Level = NotificatonLevel.Error };
await _signalRHubContext.Clients.Group(User.Identity.Name).SendAsync("RecieveNotification", notifcation);
await _signalRHubContext.Clients.Group(User.GetGitHubLogin()).SendAsync("RecieveNotification", notifcation);
return new BadRequestResult();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private async Task SendAIReviewGenerationStatus(ReviewModel review, string revie
notification.Level = NotificatonLevel.Error;
break;
}
await _signalRHubContext.Clients.Group(User.Identity.Name).SendAsync("RecieveAIReviewGenerationStatus", notification);
await _signalRHubContext.Clients.Group(User.GetGitHubLogin()).SendAsync("RecieveAIReviewGenerationStatus", notification);
}
}
}
4 changes: 1 addition & 3 deletions src/dotnet/APIView/APIViewWeb/Hubs/SignalRHub.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Threading.Tasks;
using APIViewWeb.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.Logging;

namespace APIViewWeb.Hubs
Expand All @@ -17,7 +15,7 @@ public SignalRHub(ILogger<SignalRHub> logger) {

public override Task OnConnectedAsync()
{
string name = Context.User.Identity.Name;
string name = Context.User.GetGitHubLogin();
if (!string.IsNullOrEmpty(name))
{
Groups.AddToGroupAsync(Context.ConnectionId, name);
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/APIView/APIViewWeb/Managers/ReviewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public async Task ToggleApprovalAsync(ClaimsPrincipal user, string id, string re
review.ApprovalDate = DateTime.Now;
approvalStatus = true;
}
await _signalRHubContext.Clients.Group(user.Identity.Name).SendAsync("ReceiveApprovalSelf", review.ReviewId, revisionId, approvalStatus);
await _signalRHubContext.Clients.Group(user.GetGitHubLogin()).SendAsync("ReceiveApprovalSelf", review.ReviewId, revisionId, approvalStatus);
await _signalRHubContext.Clients.All.SendAsync("ReceiveApproval", review.ReviewId, revisionId, userId, approvalStatus);
await _reviewsRepository.UpsertReviewAsync(review);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task<IActionResult> OnPostUploadAsync()
}
}
var notifcation = new NotificationModel() { Message = errors.ToString(), Level = NotificatonLevel.Error };
await _notificationHubContext.Clients.Group(User.Identity.Name).SendAsync("RecieveNotification", notifcation);
await _notificationHubContext.Clients.Group(User.GetGitHubLogin()).SendAsync("RecieveNotification", notifcation);
return new NoContentResult();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task<IActionResult> OnGetAsync(string id, string revisionId = null)
if (Lines.Length == 0)
{
var notifcation = new NotificationModel() { Message = "There is no diff between the two revisions.", Level = NotificatonLevel.Info };
await _signalRHubContext.Clients.Group(User.Identity.Name).SendAsync("RecieveNotification", notifcation);
await _signalRHubContext.Clients.Group(User.GetGitHubLogin()).SendAsync("RecieveNotification", notifcation);
return Redirect(Request.Headers["referer"]);
}
}
Expand Down Expand Up @@ -298,7 +298,7 @@ private async Task GetReviewPageModelPropertiesAsync(string id, string revisionI
else
{
var notifcation = new NotificationModel() { Message = $"A revision with ID {revisionId} does not exist for this review.", Level = NotificatonLevel.Warning };
await _signalRHubContext.Clients.Group(User.Identity.Name).SendAsync("RecieveNotification", notifcation);
await _signalRHubContext.Clients.Group(User.GetGitHubLogin()).SendAsync("RecieveNotification", notifcation);
}

}
Expand Down

0 comments on commit 7361064

Please sign in to comment.