116 lines
4.6 KiB
C#
116 lines
4.6 KiB
C#
namespace QMax.Api.Infrastructure.Max;
|
|
|
|
public sealed class MockMaxBridgeClient : IMaxBridgeClient
|
|
{
|
|
private readonly List<MaxChatUpdate> _updates =
|
|
[
|
|
new MaxChatUpdate(
|
|
"mock-qmax",
|
|
"QMAX smoke chat",
|
|
null,
|
|
DateTimeOffset.UtcNow,
|
|
[
|
|
new MaxMessageUpdate(
|
|
"mock-message-1",
|
|
"max",
|
|
"MAX",
|
|
false,
|
|
"Mock mode is active. Switch QMax:MaxMode to Playwright for real web.max.ru.",
|
|
DateTimeOffset.UtcNow)
|
|
])
|
|
];
|
|
|
|
public Task<MaxBridgeStatus> GetStatusAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxBridgeStatus("Mock", true, "Authorized", "MockReady", null, "Mock", null, DateTimeOffset.UtcNow));
|
|
}
|
|
|
|
public Task<MaxBridgeStatus> BeginPhoneLoginAsync(string phoneNumber, CancellationToken cancellationToken)
|
|
{
|
|
return GetStatusAsync(cancellationToken);
|
|
}
|
|
|
|
public Task<MaxBridgeStatus> SubmitLoginCodeAsync(string code, CancellationToken cancellationToken)
|
|
{
|
|
return GetStatusAsync(cancellationToken);
|
|
}
|
|
|
|
public Task<MaxBrowserSnapshot> GetSnapshotAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxBrowserSnapshot(null, "Mock", "Mock MAX bridge", "", DateTimeOffset.UtcNow));
|
|
}
|
|
|
|
public Task<IReadOnlyList<MaxChatUpdate>> FetchUpdatesAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult<IReadOnlyList<MaxChatUpdate>>(_updates);
|
|
}
|
|
|
|
public Task<MaxChatUpdate?> FetchChatHistoryAsync(string externalChatId, string? chatUrl, CancellationToken cancellationToken)
|
|
{
|
|
var update = _updates.FirstOrDefault(x => x.ExternalId == externalChatId);
|
|
return Task.FromResult(update);
|
|
}
|
|
|
|
public Task<MaxChatPresence?> FetchChatPresenceAsync(string externalChatId, string? chatUrl, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult<MaxChatPresence?>(new MaxChatPresence(false, null, DateTimeOffset.UtcNow));
|
|
}
|
|
|
|
public Task<MaxChatUrlResult> ResolveChatUrlAsync(string externalChatId, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxChatUrlResult(true, MockChatUrl(externalChatId), null));
|
|
}
|
|
|
|
public Task<MaxActionResult> ClearChatHistoryAsync(string externalChatId, string? chatUrl, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxActionResult(true, null));
|
|
}
|
|
|
|
public Task<MaxActionResult> DeleteChatAsync(string externalChatId, string? chatUrl, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxActionResult(
|
|
false,
|
|
"Chat deletion is disabled because MAX does not remove chats from the web client."));
|
|
}
|
|
|
|
public Task<MaxSendResult> SendTextAsync(string externalChatId, string? chatUrl, string text, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxSendResult(true, $"mock-out-{Guid.NewGuid():N}", null, MockChatUrl(externalChatId)));
|
|
}
|
|
|
|
public Task<MaxSendResult> SendAttachmentAsync(string externalChatId, string? chatUrl, string path, string caption, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxSendResult(true, $"mock-file-{Guid.NewGuid():N}", null, MockChatUrl(externalChatId)));
|
|
}
|
|
|
|
public Task<MaxActionResult> EditMessageAsync(string externalChatId, string externalMessageId, string? currentText, string text, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxActionResult(true, null));
|
|
}
|
|
|
|
public Task<MaxActionResult> DeleteMessageAsync(string externalChatId, string externalMessageId, string? currentText, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxActionResult(true, null));
|
|
}
|
|
|
|
public Task<MaxActionResult> SetReactionAsync(string externalChatId, string externalMessageId, string? currentText, string emoji, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxActionResult(true, null));
|
|
}
|
|
|
|
public Task<MaxActionResult> ClearReactionAsync(string externalChatId, string externalMessageId, string? currentText, string emoji, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new MaxActionResult(true, null));
|
|
}
|
|
|
|
public Task<MaxMediaDownload?> DownloadMediaAsync(string remoteUrl, CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult<MaxMediaDownload?>(null);
|
|
}
|
|
|
|
private static string MockChatUrl(string externalChatId)
|
|
{
|
|
return $"https://web.max.ru/mock/{Uri.EscapeDataString(externalChatId)}";
|
|
}
|
|
}
|