#nullable enable
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
-using OpenTween.Setting;
using OpenTween.SocialProtocol;
-using OpenTween.SocialProtocol.Twitter;
namespace OpenTween.Models
{
public override async Task RefreshAsync(ISocialAccount account, bool backward, IProgress<string> progress)
{
- if (account is not TwitterAccount twAccount)
- throw new ArgumentException($"Invalid account type: {account.AccountType}", nameof(account));
-
progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19);
var firstLoad = !this.IsFirstLoadCompleted;
+ var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, backward, firstLoad);
+ var cursor = backward ? this.CursorBottom : this.CursorTop;
- await twAccount.Legacy.GetFavoritesApi(this, backward, firstLoad)
+ var response = await account.Client.GetFavoritesTimeline(count, cursor, firstLoad)
.ConfigureAwait(false);
+ foreach (var post in response.Posts)
+ TabInformations.GetInstance().AddPost(post);
+
TabInformations.GetInstance().DistributePosts();
+ if (response.CursorTop != null && !backward)
+ this.CursorTop = response.CursorTop;
+
+ if (response.CursorBottom != null)
+ this.CursorBottom = response.CursorBottom;
+
if (firstLoad)
this.IsFirstLoadCompleted = true;
public Task<TimelineResponse> GetMentionsTimeline(int count, IQueryCursor? cursor, bool firstLoad);
+ public Task<TimelineResponse> GetFavoritesTimeline(int count, IQueryCursor? cursor, bool firstLoad);
+
public Task<TimelineResponse> GetSearchTimeline(string query, string lang, int count, IQueryCursor? cursor, bool firstLoad);
public Task<PostClass[]> GetRelatedPosts(PostClass targetPost, bool firstLoad);
public Task<TimelineResponse> GetMentionsTimeline(int count, IQueryCursor? cursor, bool firstLoad)
=> throw this.CreateException();
+ public Task<TimelineResponse> GetFavoritesTimeline(int count, IQueryCursor? cursor, bool firstLoad)
+ => throw this.CreateException();
+
public Task<TimelineResponse> GetSearchTimeline(string query, string lang, int count, IQueryCursor? cursor, bool firstLoad)
=> throw this.CreateException();
return new(posts, cursorTop, cursorBottom);
}
+ public async Task<TimelineResponse> GetFavoritesTimeline(int count, IQueryCursor? cursor, bool firstLoad)
+ {
+ this.account.Legacy.CheckAccountState();
+
+ var request = new LikesRequest
+ {
+ UserId = this.account.AccountState.UserId,
+ Count = count,
+ Cursor = cursor?.As<TwitterGraphqlCursor>(),
+ };
+
+ var response = await request.Send(this.account.Connection)
+ .ConfigureAwait(false);
+
+ var statuses = response.ToTwitterStatuses();
+ var cursorTop = response.CursorTop;
+ var cursorBottom = response.CursorBottom;
+
+ var posts = this.account.Legacy.CreatePostsFromJson(statuses, firstLoad);
+ posts = this.account.Legacy.FilterNoRetweetUserPosts(posts);
+
+ return new(posts, cursorTop, cursorBottom);
+ }
+
public async Task<TimelineResponse> GetSearchTimeline(string query, string lang, int count, IQueryCursor? cursor, bool firstLoad)
{
this.account.Legacy.CheckAccountState();
return new(posts, cursorTop, cursorBottom);
}
+ public async Task<TimelineResponse> GetFavoritesTimeline(int count, IQueryCursor? cursor, bool firstLoad)
+ {
+ this.account.Legacy.CheckAccountState();
+
+ var (sinceId, maxId) = GetCursorParams(cursor);
+
+ var statuses = await this.account.Legacy.Api.FavoritesList(count, maxId, sinceId)
+ .ConfigureAwait(false);
+
+ var (cursorTop, cursorBottom) = GetCursorFromResponse(statuses);
+ var posts = this.account.Legacy.CreatePostsFromJson(statuses, firstLoad);
+ posts = this.account.Legacy.FilterNoRetweetUserPosts(posts);
+
+ return new(posts, cursorTop, cursorBottom);
+ }
+
public async Task<TimelineResponse> GetSearchTimeline(string query, string lang, int count, IQueryCursor? cursor, bool firstLoad)
{
this.account.Legacy.CheckAccountState();
return posts.ToArray();
}
- public async Task GetFavoritesApi(FavoritesTabModel tab, bool backward, bool firstLoad)
- {
- this.CheckAccountState();
-
- var count = GetApiResultCount(MyCommon.WORKERTYPE.Favorites, backward, firstLoad);
-
- TwitterStatus[] statuses;
- if (this.Api.AuthType == APIAuthType.TwitterComCookie)
- {
- var cursor = backward ? tab.CursorBottom : tab.CursorTop;
- var request = new LikesRequest
- {
- UserId = this.UserId,
- Count = count,
- Cursor = cursor?.As<TwitterGraphqlCursor>(),
- };
- var response = await request.Send(this.Api.Connection)
- .ConfigureAwait(false);
-
- statuses = response.ToTwitterStatuses();
-
- tab.CursorBottom = response.CursorBottom;
-
- if (!backward)
- tab.CursorTop = response.CursorTop;
- }
- else
- {
- var maxId = backward ? tab.CursorBottom : null;
-
- statuses = await this.Api.FavoritesList(count, maxId: maxId?.As<TwitterStatusId>())
- .ConfigureAwait(false);
-
- if (statuses.Length > 0)
- {
- var min = statuses.Select(x => new TwitterStatusId(x.IdStr)).Min();
- tab.CursorBottom = new QueryCursor<TwitterStatusId>(CursorType.Bottom, min);
- }
- }
-
- var posts = this.CreatePostsFromJson(statuses, firstLoad);
- posts = this.FilterNoRetweetUserPosts(posts);
-
- foreach (var post in posts)
- TabInformations.GetInstance().AddPost(post);
- }
-
/// <summary>
/// フォロワーIDを更新します
/// </summary>