mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-17 12:59:25 +00:00
Expose chat read positions and E2EE errors
Add optional chat activity and read-position details to the unread-count endpoint. Return stable E2EE rejection codes for stale timestamps and untrusted signing devices, with tests for both behaviors.
This commit is contained in:
@@ -44,8 +44,15 @@ public class MessageReadController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("unread-count")]
|
||||
public async Task<IActionResult> GetUnreadCount(Guid chatId, [FromQuery] RecipientType recipientType)
|
||||
public async Task<IActionResult> GetUnreadCount(Guid chatId, [FromQuery] RecipientType recipientType,
|
||||
[FromQuery] bool includeActivity = false, [FromQuery] bool includeReadPosition = false)
|
||||
{
|
||||
if (includeActivity)
|
||||
{
|
||||
var activity = await _reader.GetChatActivityAsync(_currentUser.GetCurrentUserId(), chatId, recipientType,
|
||||
includeReadPosition);
|
||||
return activity.IsFailure ? activity.ToActionResult() : Ok(activity.Value);
|
||||
}
|
||||
var result = await _reader.GetUnreadCountAsync(_currentUser.GetCurrentUserId(), chatId, recipientType);
|
||||
return result.IsFailure ? result.ToActionResult() : Ok(new { unreadCount = result.Value });
|
||||
}
|
||||
|
||||
@@ -101,7 +101,16 @@ public class ChatsHub : Hub
|
||||
var result = await _messageSendingService.SendMessageAsync(sendParams);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
if (result.Exception is UnauthorizedAccessException { Message: E2eeProtocol.SigningDeviceRejectedError })
|
||||
{
|
||||
_logger.LogWarning("Message rejected for {UserId}: {Reason}", userId, E2eeProtocol.SigningDeviceRejectedError);
|
||||
return HubResult<UserMessageResponse>.Forbidden(E2eeProtocol.SigningDeviceRejectedError);
|
||||
}
|
||||
if (result.Exception is ArgumentException { Message: E2eeProtocol.TimestampOutOfRangeError or E2eeProtocol.DevicesChangedError } rejection)
|
||||
_logger.LogWarning("Message rejected for {UserId}: {Reason}", userId, rejection.Message);
|
||||
throw result.Exception ?? new InvalidOperationException("Failed to send message");
|
||||
}
|
||||
|
||||
var response = MapToResponse(result.Message, request.ReplyToMessageId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user