Esempio n. 1
0
 public async Task<MastodonPost> GetPost(string postID, MastodonPostContextOptions mastodonPostContextOptions = null)
 {
     var mastodonClient = GetOrCreateMastodonClient();
     var post = (await mastodonClient.GetStatus(postID.ToLong())).ToPost();
     await AddContextToMastodonPost(post, mastodonPostContextOptions);
     return post;
 }
Esempio n. 2
0
        private async Task <MastodonPost> GetPost(string postID, MastodonPostContextOptions mastodonPostContextOptions)
        {
            var post = BuildPost(postID);

            await AddContextToMastodonPost(post, mastodonPostContextOptions);

            return(post);
        }
Esempio n. 3
0
 public async Task<PagedList<MastodonPost>> GetPostsOnPublicTimeline(MastodonPostContextOptions mastodonPostContextOptions = null, PagingOptions pagingOptions = null)
 {
     var effectivePagingOptions = pagingOptions ?? new PagingOptions();
     var mastodonClient = GetOrCreateMastodonClient();
     var mastodonPostsApiResult = await mastodonClient.GetPublicTimeline(effectivePagingOptions.MaxID.ToNullableLong(), effectivePagingOptions.SinceID.ToNullableLong(), effectivePagingOptions.Limit, true);
     var result = PagedList<MastodonPost>.Create(mastodonPostsApiResult, s => s.ToPost());
     await AddContextToMastodonPosts(result.Elements, mastodonPostContextOptions);
     return result;
 }
Esempio n. 4
0
        private async Task <PagedList <MastodonPost> > GetPostsOnPublicTimeline(MastodonPostContextOptions mastodonPostContextOptions, PagingOptions pagingOptions)
        {
            var posts = _postsAndAuthors.Where(p => p.Value != ActiveUserID).Select(p => BuildPost(p.Key)).ToArray();

            await AddContextToMastodonPosts(posts, mastodonPostContextOptions);

            return(new PagedList <MastodonPost> {
                Elements = posts
            });
        }
Esempio n. 5
0
        private async Task <PagedList <MastodonPost> > GetPostsOnActiveUserTimeline(MastodonPostContextOptions mastodonPostContextOptions, PagingOptions pagingOptions)
        {
            var authorUserIDs = GetFollowingUserIDs(ActiveUserID).ToHashSet();
            var posts         = _postsAndAuthors.Where(p => authorUserIDs.Contains(p.Value)).Select(p => BuildPost(p.Key)).ToArray();

            await AddContextToMastodonPosts(posts, mastodonPostContextOptions);

            return(new PagedList <MastodonPost> {
                Elements = posts
            });
        }
Esempio n. 6
0
        /// <summary>
        /// private helper method to get notifications for the active Mastodon user
        /// </summary>
        /// <param name="getMastodonNotificationsCommand"></param>
        /// <param name="refPageInformtation"></param>
        /// <returns></returns>
        private async Task <IList <MastodonNotification> > GetNotifications(GetMastodonNotificationsCommand getMastodonNotificationsCommand, PageInformation refPageInformtation)
        {
            var mastodonPostContexOptions = new MastodonPostContextOptions {
                IncludeAncestors = getMastodonNotificationsCommand.IncludeAncestors, IncludeDescendants = getMastodonNotificationsCommand.IncludeDescendants
            };
            var result = await _mastodonApiWrapper.GetActiveUserNotifications(mastodonPostContexOptions, getMastodonNotificationsCommand.PagingOptions);

            // I beleive this is all that is needed in this context for updated the refPagedList?
            UpdatedRefPagedList(refPageInformtation, result);
            return(result.Elements);
        }
Esempio n. 7
0
        private Task AddContextToMastodonPost(MastodonPost post, MastodonPostContextOptions mastodonPostContextOptions)
        {
            var effectiveMastodonPostContextOptions = mastodonPostContextOptions ?? new MastodonPostContextOptions();

            if (effectiveMastodonPostContextOptions.IncludeAncestors)
            {
                post.Ancestors = GetAncestorPostIDs(post.Id).Select(BuildPost).ToList();
            }
            if (effectiveMastodonPostContextOptions.IncludeDescendants)
            {
                post.Descendants = GetDescendantPostID(post.Id).Select(BuildPost).ToList();
            }
            return(Task.CompletedTask);
        }
Esempio n. 8
0
        public async Task AddContextToMastodonPost(MastodonPost mastodonPost, MastodonPostContextOptions mastodonPostContextOptions = null)
        {
            var effectiveMastodonPostContextOptions = mastodonPostContextOptions ?? new MastodonPostContextOptions();
            var mastodonClient = GetOrCreateMastodonClient();

            if (effectiveMastodonPostContextOptions.IncludeAncestors || effectiveMastodonPostContextOptions.IncludeDescendants)
            {
                var statusContext = await mastodonClient.GetStatusContext(mastodonPost.Id.ToLong());
                if (effectiveMastodonPostContextOptions.IncludeAncestors)
                {
                    mastodonPost.Ancestors = statusContext.Ancestors.Select(s => s.ToPost()).ToList();
                }
                if (effectiveMastodonPostContextOptions.IncludeDescendants)
                {
                    mastodonPost.Descendants = statusContext.Descendants.Select(s => s.ToPost()).ToList();
                }
            }
        }
