Skip to content

Commit

Permalink
Twitterクラスを OpenTween.SocialProtocol.Twitter 名前空間に移動
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Jun 20, 2024
1 parent ef7fd1c commit ec32cb6
Show file tree
Hide file tree
Showing 28 changed files with 140 additions and 145 deletions.
8 changes: 2 additions & 6 deletions OpenTween.Tests/ListManageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTween.Api;
using OpenTween.SocialProtocol.Twitter;
using Xunit;

namespace OpenTween
Expand All @@ -35,7 +31,7 @@ public class ListManageTest
public void Initialize_Test()
{
using var twitterApi = new TwitterApi();
using var twitter = new Twitter(twitterApi);
using var twitter = new TwitterLegacy(twitterApi);
using var dialog = new ListManage(twitter);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@

using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using OpenTween.Api;
using OpenTween.Models;
using OpenTween.Setting;
using Xunit;
using Xunit.Extensions;

namespace OpenTween
namespace OpenTween.SocialProtocol.Twitter
{
public class TwitterTest
public class TwitterLegacyTest
{
[Theory]
[InlineData("https://twitter.com/twitterapi/status/22634515958",
Expand All @@ -49,7 +46,7 @@ public class TwitterTest
new[] { "22634515958" })]
public void StatusUrlRegexTest(string url, string[] expected)
{
var results = Twitter.StatusUrlRegex.Matches(url).Cast<Match>()
var results = TwitterLegacy.StatusUrlRegex.Matches(url).Cast<Match>()
.Select(x => x.Groups["StatusId"].Value).ToArray();

Assert.Equal(expected, results);
Expand All @@ -70,7 +67,7 @@ public void StatusUrlRegexTest(string url, string[] expected)
[InlineData("https://mobile.x.com/twitterapi/status/22634515958", true)]
[InlineData("https://x.com/messages/compose?recipient_id=514241801", false)] // DM は twitter.com のみ通る
public void AttachmentUrlRegexTest(string url, bool isMatch)
=> Assert.Equal(isMatch, Twitter.AttachmentUrlRegex.IsMatch(url));
=> Assert.Equal(isMatch, TwitterLegacy.AttachmentUrlRegex.IsMatch(url));

[Theory]
[InlineData("http://favstar.fm/users/twitterapi/status/22634515958", new[] { "22634515958" })]
Expand All @@ -80,7 +77,7 @@ public void AttachmentUrlRegexTest(string url, bool isMatch)
[InlineData("http://frtrt.net/solo_status.php?status=263483634307198977", new[] { "263483634307198977" })]
public void ThirdPartyStatusUrlRegexTest(string url, string[] expected)
{
var results = Twitter.ThirdPartyStatusUrlRegex.Matches(url).Cast<Match>()
var results = TwitterLegacy.ThirdPartyStatusUrlRegex.Matches(url).Cast<Match>()
.Select(x => x.Groups["StatusId"].Value).ToArray();

Assert.Equal(expected, results);
Expand Down Expand Up @@ -113,14 +110,14 @@ public void GetApiResultCount_DefaultTest()
Assert.Equal(20, usertl);

// Timeline,Reply
Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, false, false));
Assert.Equal(reply, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Reply, false, false));
Assert.Equal(timeline, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, false, false));
Assert.Equal(reply, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Reply, false, false));

// その他はTimelineと同値になる
Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, false, false));
Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.List, false, false));
Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, false));
Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, false));
Assert.Equal(timeline, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, false, false));
Assert.Equal(timeline, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.List, false, false));
Assert.Equal(timeline, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, false));
Assert.Equal(timeline, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, false));

SettingManagerTest.Common = oldInstance;
}
Expand All @@ -143,58 +140,58 @@ public void GetApiResultCount_AdditionalCountTest()
SettingManager.Instance.Common.UseAdditionalCount = true;

