Commit d7b5356b authored by Robert Rudman's avatar Robert Rudman

Break messages into smaller parts when processing if the message becomes too long

parent e3be233c
Pipeline #41495839 passed with stages
in 4 minutes and 30 seconds
......@@ -112,7 +112,29 @@ namespace Rodgort.Services
if (!questionIdList.Any())
return;
await chatClient.SendMessage(ChatSite.StackOverflow, Headquarters, $"Processing {string.Join(", ", questionIdList)} from room {roomId}");
var messages = new List<string>();
var tempIds = new List<int>();
foreach (var questionId in questionIdList)
{
var message = GetProcessingMessage(tempIds.Concat(new[] {questionId}));
if (message.Length > ChatClient.MAX_MESSAGE_LENGTH)
{
messages.Add(GetProcessingMessage(tempIds));
tempIds.Clear();
}
tempIds.Add(questionId);
}
if (tempIds.Any())
messages.Add(GetProcessingMessage(tempIds));
string GetProcessingMessage(IEnumerable<int> qIds)
{
return $"Processing {string.Join(", ", qIds)} from room {roomId}";
}
foreach (var message in messages)
await chatClient.SendMessage(ChatSite.StackOverflow, Headquarters, message);
var apiClient = _serviceProvider.GetRequiredService<ApiClient>();
var revisions = await apiClient.Revisions("stackoverflow.com", questionIdList);
......
......@@ -13,6 +13,8 @@ namespace StackExchangeChat
{
public class ChatClient
{
public const int MAX_MESSAGE_LENGTH = 500;
private readonly SiteAuthenticator _siteAuthenticator;
private readonly HttpClientWithHandler _httpClient;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment