Add channel search and subscription

This commit is contained in:
sevenhill
2026-07-07 22:09:18 +03:00
parent b2766ebbe9
commit 0a42e6f860
14 changed files with 421 additions and 4 deletions
@@ -19,4 +19,13 @@ public interface IMaxBridgeClient
Task<MaxActionResult> SetReactionAsync(string externalChatId, string externalMessageId, string? currentText, string emoji, CancellationToken cancellationToken);
Task<MaxActionResult> ClearReactionAsync(string externalChatId, string externalMessageId, string? currentText, string emoji, CancellationToken cancellationToken);
Task<MaxMediaDownload?> DownloadMediaAsync(string remoteUrl, CancellationToken cancellationToken);
Task<IReadOnlyList<MaxChannelSearchResult>> SearchChannelsAsync(string query, CancellationToken cancellationToken)
{
return Task.FromResult<IReadOnlyList<MaxChannelSearchResult>>(Array.Empty<MaxChannelSearchResult>());
}
Task<MaxChatUpdate?> JoinChannelAsync(string link, CancellationToken cancellationToken)
{
return Task.FromResult<MaxChatUpdate?>(null);
}
}
@@ -65,3 +65,11 @@ public sealed record MaxChatPresence(
bool IsTyping,
string? StatusText,
DateTimeOffset UpdatedAt);
public sealed record MaxChannelSearchResult(
string ExternalId,
string Title,
string? AvatarUrl,
string? ChatUrl,
bool IsSubscribed,
string? Description = null);
@@ -108,6 +108,30 @@ public sealed class MockMaxBridgeClient : IMaxBridgeClient
return Task.FromResult<MaxMediaDownload?>(null);
}
public Task<IReadOnlyList<MaxChannelSearchResult>> SearchChannelsAsync(string query, CancellationToken cancellationToken)
{
IReadOnlyList<MaxChannelSearchResult> result = string.IsNullOrWhiteSpace(query)
? []
: [new MaxChannelSearchResult("mock-channel", "Mock channel", null, "mock-channel", false, "Mock MAX channel")];
return Task.FromResult(result);
}
public Task<MaxChatUpdate?> JoinChannelAsync(string link, CancellationToken cancellationToken)
{
return Task.FromResult<MaxChatUpdate?>(new MaxChatUpdate(
"mock-channel",
"Mock channel",
null,
DateTimeOffset.UtcNow,
[],
"Mock channel subscribed",
false,
DateTimeOffset.UtcNow,
null,
MockChatUrl("mock-channel"),
"Channel"));
}
private static string MockChatUrl(string externalChatId)
{
return $"pymax://mock/{Uri.EscapeDataString(externalChatId)}";
@@ -160,6 +160,25 @@ public sealed class WorkerMaxBridgeClient(
}
}
public async Task<IReadOnlyList<MaxChannelSearchResult>> SearchChannelsAsync(string query, CancellationToken cancellationToken)
{
return await SendAsync<IReadOnlyList<MaxChannelSearchResult>>(
HttpMethod.Post,
"/channels/search",
new { query },
cancellationToken)
?? Array.Empty<MaxChannelSearchResult>();
}
public async Task<MaxChatUpdate?> JoinChannelAsync(string link, CancellationToken cancellationToken)
{
return await SendAsync<MaxChatUpdate>(
HttpMethod.Post,
"/channels/join",
new { link },
cancellationToken);
}
private async Task<T?> SendAsync<T>(HttpMethod method, string path, object? body, CancellationToken cancellationToken)
{
try