// Timeline
Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, false, false));
Assert.Equal(100, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, true, false)); // 100 件が上限
Assert.Equal(startup, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, false, true));
Assert.Equal(timeline, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, false, false));
Assert.Equal(100, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, true, false)); // 100 件が上限
Assert.Equal(startup, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, false, true));

// Reply
Assert.Equal(reply, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Reply, false, false));
Assert.Equal(more, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Reply, true, false));
Assert.Equal(reply, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Reply, false, true)); // Replyの値が使われる
Assert.Equal(reply, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Reply, false, false));
Assert.Equal(more, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Reply, true, false));
Assert.Equal(reply, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Reply, false, true)); // Replyの値が使われる

// Favorites
Assert.Equal(favorite, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, false, false));
Assert.Equal(favorite, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, true, false));
Assert.Equal(favorite, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, false, true));
Assert.Equal(favorite, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, false, false));
Assert.Equal(favorite, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, true, false));
Assert.Equal(favorite, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, false, true));

SettingManager.Instance.Common.FavoritesCountApi = 0;

Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, false, false));
Assert.Equal(more, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, true, false));
Assert.Equal(startup, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, false, true));
Assert.Equal(timeline, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, false, false));
Assert.Equal(more, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, true, false));
Assert.Equal(startup, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, false, true));

// List
Assert.Equal(list, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.List, false, false));
Assert.Equal(list, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.List, true, false));
Assert.Equal(list, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.List, false, true));
Assert.Equal(list, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.List, false, false));
Assert.Equal(list, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.List, true, false));
Assert.Equal(list, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.List, false, true));

SettingManager.Instance.Common.ListCountApi = 0;

Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.List, false, false));
Assert.Equal(more, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.List, true, false));
Assert.Equal(startup, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.List, false, true));
Assert.Equal(timeline, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.List, false, false));
Assert.Equal(more, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.List, true, false));
Assert.Equal(startup, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.List, false, true));

// PublicSearch
Assert.Equal(search, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, false));
Assert.Equal(search, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, true, false));
Assert.Equal(search, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, true));
Assert.Equal(search, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, false));
Assert.Equal(search, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, true, false));
Assert.Equal(search, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, true));

SettingManager.Instance.Common.SearchCountApi = 0;

Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, false));
Assert.Equal(search, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, true, false)); // MoreCountApiの値がPublicSearchの最大値に制限される
Assert.Equal(startup, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, true));
Assert.Equal(timeline, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, false));
Assert.Equal(search, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, true, false)); // MoreCountApiの値がPublicSearchの最大値に制限される
Assert.Equal(startup, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, true));

// UserTimeline
Assert.Equal(usertl, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, false));
Assert.Equal(usertl, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, true, false));
Assert.Equal(usertl, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, true));
Assert.Equal(usertl, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, false));
Assert.Equal(usertl, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, true, false));
Assert.Equal(usertl, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, true));

SettingManager.Instance.Common.UserTimelineCountApi = 0;

Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, false));
Assert.Equal(more, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, true, false));
Assert.Equal(startup, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, true));
Assert.Equal(timeline, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, false));
Assert.Equal(more, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, true, false));
Assert.Equal(startup, TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, true));

