OSDN Git Service

TimelineResponse.ToTwitterStatusesメソッドを追加
authorKimura Youichi <kim.upsilon@bucyou.net>
Sat, 6 Jan 2024 15:38:03 +0000 (00:38 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 6 Jan 2024 15:38:23 +0000 (00:38 +0900)
OpenTween.Tests/Api/GraphQL/TimelineResponseTest.cs [new file with mode: 0644]
OpenTween/Api/GraphQL/TimelineResponse.cs
OpenTween/Twitter.cs

diff --git a/OpenTween.Tests/Api/GraphQL/TimelineResponseTest.cs b/OpenTween.Tests/Api/GraphQL/TimelineResponseTest.cs
new file mode 100644 (file)
index 0000000..4a793df
--- /dev/null
@@ -0,0 +1,41 @@
+// OpenTween - Client of Twitter
+// Copyright (c) 2024 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+using System.Threading.Tasks;
+using Xunit;
+
+namespace OpenTween.Api.GraphQL
+{
+    public class TimelineResponseTest
+    {
+        [Fact]
+        public async Task ToTwitterStatuses_Test()
+        {
+            using var apiResponse = await TestUtils.CreateApiResponse("Resources/Responses/SearchTimeline_SimpleTweet.json");
+            var tweets = TimelineTweet.ExtractTimelineTweets(await apiResponse.ReadAsJsonXml());
+            var timelineResponse = new TimelineResponse(tweets, "", "");
+
+            var statuses = timelineResponse.ToTwitterStatuses();
+            Assert.Single(statuses);
+            Assert.Equal("1619433164757413894", statuses[0].IdStr);
+        }
+    }
+}
index d92430a..052ea61 100644 (file)
 
 #nullable enable
 
-using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using OpenTween.Api.DataModel;
 
 namespace OpenTween.Api.GraphQL
 {
@@ -33,5 +30,12 @@ namespace OpenTween.Api.GraphQL
         TimelineTweet[] Tweets,
         string? CursorTop,
         string? CursorBottom
-    );
+    )
+    {
+        public TwitterStatus[] ToTwitterStatuses()
+            => this.Tweets
+                .Where(x => !x.IsTombstone)
+                .Select(x => x.ToTwitterStatus())
+                .ToArray();
+    }
 }
index ab03071..63ba006 100644 (file)
@@ -677,9 +677,7 @@ namespace OpenTween
                 var response = await request.Send(this.Api.Connection)
                     .ConfigureAwait(false);
 
-                statuses = response.Tweets
-                    .Where(x => !x.IsTombstone)
-                    .Select(x => x.ToTwitterStatus())
+                statuses = response.ToTwitterStatuses()
                     .Where(x => x.User.IdStr == userId) // リプライツリーに含まれる他ユーザーのツイートを除外
                     .ToArray();
 
@@ -884,12 +882,10 @@ namespace OpenTween
                 var response = await request.Send(this.Api.Connection)
                     .ConfigureAwait(false);
 
-                var convertedStatuses = response.Tweets
-                    .Where(x => !x.IsTombstone)
-                    .Select(x => x.ToTwitterStatus());
+                var convertedStatuses = response.ToTwitterStatuses();
 
                 if (!SettingManager.Instance.Common.IsListsIncludeRts)
-                    convertedStatuses = convertedStatuses.Where(x => x.RetweetedStatus == null);
+                    convertedStatuses = convertedStatuses.Where(x => x.RetweetedStatus == null).ToArray();
 
                 statuses = convertedStatuses.ToArray();
                 tab.CursorBottom = response.CursorBottom;
@@ -1080,10 +1076,7 @@ namespace OpenTween
                 var response = await request.Send(this.Api.Connection)
                     .ConfigureAwait(false);
 
-                statuses = response.Tweets
-                    .Where(x => !x.IsTombstone)
-                    .Select(x => x.ToTwitterStatus())
-                    .ToArray();
+                statuses = response.ToTwitterStatuses();
             }
             else
             {
@@ -1111,10 +1104,7 @@ namespace OpenTween
                 var response = await request.Send(this.Api.Connection)
                     .ConfigureAwait(false);
 
-                statuses = response.Tweets
-                    .Where(x => !x.IsTombstone)
-                    .Select(x => x.ToTwitterStatus())
-                    .ToArray();
+                statuses = response.ToTwitterStatuses();
 
                 tab.CursorBottom = response.CursorBottom;