mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Refactor: migrate Core -> Domain and reorganize projects
Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
namespace Govor.Application.Users.UserOnlineStatus;
|
||||
|
||||
public interface IOnlineUserStore
|
||||
{
|
||||
bool AddConnection(Guid userId, string connectionId);
|
||||
bool RemoveConnection(Guid userId, string connectionId);
|
||||
bool IsOnline(Guid userId);
|
||||
IEnumerable<string> GetConnections(Guid userId);
|
||||
IReadOnlyCollection<Guid> GetAllOnlineUsers();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Govor.Application.Users.UserOnlineStatus;
|
||||
|
||||
public interface IUserNotificationScopeService
|
||||
{
|
||||
Task<List<Guid>> GetNotifiedUsers(Guid userId);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Govor.Application.Users.UserOnlineStatus;
|
||||
|
||||
public interface IUserPresenceReader
|
||||
{
|
||||
Task<DateTime?> GetLastSeenAsync(Guid userId);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Govor.Application.Users.UserOnlineStatus;
|
||||
|
||||
public class OnlineUserStore : IOnlineUserStore
|
||||
{
|
||||
private readonly ConcurrentDictionary<Guid, HashSet<string>> _userConnections = new();
|
||||
|
||||
public bool AddConnection(Guid userId, string connectionId)
|
||||
{
|
||||
bool isFirstConnection = false;
|
||||
|
||||
_userConnections.AddOrUpdate(userId,
|
||||
_ => {
|
||||
isFirstConnection = true;
|
||||
return new HashSet<string> { connectionId };
|
||||
},
|
||||
(_, connections) => {
|
||||
lock (connections)
|
||||
{
|
||||
if (connections.Count == 0) isFirstConnection = true;
|
||||
connections.Add(connectionId);
|
||||
}
|
||||
return connections;
|
||||
});
|
||||
|
||||
return isFirstConnection;
|
||||
}
|
||||
|
||||
public bool RemoveConnection(Guid userId, string connectionId)
|
||||
{
|
||||
bool isLastConnection = false;
|
||||
|
||||
if (_userConnections.TryGetValue(userId, out var connections))
|
||||
{
|
||||
lock (connections)
|
||||
{
|
||||
connections.Remove(connectionId);
|
||||
if (connections.Count == 0)
|
||||
{
|
||||
isLastConnection = true;
|
||||
_userConnections.TryRemove(userId, out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isLastConnection;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetConnections(Guid userId)
|
||||
{
|
||||
if (_userConnections.TryGetValue(userId, out var connections))
|
||||
{
|
||||
lock (connections)
|
||||
{
|
||||
return connections.ToList();
|
||||
}
|
||||
}
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
public bool IsOnline(Guid userId)
|
||||
{
|
||||
return _userConnections.TryGetValue(userId, out var connections) && connections.Count > 0;
|
||||
}
|
||||
|
||||
public IReadOnlyCollection<Guid> GetAllOnlineUsers()
|
||||
{
|
||||
return _userConnections.Keys.ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Govor.Application.Friends;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Govor.Application.Users.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)
|
||||
{
|
||||
_logger.LogInformation($"Getting notified users of online/offline action user {userId}");
|
||||
var users = await _friendships.GetFriendsAsync(userId);
|
||||
return users.Select(u => u.Id).ToList();
|
||||
}
|
||||
|
||||
/*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");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Govor.Application.Users.UserOnlineStatus;
|
||||
|
||||
public class UserPresenceReader : IUserPresenceReader
|
||||
{
|
||||
public Task<DateTime?> GetLastSeenAsync(Guid userId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user