mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
31fdf4cb37
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.
54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
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");
|
|
}
|
|
}*/
|
|
} |