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; }
private async Task <MastodonPost> GetPost(string postID, MastodonPostContextOptions mastodonPostContextOptions) { var post = BuildPost(postID); await AddContextToMastodonPost(post, mastodonPostContextOptions); return(post); }
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; }
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 }); }
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 }); }
/// <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); }
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); }
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(); } } }
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 }); }
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 }); }
private async Task AddContextToMastodonPosts(IEnumerable <MastodonPost> posts, MastodonPostContextOptions mastodonPostContextOptions) { foreach (var post in posts) { await AddContextToMastodonPost(post, mastodonPostContextOptions); } }
/// <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; }
/// <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); } } }
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; }
public async Task AddContextToMastodonPosts(IEnumerable<MastodonPost> mastodonPosts, MastodonPostContextOptions mastodonPostContextOptions = null) { foreach (var mastodonPost in mastodonPosts) { await AddContextToMastodonPost(mastodonPost, mastodonPostContextOptions); } }