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:
Artemy
2026-11-15 21:26:00 +07:00
parent def724e0ee
commit 31d704712c
9 changed files with 108 additions and 8 deletions
@@ -2,6 +2,7 @@ using AutoMapper;
using Govor.API.Common.SignalR.Helpers;
using Govor.API.Hubs;
using Govor.API.Hubs.Infrastructure;
using Govor.Application.E2ee;
using Govor.Application.Exceptions.VerifyFriendship;
using Govor.Application.Infrastructure.Common;
using Govor.Application.Messages;
@@ -106,6 +107,21 @@ public class ChatsHubTests
Assert.That((await _hub.Send(new(){EncryptedContent="cipher"})).Status,Is.EqualTo(HubResultStatus.BadRequest));
}
[TestCase(E2eeProtocol.SigningDeviceRejectedError, HubResultStatus.Forbidden)]
[TestCase(E2eeProtocol.TimestampOutOfRangeError, HubResultStatus.BadRequest)]
[TestCase(E2eeProtocol.DevicesChangedError, HubResultStatus.BadRequest)]
public async Task SendReturnsSafeE2eeRejectionCodeWithoutNotifying(string code, HubResultStatus status)
{
Exception error = status == HubResultStatus.Forbidden
? new UnauthorizedAccessException(code) : new ArgumentException(code);
_send.Setup(x => x.SendMessageAsync(It.IsAny<SendMessage>()))
.ReturnsAsync(new SendMessageResult(false, error, null!));
var response = await _hub.Send(new() { RecipientId = _chat, EncryptedContent = "cipher" });
Assert.That(response.Status, Is.EqualTo(status));
Assert.That(response.ErrorMessage, Is.EqualTo(code));
_notifier.VerifyNoOtherCalls();
}
[Test]
public async Task ReadMapsCurrentReadersViewAndNotifies()
{