#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));
-
if (this.ListInfo == null || this.ListInfo.Id == 0)
return;
progress.Report("List refreshing...");
var firstLoad = !this.IsFirstLoadCompleted;
+ var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.List, backward, firstLoad);
+ var cursor = backward ? this.CursorBottom : this.CursorTop;
- await twAccount.Legacy.GetListStatus(this, backward, firstLoad)
+ var response = await account.Client.GetListTimeline(this.ListInfo.Id, count, cursor, firstLoad)
.ConfigureAwait(false);
+ foreach (var post in response.Posts)
+ this.AddPostQueue(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> GetFavoritesTimeline(int count, IQueryCursor? cursor, bool firstLoad);
+ public Task<TimelineResponse> GetListTimeline(long listId, 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> GetFavoritesTimeline(int count, IQueryCursor? cursor, bool firstLoad)
=> throw this.CreateException();
+ public Task<TimelineResponse> GetListTimeline(long listId, 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> GetListTimeline(long listId, int count, IQueryCursor? cursor, bool firstLoad)
+ {
+ this.account.Legacy.CheckAccountState();
+
+ var request = new ListLatestTweetsTimelineRequest(listId.ToString())
+ {
+ 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();
using OpenTween.Api.DataModel;
using OpenTween.Connection;
using OpenTween.Models;
+using OpenTween.Setting;
namespace OpenTween.SocialProtocol.Twitter
{
return new(posts, cursorTop, cursorBottom);
}
+ public async Task<TimelineResponse> GetListTimeline(long listId, int count, IQueryCursor? cursor, bool firstLoad)
+ {
+ this.account.Legacy.CheckAccountState();
+ var (sinceId, maxId) = GetCursorParams(cursor);
+
+ var includeRTs = SettingManager.Instance.Common.IsListsIncludeRts;
+ var statuses = await this.account.Legacy.Api.ListsStatuses(listId, count, maxId, sinceId, includeRTs)
+ .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();
internal PostClass[] FilterNoRetweetUserPosts(PostClass[] posts)
=> posts.Where(x => x.RetweetedByUserId == null || !this.AccountState.NoRetweetUserIds.Contains(x.RetweetedByUserId)).ToArray();
- public async Task GetListStatus(ListTimelineTabModel tab, bool more, bool firstLoad)
- {
- var count = GetApiResultCount(MyCommon.WORKERTYPE.List, more, firstLoad);
-
- TwitterStatus[] statuses;
- if (this.Api.AuthType == APIAuthType.TwitterComCookie)
- {
- var cursor = more ? tab.CursorBottom : tab.CursorTop;
- var request = new ListLatestTweetsTimelineRequest(tab.ListInfo.Id.ToString())
- {
- Count = count,
- Cursor = cursor?.As<TwitterGraphqlCursor>(),
- };
- var response = await request.Send(this.Api.Connection)
- .ConfigureAwait(false);
-
- var convertedStatuses = response.ToTwitterStatuses();
-
- if (!SettingManager.Instance.Common.IsListsIncludeRts)
- convertedStatuses = convertedStatuses.Where(x => x.RetweetedStatus == null).ToArray();
-
- statuses = convertedStatuses.ToArray();
- tab.CursorBottom = response.CursorBottom;
-
- if (!more)
- tab.CursorTop = response.CursorTop;
- }
- else
- {
- var maxId = more ? tab.CursorBottom?.As<TwitterStatusId>() : null;
-
- statuses = await this.Api.ListsStatuses(tab.ListInfo.Id, count, maxId, includeRTs: SettingManager.Instance.Common.IsListsIncludeRts)
- .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)
- tab.AddPostQueue(post);
- }
-
public async Task GetDirectMessageEvents(DirectMessagesTabModel dmTab, bool backward, bool firstLoad)
{
this.CheckAccountState();