Add user online presence tracking and notification

Introduced interfaces and services for tracking user online status, including IOnlineUserStore, IUserNotificationScopeService, and IUserPresenceReader. Added PresenceHub for real-time presence updates via SignalR. Updated OnlinePingingController to use new services and return online status and last seen. Extended UserDto with IsOnline property. Updated dependency injection and privacy settings enum. Removed obsolete IUserPresenceService.
This commit is contained in:
Artemy
2025-07-23 21:07:29 +07:00
parent cbff5857e7
commit 31fdf4cb37
13 changed files with 231 additions and 11 deletions
@@ -0,0 +1,54 @@
using Govor.Application.Interfaces.Friends;
using Govor.Application.Interfaces.UserOnlineStatus;
using Govor.Data.Repositories.Exceptions;
using Microsoft.Extensions.Logging;
namespace Govor.Application.Services.UserOnlineStatus;
public class UserNotificationScopeService : IUserNotificationScopeService
{
private readonly ILogger<UserNotificationScopeService> _logger;
private readonly IFriendshipService _friendships;
public UserNotificationScopeService(ILogger<UserNotificationScopeService> logger, IFriendshipService friendships)
{
_logger = logger;
_friendships = friendships;
}
public async Task<List<Guid>> GetNotifiedUsers(Guid userId)
{
try
{
_logger.LogInformation($"Getting notified users of online/offline action user {userId}");
var users = await _friendships.GetFriendsAsync(userId);
return users.Select(u => u.Id).ToList();
}
catch (NotFoundByKeyException<Guid> ex)
{
_logger.LogError(ex, ex.Message);
throw new InvalidOperationException("User not found");
}
}
/*public async Task SetWasOnlineAsync(Guid userId, DateTime when)
{
try
{
_logger.LogInformation("Set was-online for user {UserId}", userId);
var user = await _users.FindByIdAsync(userId);
user.WasOnline = when;
await _users.UpdateAsync(user);
}
catch (NotFoundByKeyException<Guid> ex)
{
_logger.LogError(ex, ex.Message);
throw new InvalidOperationException("User not found");
}
catch (UpdateException ex)
{
_logger.LogError(ex, "Failed to set WasOnline for user {UserId} at {Time}", userId, when);
throw new InvalidOperationException("Something went wrong when trying to set was-online for user");
}
}*/
}