diff --git a/ButterSTT.Tests/MessageSystem/MessageQueueTests.cs b/ButterSTT.Tests/MessageSystem/MessageQueueTests.cs index d753417..b8f2fe0 100644 --- a/ButterSTT.Tests/MessageSystem/MessageQueueTests.cs +++ b/ButterSTT.Tests/MessageSystem/MessageQueueTests.cs @@ -154,6 +154,38 @@ public void PageRealtimeHardWordPersistTest() Assert.Equal("that is just now finished!", curMessage); } + [Fact()] + public void PageRealtimeWordTest() + { + var queue = new MessageQueue + { + MessageLength = 26, + DequeueSystem = DequeueSystems.Pagination, + RealtimeQueuePadding = 0, + WordTime = TimeSpan.Zero, + HardWordTime = TimeSpan.MaxValue + }; + + var firstMessage = "Testing the queue system."; + queue.CurParagraph = EnglishTextParser.ParseParagraph(firstMessage); + queue.FinishCurrentParagraph(); + var curMessage = queue.GetCurrentMessage(); + _output.WriteLine($"First message: \"{curMessage}\""); + Assert.Equal(firstMessage, curMessage); + + var secondMessage = "Second test."; + queue.CurParagraph = EnglishTextParser.ParseParagraph(secondMessage); + curMessage = queue.GetCurrentMessage(); + _output.WriteLine($"Second message: \"{curMessage}\""); + Assert.Equal($"-system. {secondMessage}", curMessage); + + var thirdMessage = "Third test."; + queue.CurParagraph = EnglishTextParser.ParseParagraph(thirdMessage); + curMessage = queue.GetCurrentMessage(); + _output.WriteLine($"Second message expired: \"{curMessage}\""); + Assert.Equal($"-system. {thirdMessage}", curMessage); + } + [Theory()] [InlineData(DequeueSystems.Scrolling)] [InlineData(DequeueSystems.Pagination)] diff --git a/ButterSTT/MessageSystem/MessageQueue.cs b/ButterSTT/MessageSystem/MessageQueue.cs index 150077d..4da896b 100644 --- a/ButterSTT/MessageSystem/MessageQueue.cs +++ b/ButterSTT/MessageSystem/MessageQueue.cs @@ -297,7 +297,9 @@ private void ExpireWords() } private bool IsMessageFull => - _wordQueue.TryPeek(out var word) && _curMessageLength + word.Length > MessageLength; + (_wordQueue.TryPeek(out var word) && word.Length > AvailableMessageLength) + || ParagraphWordEnumerator().Select(w => w.Length).FirstOrDefault(0) + > AvailableMessageLength; private void PaginateWords() { @@ -305,8 +307,8 @@ private void PaginateWords() var hardExpired = DateTime.UtcNow >= lastWord.HardExpiryTime; // Wait until the last word on the full page is expired if ( - (!hardExpired || _hadTextLast) - && (!IsMessageFull || DateTime.UtcNow < lastWord.ExpiryTime) + _hadTextLast + || (!hardExpired && (DateTime.UtcNow < lastWord.ExpiryTime || !IsMessageFull)) ) return;