Skip to content

Commit

Permalink
init signalr
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Aug 28, 2023
1 parent 615bf4a commit e0842e0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/web/Client/Features/Chat/LargeChatComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<MudImage Src="@chat.GetChatImage(_currentUser.Id)" loading="lazy" Alt="Avatar" />
</MudAvatar>
<MudText>
@if (_unreadMessages.TryGetValue(chat.Id, out var unreadMessageCount) && unreadMessageCount > 0)
@if (_unreadMessages?.TryGetValue(chat.Id, out var unreadMessageCount) is true && unreadMessageCount > 0)
{
<b>@chat.GetDisplayName(_currentUser.Id) (@unreadMessageCount)</b>
}
Expand Down
1 change: 1 addition & 0 deletions src/web/Client/Jordnaer.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.9" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.10" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.9" />
Expand Down
4 changes: 2 additions & 2 deletions src/web/Server/Features/Chat/ChatApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ async Task<bool> CurrentUserIsNotPartOfChat()
var chatMessages = await context.ChatMessages
.AsNoTracking()
.Where(message => message.ChatId == chatId)
// Oldest messages first, so we get the right order in the chat
.Where(message => message.ChatId == chatId)
// Oldest messages first, so we get the right order in the chat
.OrderBy(message => message.SentUtc)
.Skip(skip)
.Take(take)
Expand Down
11 changes: 11 additions & 0 deletions src/web/Server/Features/Chat/ChatHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.SignalR;

namespace Jordnaer.Server.Features.Chat;

public class ChatHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
}
16 changes: 16 additions & 0 deletions src/web/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Jordnaer.Server.Features.Profile;
using Jordnaer.Server.Features.UserSearch;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.FeatureManagement;
using Serilog;

Expand Down Expand Up @@ -62,8 +63,23 @@

builder.AddMassTransit();

builder.Services.AddSignalR();
if (!builder.Environment.IsDevelopment())
{
builder.Services.AddResponseCompression(options =>
{
options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "application/octet-stream" });
});
}

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
app.UseResponseCompression();
}

app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
Expand Down
2 changes: 1 addition & 1 deletion src/web/Server/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"applicationUrl": "https://localhost:7116;http://localhost:5235",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ConnectionStrings_JordnaerDbContext": "Server=localhost,1433;Database=jordnaer;User ID=sa;Password=b1509e74-7cdf-4575-96c5-70ac47115acc;Persist Security Info=False;TrustServerCertificate=true;"
"ConnectionStrings_JordnaerDbContext": "Server=localhost,1433;Database=jordnaer;User ID=sa;Password=6efe173b-3e33-4d6c-8f50-3e5f7cadd54c;Persist Security Info=False;TrustServerCertificate=true;"
}
}
}
Expand Down

0 comments on commit e0842e0

Please sign in to comment.