diff --git a/OpenTween.Tests/ListManageTest.cs b/OpenTween.Tests/ListManageTest.cs index 8f3c9aa0a..3ba6f652e 100644 --- a/OpenTween.Tests/ListManageTest.cs +++ b/OpenTween.Tests/ListManageTest.cs @@ -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 @@ -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); } } diff --git a/OpenTween.Tests/TwitterTest.cs b/OpenTween.Tests/SocialProtocol/Twitter/TwitterLegacyTest.cs similarity index 71% rename from OpenTween.Tests/TwitterTest.cs rename to OpenTween.Tests/SocialProtocol/Twitter/TwitterLegacyTest.cs index b3a655f29..6569e4e23 100644 --- a/OpenTween.Tests/TwitterTest.cs +++ b/OpenTween.Tests/SocialProtocol/Twitter/TwitterLegacyTest.cs @@ -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", @@ -49,7 +46,7 @@ public class TwitterTest new[] { "22634515958" })] public void StatusUrlRegexTest(string url, string[] expected) { - var results = Twitter.StatusUrlRegex.Matches(url).Cast() + var results = TwitterLegacy.StatusUrlRegex.Matches(url).Cast() .Select(x => x.Groups["StatusId"].Value).ToArray(); Assert.Equal(expected, results); @@ -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" })] @@ -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() + var results = TwitterLegacy.ThirdPartyStatusUrlRegex.Matches(url).Cast() .Select(x => x.Groups["StatusId"].Value).ToArray(); Assert.Equal(expected, results); @@ -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; } @@ -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; } @@ -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")); @@ -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 @@ -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; @@ -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; @@ -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("🔥🐔🔥 焼き鳥")); @@ -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 @@ -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")); @@ -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(() => Twitter.CreateProfileImageUrl("https://pbs.twimg.com/profile_images/00000/foo_normal.jpg", "INVALID")); + => Assert.Throws(() => TwitterLegacy.CreateProfileImageUrl("https://pbs.twimg.com/profile_images/00000/foo_normal.jpg", "INVALID")); [Theory] [InlineData(24, "mini")] @@ -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)); } } diff --git a/OpenTween/ImageCache.cs b/OpenTween/ImageCache.cs index 97f7f4376..2adae5c5e 100644 --- a/OpenTween/ImageCache.cs +++ b/OpenTween/ImageCache.cs @@ -32,6 +32,7 @@ using System.Threading.Tasks; using System.Xml.Serialization; using OpenTween.Connection; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween { @@ -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; diff --git a/OpenTween/ListElement.cs b/OpenTween/ListElement.cs index 70f032e37..85898d130 100644 --- a/OpenTween/ListElement.cs +++ b/OpenTween/ListElement.cs @@ -48,7 +48,7 @@ public class ListElement public string Username = ""; public string Nickname = ""; - protected Twitter tw = null!; + protected TwitterLegacy tw = null!; private List members = new(); @@ -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; diff --git a/OpenTween/ListManage.cs b/OpenTween/ListManage.cs index 7281e5bac..c7ac91e50 100644 --- a/OpenTween/ListManage.cs +++ b/OpenTween/ListManage.cs @@ -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(); @@ -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); @@ -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() diff --git a/OpenTween/MediaUploadServices/Mobypicture.cs b/OpenTween/MediaUploadServices/Mobypicture.cs index f21d9f683..99a0dc301 100644 --- a/OpenTween/MediaUploadServices/Mobypicture.cs +++ b/OpenTween/MediaUploadServices/Mobypicture.cs @@ -28,6 +28,7 @@ using System.Threading.Tasks; using OpenTween.Api; using OpenTween.Api.DataModel; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween.MediaUploadServices { @@ -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) { } diff --git a/OpenTween/MediaUploadServices/TwitterPhoto.cs b/OpenTween/MediaUploadServices/TwitterPhoto.cs index 375451963..1b6ec8f20 100644 --- a/OpenTween/MediaUploadServices/TwitterPhoto.cs +++ b/OpenTween/MediaUploadServices/TwitterPhoto.cs @@ -44,10 +44,10 @@ public class TwitterPhoto : IMediaUploadService { private readonly string[] pictureExt = { ".jpg", ".jpeg", ".gif", ".png" }; - private readonly Twitter tw; + private readonly TwitterLegacy tw; private TwitterConfiguration twitterConfig; - public TwitterPhoto(Twitter twitter, TwitterConfiguration twitterConfig) + public TwitterPhoto(TwitterLegacy twitter, TwitterConfiguration twitterConfig) { this.tw = twitter; this.twitterConfig = twitterConfig; @@ -92,7 +92,7 @@ public async Task UploadAsync(IMediaItem[] mediaItems, PostSta TwitterMediaId[] mediaIds; - if (Twitter.DMSendTextRegex.IsMatch(postParams.Text)) + if (TwitterLegacy.DMSendTextRegex.IsMatch(postParams.Text)) mediaIds = new[] { await this.UploadMediaForDM(mediaItems).ConfigureAwait(false) }; else mediaIds = await this.UploadMediaForTweet(mediaItems).ConfigureAwait(false); diff --git a/OpenTween/Models/FavoritesTabModel.cs b/OpenTween/Models/FavoritesTabModel.cs index 1f89b7dde..6bbc190ca 100644 --- a/OpenTween/Models/FavoritesTabModel.cs +++ b/OpenTween/Models/FavoritesTabModel.cs @@ -30,6 +30,7 @@ using System; using System.Threading.Tasks; using OpenTween.SocialProtocol; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween.Models { @@ -53,7 +54,7 @@ public override async Task RefreshAsync(ISocialAccount account, bool backward, I progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19); var firstLoad = !this.IsFirstLoadCompleted; - var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, backward, firstLoad); + var count = TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Favorites, backward, firstLoad); var cursor = backward ? this.CursorBottom : this.CursorTop; var response = await account.Client.GetFavoritesTimeline(count, cursor, firstLoad) diff --git a/OpenTween/Models/HomeSpecifiedAccountTabModel.cs b/OpenTween/Models/HomeSpecifiedAccountTabModel.cs index 4b1b2411d..4385f1656 100644 --- a/OpenTween/Models/HomeSpecifiedAccountTabModel.cs +++ b/OpenTween/Models/HomeSpecifiedAccountTabModel.cs @@ -24,6 +24,7 @@ using System; using System.Threading.Tasks; using OpenTween.SocialProtocol; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween.Models { @@ -48,7 +49,7 @@ public override async Task RefreshAsync(ISocialAccount account, bool backward, I progress.Report("Home refreshing..."); var firstLoad = !this.IsFirstLoadCompleted; - var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, backward, firstLoad); + var count = TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, backward, firstLoad); var cursor = backward ? this.CursorBottom : this.CursorTop; var response = await account.Client.GetHomeTimeline(count, cursor, firstLoad) diff --git a/OpenTween/Models/HomeTabModel.cs b/OpenTween/Models/HomeTabModel.cs index e8cd67b41..a23d627f8 100644 --- a/OpenTween/Models/HomeTabModel.cs +++ b/OpenTween/Models/HomeTabModel.cs @@ -72,7 +72,7 @@ public override async Task RefreshAsync(ISocialAccount account, bool backward, I progress.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5, backward ? -1 : 1)); var firstLoad = !this.IsFirstLoadCompleted; - var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, backward, firstLoad); + var count = TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, backward, firstLoad); var cursor = backward ? this.CursorBottom : this.CursorTop; var response = await account.Client.GetHomeTimeline(count, cursor, firstLoad) diff --git a/OpenTween/Models/ListTimelineTabModel.cs b/OpenTween/Models/ListTimelineTabModel.cs index c889d7482..75ee596a5 100644 --- a/OpenTween/Models/ListTimelineTabModel.cs +++ b/OpenTween/Models/ListTimelineTabModel.cs @@ -30,6 +30,7 @@ using System; using System.Threading.Tasks; using OpenTween.SocialProtocol; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween.Models { @@ -59,7 +60,7 @@ public override async Task RefreshAsync(ISocialAccount account, bool backward, I progress.Report("List refreshing..."); var firstLoad = !this.IsFirstLoadCompleted; - var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.List, backward, firstLoad); + var count = TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.List, backward, firstLoad); var cursor = backward ? this.CursorBottom : this.CursorTop; var response = await account.Client.GetListTimeline(this.ListInfo.Id, count, cursor, firstLoad) diff --git a/OpenTween/Models/MentionsTabModel.cs b/OpenTween/Models/MentionsTabModel.cs index cd5f14ed0..3a0069770 100644 --- a/OpenTween/Models/MentionsTabModel.cs +++ b/OpenTween/Models/MentionsTabModel.cs @@ -30,6 +30,7 @@ using System; using System.Threading.Tasks; using OpenTween.SocialProtocol; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween.Models { @@ -53,7 +54,7 @@ public override async Task RefreshAsync(ISocialAccount account, bool backward, I progress.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4, backward ? -1 : 1)); var firstLoad = !this.IsFirstLoadCompleted; - var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Reply, backward, firstLoad); + var count = TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.Reply, backward, firstLoad); var cursor = backward ? this.CursorBottom : this.CursorTop; var response = await account.Client.GetMentionsTimeline(count, cursor, firstLoad) diff --git a/OpenTween/Models/PublicSearchTabModel.cs b/OpenTween/Models/PublicSearchTabModel.cs index ce13bc3d3..d6d2f31d2 100644 --- a/OpenTween/Models/PublicSearchTabModel.cs +++ b/OpenTween/Models/PublicSearchTabModel.cs @@ -30,6 +30,7 @@ using System; using System.Threading.Tasks; using OpenTween.SocialProtocol; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween.Models { @@ -74,7 +75,7 @@ public override async Task RefreshAsync(ISocialAccount account, bool backward, I progress.Report("Search refreshing..."); var firstLoad = !this.IsFirstLoadCompleted; - var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, backward, firstLoad); + var count = TwitterLegacy.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, backward, firstLoad); var cursor = backward ? this.CursorBottom : this.CursorTop; var response = await account.Client.GetSearchTimeline(this.SearchWords, this.SearchLang, count, cursor, firstLoad) diff --git a/OpenTween/MyLists.cs b/OpenTween/MyLists.cs index c0c88306c..65476c75f 100644 --- a/OpenTween/MyLists.cs +++ b/OpenTween/MyLists.cs @@ -38,12 +38,13 @@ using OpenTween.Api; using OpenTween.Api.DataModel; using OpenTween.Connection; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween { public partial class MyLists : OTBaseForm { - private readonly Twitter twitter = null!; + private readonly TwitterLegacy twitter = null!; private readonly string contextScreenName = null!; /// 自分が所有しているリスト @@ -55,7 +56,7 @@ public partial class MyLists : OTBaseForm public MyLists() => this.InitializeComponent(); - public MyLists(string screenName, Twitter twitter) + public MyLists(string screenName, TwitterLegacy twitter) { this.InitializeComponent(); diff --git a/OpenTween/SendErrorReportForm.cs b/OpenTween/SendErrorReportForm.cs index bce3c886b..911900636 100644 --- a/OpenTween/SendErrorReportForm.cs +++ b/OpenTween/SendErrorReportForm.cs @@ -35,6 +35,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using OpenTween.Api.DataModel; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween { @@ -133,7 +134,7 @@ public string EncodedReportForDM private string encodedReportForDM = ""; - private readonly Twitter? tw; + private readonly TwitterLegacy? tw; private readonly string originalReportText; public ErrorReport(string reportText) @@ -141,7 +142,7 @@ public ErrorReport(string reportText) { } - public ErrorReport(Twitter? tw, string reportText) + public ErrorReport(TwitterLegacy? tw, string reportText) { this.tw = tw; this.originalReportText = reportText; diff --git a/OpenTween/Setting/Panel/GetCountPanel.cs b/OpenTween/Setting/Panel/GetCountPanel.cs index e1c76e82e..7e4816ed1 100644 --- a/OpenTween/Setting/Panel/GetCountPanel.cs +++ b/OpenTween/Setting/Panel/GetCountPanel.cs @@ -34,6 +34,7 @@ using System.Linq; using System.Text; using System.Windows.Forms; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween.Setting.Panel { @@ -95,7 +96,7 @@ private void TextCountApi_Validating(object sender, CancelEventArgs e) return; } - if (!Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Timeline, cnt)) + if (!TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.Timeline, cnt)) { MessageBox.Show(Properties.Resources.TextCountApi_Validating1); e.Cancel = true; @@ -117,7 +118,7 @@ private void TextCountApiReply_Validating(object sender, CancelEventArgs e) return; } - if (!Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Reply, cnt)) + if (!TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.Reply, cnt)) { MessageBox.Show(Properties.Resources.TextCountApi_Validating1); e.Cancel = true; @@ -139,7 +140,7 @@ private void GetMoreTextCountApi_Validating(object sender, CancelEventArgs e) return; } - if (cnt != 0 && !Twitter.VerifyMoreApiResultCount(cnt)) + if (cnt != 0 && !TwitterLegacy.VerifyMoreApiResultCount(cnt)) { MessageBox.Show(Properties.Resources.TextCountApi_Validating1); e.Cancel = true; @@ -177,7 +178,7 @@ private void FirstTextCountApi_Validating(object sender, CancelEventArgs e) return; } - if (cnt != 0 && !Twitter.VerifyFirstApiResultCount(cnt)) + if (cnt != 0 && !TwitterLegacy.VerifyFirstApiResultCount(cnt)) { MessageBox.Show(Properties.Resources.TextCountApi_Validating1); e.Cancel = true; @@ -199,7 +200,7 @@ private void SearchTextCountApi_Validating(object sender, CancelEventArgs e) return; } - if (cnt != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.PublicSearch, cnt)) + if (cnt != 0 && !TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.PublicSearch, cnt)) { MessageBox.Show(Properties.Resources.TextSearchCountApi_Validating1); e.Cancel = true; @@ -221,7 +222,7 @@ private void FavoritesTextCountApi_Validating(object sender, CancelEventArgs e) return; } - if (cnt != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Favorites, cnt)) + if (cnt != 0 && !TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.Favorites, cnt)) { MessageBox.Show(Properties.Resources.TextCountApi_Validating1); e.Cancel = true; @@ -243,7 +244,7 @@ private void UserTimelineTextCountApi_Validating(object sender, CancelEventArgs return; } - if (cnt != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.UserTimeline, cnt)) + if (cnt != 0 && !TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.UserTimeline, cnt)) { MessageBox.Show(Properties.Resources.TextCountApi_Validating1); e.Cancel = true; @@ -265,7 +266,7 @@ private void ListTextCountApi_Validating(object sender, CancelEventArgs e) return; } - if (cnt != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.List, cnt)) + if (cnt != 0 && !TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.List, cnt)) { MessageBox.Show(Properties.Resources.TextCountApi_Validating1); e.Cancel = true; diff --git a/OpenTween/Setting/SettingCommon.cs b/OpenTween/Setting/SettingCommon.cs index 660a6d9ea..598926085 100644 --- a/OpenTween/Setting/SettingCommon.cs +++ b/OpenTween/Setting/SettingCommon.cs @@ -32,6 +32,7 @@ using System.Windows.Forms; using System.Xml.Serialization; using OpenTween.Connection; +using OpenTween.SocialProtocol.Twitter; using OpenTween.Thumbnail; namespace OpenTween @@ -298,28 +299,28 @@ public void Validate() if (this.ListsPeriod < 0) this.ListsPeriod = 15; - if (!Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Timeline, this.CountApi)) + if (!TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.Timeline, this.CountApi)) this.CountApi = 60; - if (!Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Reply, this.CountApiReply)) + if (!TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.Reply, this.CountApiReply)) this.CountApiReply = 40; - if (this.MoreCountApi != 0 && !Twitter.VerifyMoreApiResultCount(this.MoreCountApi)) + if (this.MoreCountApi != 0 && !TwitterLegacy.VerifyMoreApiResultCount(this.MoreCountApi)) this.MoreCountApi = 200; - if (this.FirstCountApi != 0 && !Twitter.VerifyFirstApiResultCount(this.FirstCountApi)) + if (this.FirstCountApi != 0 && !TwitterLegacy.VerifyFirstApiResultCount(this.FirstCountApi)) this.FirstCountApi = 100; - if (this.FavoritesCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Favorites, this.FavoritesCountApi)) + if (this.FavoritesCountApi != 0 && !TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.Favorites, this.FavoritesCountApi)) this.FavoritesCountApi = 40; - if (this.ListCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.List, this.ListCountApi)) + if (this.ListCountApi != 0 && !TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.List, this.ListCountApi)) this.ListCountApi = 100; - if (this.SearchCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.PublicSearch, this.SearchCountApi)) + if (this.SearchCountApi != 0 && !TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.PublicSearch, this.SearchCountApi)) this.SearchCountApi = 100; - if (this.UserTimelineCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.UserTimeline, this.UserTimelineCountApi)) + if (this.UserTimelineCountApi != 0 && !TwitterLegacy.VerifyApiResultCount(MyCommon.WORKERTYPE.UserTimeline, this.UserTimelineCountApi)) this.UserTimelineCountApi = 20; // 廃止サービスが選択されていた場合ux.nuへ読み替え diff --git a/OpenTween/SocialProtocol/Misskey/MisskeyPostFactory.cs b/OpenTween/SocialProtocol/Misskey/MisskeyPostFactory.cs index f4296e60a..571b32698 100644 --- a/OpenTween/SocialProtocol/Misskey/MisskeyPostFactory.cs +++ b/OpenTween/SocialProtocol/Misskey/MisskeyPostFactory.cs @@ -144,7 +144,7 @@ private IEnumerable ExtractPostIdFromUrls(IEnumerable { foreach (var url in urls) { - var match = OpenTween.Twitter.StatusUrlRegex.Match(url.ExpandedUrl); + var match = TwitterLegacy.StatusUrlRegex.Match(url.ExpandedUrl); if (match.Success) yield return new TwitterStatusId(match.Groups["StatusId"].Value); } diff --git a/OpenTween/SocialProtocol/Twitter/CreateTweetFormatter.cs b/OpenTween/SocialProtocol/Twitter/CreateTweetFormatter.cs index 0b5a45785..579ae8b69 100644 --- a/OpenTween/SocialProtocol/Twitter/CreateTweetFormatter.cs +++ b/OpenTween/SocialProtocol/Twitter/CreateTweetFormatter.cs @@ -134,7 +134,7 @@ private CreateTweetParams RemoveAttachmentUrl(CreateTweetParams createParams) return createParams; var tweetText = createParams.Text; - var match = OpenTween.Twitter.AttachmentUrlRegex.Match(tweetText); + var match = TwitterLegacy.AttachmentUrlRegex.Match(tweetText); if (!match.Success) return createParams; diff --git a/OpenTween/SocialProtocol/Twitter/RelatedTweetsFetcher.cs b/OpenTween/SocialProtocol/Twitter/RelatedTweetsFetcher.cs index b1c296b34..472543fd9 100644 --- a/OpenTween/SocialProtocol/Twitter/RelatedTweetsFetcher.cs +++ b/OpenTween/SocialProtocol/Twitter/RelatedTweetsFetcher.cs @@ -110,8 +110,8 @@ public async Task Run(PostClass targetPost, bool firstLoad) // MRTとかに対応のためツイート内にあるツイートを指すURLを取り込む var text = targetPost.Text; - var ma = OpenTween.Twitter.StatusUrlRegex.Matches(text).Cast() - .Concat(OpenTween.Twitter.ThirdPartyStatusUrlRegex.Matches(text).Cast()); + var ma = TwitterLegacy.StatusUrlRegex.Matches(text).Cast() + .Concat(TwitterLegacy.ThirdPartyStatusUrlRegex.Matches(text).Cast()); foreach (var match in ma) { var statusId = new TwitterStatusId(match.Groups["StatusId"].Value); diff --git a/OpenTween/SocialProtocol/Twitter/TwitterAccount.cs b/OpenTween/SocialProtocol/Twitter/TwitterAccount.cs index 03a17c8e3..2dfd79f69 100644 --- a/OpenTween/SocialProtocol/Twitter/TwitterAccount.cs +++ b/OpenTween/SocialProtocol/Twitter/TwitterAccount.cs @@ -29,7 +29,7 @@ namespace OpenTween.SocialProtocol.Twitter { public class TwitterAccount : ISocialAccount { - private readonly OpenTween.Twitter twLegacy = new(new()); + private readonly TwitterLegacy twLegacy = new(new()); private TwitterApiConnection apiConnection = new(); public string AccountType @@ -46,7 +46,7 @@ public string AccountType ISocialAccountState ISocialAccount.AccountState => this.AccountState; - public OpenTween.Twitter Legacy + public TwitterLegacy Legacy => this.twLegacy; public PersonId UserId diff --git a/OpenTween/Twitter.cs b/OpenTween/SocialProtocol/Twitter/TwitterLegacy.cs similarity index 98% rename from OpenTween/Twitter.cs rename to OpenTween/SocialProtocol/Twitter/TwitterLegacy.cs index 0d1458bb2..9a135781f 100644 --- a/OpenTween/Twitter.cs +++ b/OpenTween/SocialProtocol/Twitter/TwitterLegacy.cs @@ -29,31 +29,19 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.IO; using System.Linq; -using System.Net; -using System.Net.Http; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; using System.Text.RegularExpressions; -using System.Threading; using System.Threading.Tasks; -using System.Windows.Forms; using OpenTween.Api; using OpenTween.Api.DataModel; using OpenTween.Api.GraphQL; -using OpenTween.Api.TwitterV2; using OpenTween.Connection; using OpenTween.Models; using OpenTween.Setting; -using OpenTween.SocialProtocol.Twitter; -namespace OpenTween +namespace OpenTween.SocialProtocol.Twitter { - public class Twitter : IDisposable + public class TwitterLegacy : IDisposable { #region Regexp from twitter-text-js @@ -181,7 +169,7 @@ public TwitterTextConfiguration TextConfiguration private string? previousStatusId = null; - public Twitter(TwitterApi api) + public TwitterLegacy(TwitterApi api) { this.postFactory = new(TabInformations.GetInstance(), SettingManager.Instance.Common); this.urlExpander = new(ShortUrl.Instance); @@ -210,7 +198,7 @@ public void Initialize(TwitterApiConnection apiConnection, TwitterAccountState a { this.CheckAccountState(); - if (Twitter.DMSendTextRegex.IsMatch(param.Text)) + if (DMSendTextRegex.IsMatch(param.Text)) { var mediaId = param.MediaIds?.FirstOrDefault(); @@ -317,7 +305,7 @@ await Task.Delay(TimeSpan.FromSeconds(processingInfo.CheckAfterSecs ?? 5)) .ConfigureAwait(false); } - succeeded: + succeeded: return mediaId; } @@ -325,7 +313,7 @@ public async Task SendDirectMessage(string postStr, TwitterMediaId? mediaId = nu { this.CheckAccountState(); - var mc = Twitter.DMSendTextRegex.Match(postStr); + var mc = DMSendTextRegex.Match(postStr); var body = mc.Groups["body"].Value; var recipientName = mc.Groups["id"].Value; @@ -824,7 +812,7 @@ internal void CheckAccountState() public int GetTextLengthRemain(string postText) { - var matchDm = Twitter.DMSendTextRegex.Match(postText); + var matchDm = DMSendTextRegex.Match(postText); if (matchDm.Success) return this.GetTextLengthRemainDM(matchDm.Groups["body"].Value); diff --git a/OpenTween/SocialProtocol/Twitter/TwitterPostFactory.cs b/OpenTween/SocialProtocol/Twitter/TwitterPostFactory.cs index 8a9a71f28..c6419e41c 100644 --- a/OpenTween/SocialProtocol/Twitter/TwitterPostFactory.cs +++ b/OpenTween/SocialProtocol/Twitter/TwitterPostFactory.cs @@ -401,7 +401,7 @@ private static string CreateAccessibleText(string text, TwitterEntities? entitie { if (quotedStatus != null) { - var matchStatusUrl = OpenTween.Twitter.StatusUrlRegex.Match(entity.ExpandedUrl); + var matchStatusUrl = TwitterLegacy.StatusUrlRegex.Match(entity.ExpandedUrl); if (matchStatusUrl.Success && matchStatusUrl.Groups["StatusId"].Value == quotedStatus.IdStr) { var quotedText = CreateAccessibleText(quotedStatus.FullText, quotedStatus.MergedEntities, quotedStatus: null, quotedStatusLink: null); @@ -552,7 +552,7 @@ public static IEnumerable GetQuoteTweetStatusIds(IEnumerable LoadProfileImage(string normalImageUrl, string sizeName { try { - var imageUrl = Twitter.CreateProfileImageUrl(normalImageUrl, sizeName); + var imageUrl = TwitterLegacy.CreateProfileImageUrl(normalImageUrl, sizeName); await this.iconCache.DownloadImageAsync(imageUrl); return true; diff --git a/OpenTween/Tween.cs b/OpenTween/Tween.cs index 559dc160b..1785a744d 100644 --- a/OpenTween/Tween.cs +++ b/OpenTween/Tween.cs @@ -3322,7 +3322,7 @@ internal PostStatusParams FormatStatusText(PostStatusParams statusParams, Keys m // 参照: https://support.twitter.com/articles/14020 if (Regex.IsMatch(statusText, @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(d|dm|m)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)", RegexOptions.IgnoreCase) - && !Twitter.DMSendTextRegex.IsMatch(statusText)) + && !TwitterLegacy.DMSendTextRegex.IsMatch(statusText)) { // U+200B (ZERO WIDTH SPACE) を先頭に加えて回避 statusText = '\u200b' + statusText; @@ -5536,7 +5536,7 @@ static void ShowFormatErrorDialog(IWin32Window owner) if (ret != DialogResult.OK) return; - var match = Twitter.StatusUrlRegex.Match(inputText); + var match = TwitterLegacy.StatusUrlRegex.Match(inputText); if (!match.Success) { ShowFormatErrorDialog(this); @@ -6850,7 +6850,7 @@ internal void CheckReplyTo(string statusText) { MatchCollection m; // ハッシュタグの保存 - m = Regex.Matches(statusText, Twitter.Hashtag, RegexOptions.IgnoreCase); + m = Regex.Matches(statusText, TwitterLegacy.Hashtag, RegexOptions.IgnoreCase); var hstr = ""; foreach (Match hm in m) { @@ -9220,7 +9220,7 @@ private void ReplaceAppName() } private async void TwitterApiStatusToolStripMenuItem_Click(object sender, EventArgs e) - => await MyCommon.OpenInBrowserAsync(this, Twitter.ServiceAvailabilityStatusUrl); + => await MyCommon.OpenInBrowserAsync(this, TwitterLegacy.ServiceAvailabilityStatusUrl); private void PostButton_KeyDown(object sender, KeyEventArgs e) { diff --git a/OpenTween/TweetDetailsView.cs b/OpenTween/TweetDetailsView.cs index 157287830..9cfa79129 100644 --- a/OpenTween/TweetDetailsView.cs +++ b/OpenTween/TweetDetailsView.cs @@ -278,7 +278,7 @@ private async Task SetUserPictureAsync(string normalImageUrl, bool force = false this.ClearUserPicture(); - var imageSize = Twitter.DecideProfileImageSize(this.UserPicture.Width); + var imageSize = TwitterLegacy.DecideProfileImageSize(this.UserPicture.Width); if (!force) { var cachedImage = this.IconCache.TryGetLargerOrSameSizeFromCache(normalImageUrl, imageSize); @@ -298,7 +298,7 @@ private async Task SetUserPictureAsync(string normalImageUrl, bool force = false await this.UserPicture.SetImageFromTask( async () => { - var imageUrl = Twitter.CreateProfileImageUrl(normalImageUrl, imageSize); + var imageUrl = TwitterLegacy.CreateProfileImageUrl(normalImageUrl, imageSize); var image = await this.IconCache.DownloadImageAsync(imageUrl, force) .ConfigureAwait(false); @@ -470,7 +470,7 @@ private async Task DoSearchToolStrip(string url) private string? GetUserId() { - var m = Twitter.StatusUrlRegex.Match(this.postBrowserStatusText); + var m = TwitterLegacy.StatusUrlRegex.Match(this.postBrowserStatusText); if (m.Success && this.Owner.IsTwitterId(m.Result("${ScreenName}"))) return m.Result("${ScreenName}"); else @@ -751,7 +751,7 @@ private async void IconNameToolStripMenuItem_Click(object sender, EventArgs e) if (MyCommon.IsNullOrEmpty(imageNormalUrl)) return; - var imageOriginalUrl = Twitter.CreateProfileImageUrl(imageNormalUrl, "original"); + var imageOriginalUrl = TwitterLegacy.CreateProfileImageUrl(imageNormalUrl, "original"); await MyCommon.OpenInBrowserAsync(this, imageOriginalUrl); } diff --git a/OpenTween/TweetExtractor.cs b/OpenTween/TweetExtractor.cs index 84bf1a716..cb8b68dc4 100644 --- a/OpenTween/TweetExtractor.cs +++ b/OpenTween/TweetExtractor.cs @@ -29,6 +29,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using OpenTween.Api.DataModel; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween { @@ -47,7 +48,7 @@ public static IEnumerable ExtractUrls(string text) /// public static IEnumerable ExtractUrlEntities(string text) { - var urlMatches = Regex.Matches(text, Twitter.RgUrl, RegexOptions.IgnoreCase).Cast(); + var urlMatches = Regex.Matches(text, TwitterLegacy.RgUrl, RegexOptions.IgnoreCase).Cast(); foreach (var m in urlMatches) { var before = m.Groups["before"].Value; @@ -59,15 +60,15 @@ public static IEnumerable ExtractUrlEntities(string text) var validUrl = false; if (protocol.Length == 0) { - if (Regex.IsMatch(before, Twitter.UrlInvalidWithoutProtocolPrecedingChars)) + if (Regex.IsMatch(before, TwitterLegacy.UrlInvalidWithoutProtocolPrecedingChars)) continue; var last_url_invalid_match = false; - var domainMatches = Regex.Matches(domain, Twitter.UrlValidAsciiDomain, RegexOptions.IgnoreCase).Cast(); + var domainMatches = Regex.Matches(domain, TwitterLegacy.UrlValidAsciiDomain, RegexOptions.IgnoreCase).Cast(); foreach (var mm in domainMatches) { var lasturl = mm.Value; - last_url_invalid_match = Regex.IsMatch(lasturl, Twitter.UrlInvalidShortDomain, RegexOptions.IgnoreCase); + last_url_invalid_match = Regex.IsMatch(lasturl, TwitterLegacy.UrlInvalidShortDomain, RegexOptions.IgnoreCase); if (!last_url_invalid_match) { validUrl = true; @@ -140,7 +141,7 @@ public static IEnumerable ExtractMentionEntities(string te /// public static IEnumerable ExtractHashtagEntities(string text) { - var matches = Regex.Matches(text, Twitter.Hashtag); + var matches = Regex.Matches(text, TwitterLegacy.Hashtag); foreach (var match in matches.Cast()) { var groupHashtagSharp = match.Groups[2]; diff --git a/OpenTween/UserInfoDialog.cs b/OpenTween/UserInfoDialog.cs index 339b0ff31..9b99236e6 100644 --- a/OpenTween/UserInfoDialog.cs +++ b/OpenTween/UserInfoDialog.cs @@ -48,10 +48,10 @@ public partial class UserInfoDialog : OTBaseForm private CancellationTokenSource? cancellationTokenSource = null; private readonly TweenMain mainForm; - private readonly Twitter twitter; + private readonly TwitterLegacy twitter; private readonly DetailsHtmlBuilder detailsHtmlBuilder; - public UserInfoDialog(TweenMain mainForm, Twitter twitter, DetailsHtmlBuilder detailsHtmlBuilder) + public UserInfoDialog(TweenMain mainForm, TwitterLegacy twitter, DetailsHtmlBuilder detailsHtmlBuilder) { this.mainForm = mainForm; this.twitter = twitter; @@ -207,8 +207,8 @@ private async Task SetUserImageAsync(string imageUri, CancellationToken cancella await this.UserPicture.SetImageFromTask(async () => { - var sizeName = Twitter.DecideProfileImageSize(this.UserPicture.Width); - var uri = Twitter.CreateProfileImageUrl(imageUri, sizeName); + var sizeName = TwitterLegacy.DecideProfileImageSize(this.UserPicture.Width); + var uri = TwitterLegacy.CreateProfileImageUrl(imageUri, sizeName); using var imageStream = await Networking.Http.GetStreamAsync(uri) .ConfigureAwait(false); @@ -468,7 +468,7 @@ private async void ButtonSearchPosts_Click(object sender, EventArgs e) private async void UserPicture_Click(object sender, EventArgs e) { var imageUrl = this.displayUser.ProfileImageUrlHttps; - imageUrl = Twitter.CreateProfileImageUrl(imageUrl, "original"); + imageUrl = TwitterLegacy.CreateProfileImageUrl(imageUrl, "original"); await MyCommon.OpenInBrowserAsync(this, imageUrl); }