OSDN Git Service

ISocialProtocolClient.GetPostByIdメソッドを追加
authorKimura Youichi <kim.upsilon@bucyou.net>
Tue, 14 May 2024 18:01:47 +0000 (03:01 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Tue, 14 May 2024 19:45:14 +0000 (04:45 +0900)
OpenTween/SocialProtocol/ISocialProtocolClient.cs
OpenTween/SocialProtocol/Twitter/TwitterGraphqlClient.cs
OpenTween/SocialProtocol/Twitter/TwitterV1Client.cs
OpenTween/Tween.cs
OpenTween/TweetDetailsView.cs

index f3e3dfd..2af6ecd 100644 (file)
@@ -28,6 +28,8 @@ namespace OpenTween.SocialProtocol
 {
     public interface ISocialProtocolClient
     {
+        public Task<PostClass> GetPostById(PostId postId, bool firstLoad);
+
         public Task<TimelineResponse> GetHomeTimeline(int count, IQueryCursor? cursor, bool firstLoad);
 
         public Task DeletePost(PostId postId);
index cca88aa..f57a8ca 100644 (file)
@@ -27,6 +27,7 @@
 
 #nullable enable
 
+using System.Linq;
 using System.Threading.Tasks;
 using OpenTween.Api.GraphQL;
 using OpenTween.Models;
@@ -42,6 +43,28 @@ namespace OpenTween.SocialProtocol.Twitter
             this.account = account;
         }
 
+        public async Task<PostClass> GetPostById(PostId postId, bool firstLoad)
+        {
+            this.account.Legacy.CheckAccountState();
+
+            var statusId = this.AssertTwitterStatusId(postId);
+            var request = new TweetDetailRequest
+            {
+                FocalTweetId = statusId,
+            };
+
+            var tweets = await request.Send(this.account.Connection)
+                .ConfigureAwait(false);
+
+            var status = tweets.Select(x => x.ToTwitterStatus())
+                .Where(x => x.IdStr == statusId.Id)
+                .FirstOrDefault() ?? throw new WebApiException("Empty result set");
+
+            var post = this.account.Legacy.CreatePostsFromStatusData(status, firstLoad, favTweet: false);
+
+            return post;
+        }
+
         public async Task<TimelineResponse> GetHomeTimeline(int count, IQueryCursor? cursor, bool firstLoad)
         {
             this.account.Legacy.CheckAccountState();
index 6d264af..0f8a343 100644 (file)
@@ -45,6 +45,19 @@ namespace OpenTween.SocialProtocol.Twitter
             this.account = account;
         }
 
+        public async Task<PostClass> GetPostById(PostId postId, bool firstLoad)
+        {
+            this.account.Legacy.CheckAccountState();
+
+            var statusId = this.AssertTwitterStatusId(postId);
+            var status = await this.account.Legacy.Api.StatusesShow(statusId)
+                .ConfigureAwait(false);
+
+            var post = this.account.Legacy.CreatePostsFromStatusData(status, firstLoad, favTweet: false);
+
+            return post;
+        }
+
         public async Task<TimelineResponse> GetHomeTimeline(int count, IQueryCursor? cursor, bool firstLoad)
         {
             this.account.Legacy.CheckAccountState();
index 32fdcb4..6e0b4bf 100644 (file)
@@ -5134,7 +5134,7 @@ namespace OpenTween
             {
                 try
                 {
-                    var post = await this.tw.GetStatusApi(currentPost.StatusId.ToTwitterStatusId());
+                    var post = await this.CurrentTabAccount.Client.GetPostById(currentPost.StatusId, firstLoad: false);
 
                     currentPost = currentPost with
                     {
@@ -5182,7 +5182,7 @@ namespace OpenTween
                 {
                     await Task.Run(async () =>
                     {
-                        var post = await this.tw.GetStatusApi(currentPost.InReplyToStatusId.ToTwitterStatusId())
+                        var post = await this.CurrentTabAccount.Client.GetPostById(currentPost.InReplyToStatusId, firstLoad: false)
                             .ConfigureAwait(false);
 
                         this.statuses.AddPost(post);
@@ -9062,7 +9062,7 @@ namespace OpenTween
             {
                 try
                 {
-                    post = await this.tw.GetStatusApi(statusId.ToTwitterStatusId());
+                    post = await this.CurrentTabAccount.Client.GetPostById(statusId, firstLoad: false);
                 }
                 catch (WebApiException ex)
                 {
index d5daaa9..ba661dc 100644 (file)
@@ -363,8 +363,7 @@ namespace OpenTween
             {
                 try
                 {
-                    var twitterAccount = (SocialProtocol.Twitter.TwitterAccount)this.Owner.CurrentTabAccount;
-                    post = await twitterAccount.Legacy.GetStatusApi(statusId.ToTwitterStatusId())
+                    post = await this.Owner.CurrentTabAccount.Client.GetPostById(statusId, firstLoad: false)
                         .ConfigureAwait(false);
                 }
                 catch (WebApiException ex)