Esempio n. 9
0
        private async Task <PagedList <MastodonPost> > GetPostsByHashTag(string hashTag, MastodonPostContextOptions mastodonPostContextOptions, PagingOptions pagingOptions)
        {
            var posts = _postsAndAuthors.Keys.Select(BuildPost).Where(p => p.Content.Contains(hashTag, StringComparison.OrdinalIgnoreCase)).ToArray();

            await AddContextToMastodonPosts(posts, mastodonPostContextOptions);

            return(new PagedList <MastodonPost> {
                Elements = posts
            });
        }
Esempio n. 10
0
        private async Task <PagedList <MastodonPost> > GetPostsByAuthorUserID(string authorUserID, MastodonPostContextOptions mastodonPostContextOptions, PagingOptions pagingOptions)
        {
            var posts = _postsAndAuthors.Where(p => p.Value == authorUserID).Select(p => BuildPost(p.Key)).ToArray();

            await AddContextToMastodonPosts(posts, mastodonPostContextOptions);

            return(new PagedList <MastodonPost> {
                Elements = posts
            });
        }
Esempio n. 11
0
 private async Task AddContextToMastodonPosts(IEnumerable <MastodonPost> posts, MastodonPostContextOptions mastodonPostContextOptions)
 {
     foreach (var post in posts)
     {
         await AddContextToMastodonPost(post, mastodonPostContextOptions);
     }
 }
Esempio n. 12
0
 /// <summary>
 /// Gets the lastest notifications for the active Mastodon user
 /// </summary>
 /// <param name="mastodonPostContextOptions"></param>
 /// <param name="pagingOptions"></param>
 /// <returns></returns>
 public async Task<PagedList<MastodonNotification>> GetActiveUserNotifications(MastodonPostContextOptions mastodonPostContextOptions = null, PagingOptions pagingOptions = null)
 {
     var effectivePagingOptions = pagingOptions ?? new PagingOptions();
     var mastodonClient = GetOrCreateMastodonClient();
     var mastodonNotificationsApiResult = await mastodonClient.GetNotifications(effectivePagingOptions.MaxID.ToNullableLong(), effectivePagingOptions.SinceID.ToNullableLong(), effectivePagingOptions.Limit);
     var result = PagedList<MastodonNotification>.Create(mastodonNotificationsApiResult, s => s.ToMastodonNotification());
     await AddContextToMastodonNotificationsPosts(result.Elements, mastodonPostContextOptions);
     return result;
 }
Esempio n. 13
0
 /// <summary>
 /// Goes through each notification in a list of MastodonNotifications and adds context to each Post,
 /// if the notification has a Post
 /// </summary>
 /// <param name="mastodonNotifications"></param>
 /// <param name="mastodonPostContextOptions"></param>
 /// <returns></returns>
 public async Task AddContextToMastodonNotificationsPosts(IEnumerable<MastodonNotification> mastodonNotifications, MastodonPostContextOptions mastodonPostContextOptions = null)
 {
     foreach (var mastodonNotification in mastodonNotifications)
     {
         if (mastodonNotification.Status != null)
         {
             await AddContextToMastodonPost(mastodonNotification.Status, mastodonPostContextOptions);
         }
     }
 }
Esempio n. 14
0
 public async Task<PagedList<MastodonPost>> GetPostsByAuthorUserID(string authorMastodonUserID, MastodonPostContextOptions mastodonPostContextOptions = null, PagingOptions pagingOptions = null)
 {
     var effectivePagingOptions = pagingOptions ?? new PagingOptions();
     var mastodonClient = GetOrCreateMastodonClient();
     var mastodonPostsApiResult = await mastodonClient.GetAccountStatuses(authorMastodonUserID.ToLong(), effectivePagingOptions.MaxID.ToNullableLong(), effectivePagingOptions.SinceID.ToNullableLong(), effectivePagingOptions.Limit, false, false);
     var result = PagedList<MastodonPost>.Create(mastodonPostsApiResult, s => s.ToPost());
     await AddContextToMastodonPosts(result.Elements, mastodonPostContextOptions);
     return result;
 }
Esempio n. 15
0
 public async Task AddContextToMastodonPosts(IEnumerable<MastodonPost> mastodonPosts, MastodonPostContextOptions mastodonPostContextOptions = null)
 {
     foreach (var mastodonPost in mastodonPosts)
     {
         await AddContextToMastodonPost(mastodonPost, mastodonPostContextOptions);
     }
 }