OSDN Git Service

ISocialProtocolClient.GetListTimelineメソッドを追加
authorKimura Youichi <kim.upsilon@bucyou.net>
Mon, 20 May 2024 18:21:08 +0000 (03:21 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Mon, 20 May 2024 18:21:08 +0000 (03:21 +0900)
OpenTween/Models/ListTimelineTabModel.cs
OpenTween/SocialProtocol/ISocialProtocolClient.cs
OpenTween/SocialProtocol/InvalidAccount.cs
OpenTween/SocialProtocol/Twitter/TwitterGraphqlClient.cs
OpenTween/SocialProtocol/Twitter/TwitterV1Client.cs
OpenTween/Twitter.cs

index 77458ad..c889d74 100644 (file)
 #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
 {
@@ -58,21 +53,29 @@ 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;
 
index b8f52ef..45743a0 100644 (file)
@@ -38,6 +38,8 @@ namespace OpenTween.SocialProtocol
 
         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);
index bb21841..d43965b 100644 (file)
@@ -84,6 +84,9 @@ namespace OpenTween.SocialProtocol
             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();
 
index cddd7b7..b516998 100644 (file)
@@ -149,6 +149,29 @@ 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 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();
index 96cf4d0..f174ba4 100644 (file)
@@ -33,6 +33,7 @@ using OpenTween.Api;
 using OpenTween.Api.DataModel;
 using OpenTween.Connection;
 using OpenTween.Models;
+using OpenTween.Setting;
 
 namespace OpenTween.SocialProtocol.Twitter
 {
@@ -116,6 +117,22 @@ 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();
index 9fcd2c3..9008ecb 100644 (file)
@@ -552,54 +552,6 @@ namespace OpenTween
         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();