mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-17 04:58:46 +00:00
Add reactions, reliable push & session checks
Implements message reactions and reaction packs (domain models, services, admin HTTP API, media processing via ImageSharp and limits) and adds reliable push delivery (ChatPushNotification, ChatPushDispatcher, ChatPushWorker, improved ChatNotificationService). Enhances message reading (ReadChat API, unread counts, concurrency-safe receipts) and tightens session security (access-token session validation in JWT, hub filter, SessionAuthorization). Improves SignalR behavior (session groups, reaction/channel events, hub/error mappings). Adds EF migrations, many controller fixes (Forbid handling, password API), tests (Govor.Server.Tests), docs, CI and tooling updates (Dockerfile → .NET 10, GH Actions matrix for sqlite/postgres, Govor.Server.slnx, global.json), and small infra changes (AutoMapper bump, NullPushProvider, storage/token handling).
This commit is contained in:
@@ -11,6 +11,7 @@ using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Application.Infrastructure.Validators;
|
||||
using Govor.Application.Medias;
|
||||
using Govor.Application.Messages;
|
||||
using Govor.Application.Reactions;
|
||||
using Govor.Application.PingHandler;
|
||||
using Govor.Application.PrivateUserChats;
|
||||
using Govor.Application.Profiles;
|
||||
@@ -68,6 +69,9 @@ public static class ConfigurationProgramExtensions
|
||||
//services.AddScoped<IMessageCommandService, MessageCommandService>();
|
||||
services.AddScoped<IMessageSendingService, MessageSendingService>();
|
||||
services.AddScoped<IMessageReadingService, MessageReadingService>();
|
||||
services.AddScoped<IMessageReactionService, MessageReactionService>();
|
||||
services.AddScoped<IReactionPackService, ReactionPackService>();
|
||||
services.AddSingleton<IReactionMediaProcessor, ReactionMediaProcessor>();
|
||||
services.AddScoped<IMessageEditingService, MessageEditingService>();
|
||||
services.AddScoped<IMessageRemovingService, MessageRemovingService>();
|
||||
services.AddScoped<IVerifyFriendship, VerifyFriendship>();
|
||||
@@ -91,6 +95,8 @@ public static class ConfigurationProgramExtensions
|
||||
// Hubs Infrastructure
|
||||
services.AddScoped<IPrivateChatGroupManager, PrivateChatGroupManager>();
|
||||
services.AddScoped<IChatNotificationService, ChatNotificationService>();
|
||||
services.AddScoped<ChatPushDispatcher>();
|
||||
services.AddHostedService<ChatPushWorker>();
|
||||
services.AddScoped<IConnectionManager, ConnectionManager>();
|
||||
|
||||
services.AddSingleton<IConnectionStore, ConnectionStore>();
|
||||
@@ -98,7 +104,10 @@ public static class ConfigurationProgramExtensions
|
||||
// Pushs
|
||||
services.AddScoped<IPushTokenService, PushTokenService>();
|
||||
services.AddScoped<IPushNotificationService, PushNotificationService>();
|
||||
services.AddSingleton<IPushNotificationProvider, FirebasePushProvider>();
|
||||
services.AddSingleton<IPushNotificationProvider>(sp =>
|
||||
sp.GetRequiredService<IConfiguration>().GetValue("Firebase:Enabled", true)
|
||||
? ActivatorUtilities.CreateInstance<FirebasePushProvider>(sp)
|
||||
: new NullPushProvider());
|
||||
|
||||
|
||||
// Auto Mapper
|
||||
@@ -133,8 +142,8 @@ public static class ConfigurationProgramExtensions
|
||||
|
||||
//options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
|
||||
options.EnableSensitiveDataLogging();
|
||||
options.EnableDetailedErrors();
|
||||
if (configuration.GetValue<bool>("Database:EnableDetailedErrors"))
|
||||
options.EnableDetailedErrors();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using Govor.Contracts.Responses.SignalR;
|
||||
using Govor.Domain.Common;
|
||||
|
||||
namespace Govor.API.Common.Extensions;
|
||||
|
||||
public static class HubResultExtensions
|
||||
{
|
||||
public static HubResult<T> ToHubResult<T>(this Error error) => error.Type switch
|
||||
{
|
||||
ErrorType.NotFound => HubResult<T>.NotFound(error.Message),
|
||||
ErrorType.Forbidden => HubResult<T>.Forbidden(error.Message),
|
||||
ErrorType.Unauthorized => HubResult<T>.Unauthorized(error.Message),
|
||||
ErrorType.Conflict => HubResult<T>.Conflict(error.Message),
|
||||
ErrorType.ServerError => HubResult<T>.Error("Internal server error."),
|
||||
_ => HubResult<T>.BadRequest(error.Message)
|
||||
};
|
||||
}
|
||||
@@ -28,6 +28,7 @@ public static class ResultExtensions
|
||||
ErrorType.Conflict => StatusCodes.Status409Conflict,
|
||||
ErrorType.Unauthorized => StatusCodes.Status401Unauthorized,
|
||||
ErrorType.Forbidden => StatusCodes.Status403Forbidden,
|
||||
ErrorType.ServerError => StatusCodes.Status500InternalServerError,
|
||||
_ => StatusCodes.Status400BadRequest
|
||||
};
|
||||
|
||||
@@ -55,6 +56,7 @@ public static class ResultExtensions
|
||||
ErrorType.Conflict => "Conflict",
|
||||
ErrorType.Unauthorized => "Unauthorized",
|
||||
ErrorType.Forbidden => "Forbidden",
|
||||
ErrorType.ServerError => "Internal Server Error",
|
||||
_ => "Bad Request"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#nullable enable
|
||||
using System.Security.Claims;
|
||||
using Govor.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Govor.API.Common.Extensions;
|
||||
|
||||
public static class SessionAuthorization
|
||||
{
|
||||
public static Task<bool> HasActiveSessionAsync(this GovorDbContext context, ClaimsPrincipal? user)
|
||||
{
|
||||
if (user?.Identity?.IsAuthenticated != true || user.FindFirst("tokenType")?.Value == "refresh" ||
|
||||
!Guid.TryParse(user.FindFirst("userId")?.Value, out var userId) ||
|
||||
!Guid.TryParse(user.FindFirst("sid")?.Value, out var sessionId))
|
||||
return Task.FromResult(false);
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
return context.UserSessions.AsNoTracking().AnyAsync(s => s.Id == sessionId &&
|
||||
s.UserId == userId && !s.IsRevoked && s.ExpiresAt > now);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user