public async IAsyncEnumerable <MessageContentGrpcModel> GetMessagesFromMessageId(string topicId, long fromMessageId,
                                                                                         int maxMessagesAmount, string reason)
        {
            var pageId = MessagesContentPagesUtils.GetPageId(fromMessageId);


            var maxPageId = pageId.Value + 2;

            var messageNo = 0;

            while (pageId.Value < maxPageId)
            {
                var page = await TryGetPageAsync(topicId, pageId, reason);

                foreach (var message in page.GetMessages())
                {
                    if (message.MessageId >= fromMessageId)
                    {
                        yield return(message);

                        messageNo++;
                    }

                    if (messageNo >= maxMessagesAmount)
                    {
                        yield break;
                    }
                }

                pageId = new MessagePageId(pageId.Value + 1);
            }
        }
        public async IAsyncEnumerable <MessageContentGrpcModel> GetMessagesByDateAsync(string topicId, DateTime fromDate, string reason)
        {
            var messageId = await GetMessageIsByDateAsync(topicId, fromDate);

            if (messageId <= 0)
            {
                yield break;
            }

            var pageId = MessagesContentPagesUtils.GetPageId(messageId);

            var maxPageId = pageId.Value + 2;

            while (pageId.Value <= maxPageId)
            {
                var page = await TryGetPageAsync(topicId, pageId, reason);

                foreach (var message in page.GetMessages())
                {
                    if (message.Created >= fromDate)
                    {
                        yield return(message);
                    }
                }

                pageId = pageId.NextPage();
            }
        }
        public async Task <(MessageContentGrpcModel message, IMessageContentPage page)> TryGetMessageAsync(string topicId, long messageId, string reason)
        {
            var pageId = MessagesContentPagesUtils.GetPageId(messageId);

            var page = await TryGetPageAsync(topicId, pageId, reason);

            return(page?.TryGet(messageId), page);
        }