Exemplo n.º 1
0
        public CommandResult <SearchMastodonPostsCommandResultData> SearchPosts(SearchMastodonPostsCommand searchMastodonPostsCommand)
        {
            return(ProcessCommand <SearchMastodonPostsCommandResultData>(result =>
            {
                if (searchMastodonPostsCommand.IsGlobalSearch)
                {
                    throw new UserErrorException("Please specify at least one search criterion");
                }

                var pageInformation = new PageInformation();
                result.Data = new SearchMastodonPostsCommandResultData
                {
                    Posts = GetPosts(searchMastodonPostsCommand, pageInformation).Synchronously(),
                    PageInformation = pageInformation
                };
            }));
        }
Exemplo n.º 2
0
        private async Task <IList <MastodonPost> > GetPosts(SearchMastodonPostsCommand searchMastodonPostsCommand, PageInformation refPageInformtation)
        {
            var posts = null as Dictionary <string, MastodonPost>;

            if (!string.IsNullOrWhiteSpace(searchMastodonPostsCommand.PostID))
            {
                posts = await FilterByPostID(posts, searchMastodonPostsCommand.PostID);
            }
            if (!string.IsNullOrWhiteSpace(searchMastodonPostsCommand.ByAuthorMastodonUserID))
            {
                posts = await FilterByAuthorUserID(posts, searchMastodonPostsCommand.ByAuthorMastodonUserID, searchMastodonPostsCommand.PagingOptions?.SinceID, searchMastodonPostsCommand.PagingOptions?.MaxID, refPageInformtation);
            }
            if (searchMastodonPostsCommand.OnlyOnActiveUserTimeline)
            {
                posts = await FilterByOnActiveUserTimeline(posts, searchMastodonPostsCommand.PagingOptions?.SinceID, searchMastodonPostsCommand.PagingOptions?.MaxID, refPageInformtation);
            }
            if (searchMastodonPostsCommand.OnlyOnPublicTimeline)
            {
                posts = await FilterByOnPublicTimeline(posts, searchMastodonPostsCommand.PagingOptions?.SinceID, searchMastodonPostsCommand.PagingOptions?.MaxID, refPageInformtation);
            }
            if (!string.IsNullOrWhiteSpace(searchMastodonPostsCommand.HavingHashTag))
            {
                posts = await FilterByHashTag(posts, searchMastodonPostsCommand.HavingHashTag, searchMastodonPostsCommand.PagingOptions?.SinceID, searchMastodonPostsCommand.PagingOptions?.MaxID, refPageInformtation);
            }

            await _mastodonApiWrapper.AddContextToMastodonPosts
            (
                posts.Values,
                new MastodonPostContextOptions
            {
                IncludeAncestors   = searchMastodonPostsCommand.IncludeAncestors,
                IncludeDescendants = searchMastodonPostsCommand.IncludeDescendants
            }
            );

            return(posts.Values.ToArray());
        }