Код: Выделить всё
private static IChannelClient ChannelClient
{
get
{
var config = ServiceLocator.GetService();
var clientFactory = new StreamClientFactory(config.ApiKey, config.ApiSecret);
return clientFactory.GetChannelClient();
}
}
Код: Выделить всё
public async Task GetChannelMessages(string channelId)
{
try
{
var channel = await ChannelClient.GetOrCreateAsync("messaging", //channel id is: 4a20bbb1-63f9-46f7-80d3-08dd51a1dfad
channelId,
new ChannelGetRequest
{
MessagesPagination = new MessagePaginationParams { Limit = 50, Offset = 0 },
MembersPagination = new PaginationParams { Limit = 10, Offset = 0 },
WatchersPagination = new PaginationParams { Limit = 20, Offset = 0 }
});
return channel.Messages.Select(x => new ChatMessageDto //channel.Messages is always empty here
{
StreamMessageId = x.Id,
CreatedBy = x.User.Id,
CreatedDate = x.CreatedAt,
MessageText = x.Text,
ChannelId = channel.Channel.Id
}).ToArray();
}
catch (Exception ex)
{
Logger.LogError(ex, $"Failed to get messages for channel id: {channelId} at {DateTimeOffset.UtcNow}");
return [];
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... n-response