SettingManagerTest.Common = oldInstance;
}
Expand All @@ -203,7 +200,7 @@ public void GetApiResultCount_AdditionalCountTest()
public void GetTextLengthRemain_Test()
{
using var twitterApi = new TwitterApi();
using var twitter = new Twitter(twitterApi);
using var twitter = new TwitterLegacy(twitterApi);

Assert.Equal(280, twitter.GetTextLengthRemain(""));
Assert.Equal(272, twitter.GetTextLengthRemain("hogehoge"));
Expand All @@ -213,7 +210,7 @@ public void GetTextLengthRemain_Test()
public void GetTextLengthRemain_DirectMessageTest()
{
using var twitterApi = new TwitterApi();
using var twitter = new Twitter(twitterApi);
using var twitter = new TwitterLegacy(twitterApi);

// 2015年8月から DM の文字数上限が 10,000 文字に変更された
// https://twittercommunity.com/t/41348
Expand All @@ -234,7 +231,7 @@ public void GetTextLengthRemain_DirectMessageTest()
public void GetTextLengthRemain_UrlTest()
{
using var twitterApi = new TwitterApi();
using var twitter = new Twitter(twitterApi);
using var twitter = new TwitterLegacy(twitterApi);

// t.co に短縮される分の文字数を考慮
twitter.TextConfiguration.TransformedURLLength = 20;
Expand All @@ -251,7 +248,7 @@ public void GetTextLengthRemain_UrlTest()
public void GetTextLengthRemain_UrlWithoutSchemeTest()
{
using var twitterApi = new TwitterApi();
using var twitter = new Twitter(twitterApi);
using var twitter = new TwitterLegacy(twitterApi);

// t.co に短縮される分の文字数を考慮
twitter.TextConfiguration.TransformedURLLength = 20;
Expand All @@ -269,7 +266,7 @@ public void GetTextLengthRemain_UrlWithoutSchemeTest()
public void GetTextLengthRemain_SurrogatePairTest()
{
using var twitterApi = new TwitterApi();
using var twitter = new Twitter(twitterApi);
using var twitter = new TwitterLegacy(twitterApi);

Assert.Equal(278, twitter.GetTextLengthRemain("🍣"));
Assert.Equal(267, twitter.GetTextLengthRemain("🔥🐔🔥 焼き鳥"));
Expand All @@ -279,7 +276,7 @@ public void GetTextLengthRemain_SurrogatePairTest()
public void GetTextLengthRemain_EmojiTest()
{
using var twitterApi = new TwitterApi();
using var twitter = new Twitter(twitterApi);
using var twitter = new TwitterLegacy(twitterApi);

// 絵文字の文字数カウントの仕様変更に対するテストケース
// https://twittercommunity.com/t/114607
Expand All @@ -299,7 +296,7 @@ public void GetTextLengthRemain_EmojiTest()
public void GetTextLengthRemain_BrokenSurrogateTest()
{
using var twitterApi = new TwitterApi();
using var twitter = new Twitter(twitterApi);
using var twitter = new TwitterLegacy(twitterApi);

// 投稿欄に IME から絵文字を入力すると HighSurrogate のみ入力された状態で TextChanged イベントが呼ばれることがある
Assert.Equal(278, twitter.GetTextLengthRemain("\ud83d"));
Expand All @@ -313,11 +310,11 @@ public void GetTextLengthRemain_BrokenSurrogateTest()
[InlineData("https://pbs.twimg.com/profile_images/00000/foo_normal.jpg", "original", "https://pbs.twimg.com/profile_images/00000/foo.jpg")]
[InlineData("https://pbs.twimg.com/profile_images/00000/foo_normal_bar_normal.jpg", "original", "https://pbs.twimg.com/profile_images/00000/foo_normal_bar.jpg")]
public void CreateProfileImageUrl_Test(string normalUrl, string size, string expected)
=> Assert.Equal(expected, Twitter.CreateProfileImageUrl(normalUrl, size));
=> Assert.Equal(expected, TwitterLegacy.CreateProfileImageUrl(normalUrl, size));

[Fact]
public void CreateProfileImageUrl_InvalidSizeTest()
=> Assert.Throws<ArgumentException>(() => Twitter.CreateProfileImageUrl("https://pbs.twimg.com/profile_images/00000/foo_normal.jpg", "INVALID"));
=> Assert.Throws<ArgumentException>(() => TwitterLegacy.CreateProfileImageUrl("https://pbs.twimg.com/profile_images/00000/foo_normal.jpg", "INVALID"));

[Theory]
[InlineData(24, "mini")]
Expand All @@ -327,6 +324,6 @@ public void CreateProfileImageUrl_InvalidSizeTest()
[InlineData(73, "bigger")]
[InlineData(74, "original")]
public void DecideProfileImageSize_Test(int sizePx, string expected)
=> Assert.Equal(expected, Twitter.DecideProfileImageSize(sizePx));
=> Assert.Equal(expected, TwitterLegacy.DecideProfileImageSize(sizePx));
}
}
3 changes: 2 additions & 1 deletion OpenTween/ImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using System.Threading.Tasks;
using System.Xml.Serialization;
using OpenTween.Connection;
using OpenTween.SocialProtocol.Twitter;

namespace OpenTween
{
Expand Down Expand Up @@ -145,7 +146,7 @@ private MemoryImage CreateBlankImage()

foreach (var candidateSize in sizes.Skip(minimumIndex))
{
var imageUrl = Twitter.CreateProfileImageUrl(normalUrl, candidateSize);
var imageUrl = TwitterLegacy.CreateProfileImageUrl(normalUrl, candidateSize);
var image = this.TryGetFromCache(imageUrl);
if (image != null)
return image;
Expand Down
4 changes: 2 additions & 2 deletions OpenTween/ListElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ListElement
public string Username = "";
public string Nickname = "";

protected Twitter tw = null!;
protected TwitterLegacy tw = null!;

private List<UserInfo> members = new();

Expand All @@ -59,7 +59,7 @@ public ListElement()
{
}

public ListElement(TwitterList listElementData, Twitter tw)
public ListElement(TwitterList listElementData, TwitterLegacy tw)
{
this.Description = listElementData.Description;
this.Id = listElementData.Id;
Expand Down
11 changes: 6 additions & 5 deletions OpenTween/ListManage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@
using System.Windows.Forms;
using OpenTween.Connection;
using OpenTween.Models;
using OpenTween.SocialProtocol.Twitter;

namespace OpenTween
{
public partial class ListManage : OTBaseForm
{
private readonly Twitter tw;
private readonly TwitterLegacy tw;

public ListManage(Twitter tw)
public ListManage(TwitterLegacy tw)
{
this.InitializeComponent();

Expand Down Expand Up @@ -349,8 +350,8 @@ private async Task LoadUserIconAsync(Uri imageUri, PersonId userId)

await this.UserIcon.SetImageFromTask(async () =>
{
var sizeName = Twitter.DecideProfileImageSize(this.UserIcon.Width);
var uri = Twitter.CreateProfileImageUrl(imageUri.AbsoluteUri, sizeName);
var sizeName = TwitterLegacy.DecideProfileImageSize(this.UserIcon.Width);
var uri = TwitterLegacy.CreateProfileImageUrl(imageUri.AbsoluteUri, sizeName);

using var imageStream = await Networking.Http.GetStreamAsync(uri);
var image = await MemoryImage.CopyFromStreamAsync(imageStream);
Expand Down Expand Up @@ -421,7 +422,7 @@ private class NewListElement : ListElement
{
public bool IsCreated { get; private set; } = false;

public NewListElement(Twitter tw)
public NewListElement(TwitterLegacy tw)
=> this.tw = tw;

public override async Task Refresh()
Expand Down
3 changes: 2 additions & 1 deletion OpenTween/MediaUploadServices/Mobypicture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Threading.Tasks;
using OpenTween.Api;
using OpenTween.Api.DataModel;
using OpenTween.SocialProtocol.Twitter;

namespace OpenTween.MediaUploadServices
{
Expand Down Expand Up @@ -72,7 +73,7 @@ public class Mobypicture : IMediaUploadService

private TwitterConfiguration twitterConfig;

public Mobypicture(Twitter twitter, TwitterConfiguration twitterConfig)
public Mobypicture(TwitterLegacy twitter, TwitterConfiguration twitterConfig)
: this(new MobypictureApi(twitter.Api), twitterConfig)
{
}
Expand Down
Loading

0 comments on commit ec32cb6

Please sign in to comment.