diff --git a/OpenTween.Tests/Api/TwitterApiTest.cs b/OpenTween.Tests/Api/TwitterApiTest.cs index 0ab1aad41..96fb47274 100644 --- a/OpenTween.Tests/Api/TwitterApiTest.cs +++ b/OpenTween.Tests/Api/TwitterApiTest.cs @@ -32,7 +32,6 @@ using Moq; using OpenTween.Api.DataModel; using OpenTween.Connection; -using OpenTween.SocialProtocol.Twitter; using Xunit; namespace OpenTween.Api @@ -54,28 +53,21 @@ private void MyCommonSetup() public void Initialize_Test() { using var twitterApi = new TwitterApi(); - var apiConnection = Assert.IsType(twitterApi.Connection); - Assert.IsType(apiConnection.Credential); + var apiConnectionNone = Assert.IsType(twitterApi.Connection); + Assert.IsType(apiConnectionNone.Credential); var credential = new TwitterCredentialOAuth1(TwitterAppToken.GetDefault(), "*** AccessToken ***", "*** AccessSecret ***"); - var accountState = new TwitterAccountState(100L, "hogehoge"); - twitterApi.Initialize(credential, accountState); + using var apiConnection = new TwitterApiConnection(credential, new()); + twitterApi.Initialize(apiConnection); - apiConnection = Assert.IsType(twitterApi.Connection); - Assert.Same(credential, apiConnection.Credential); - Assert.Same(accountState, twitterApi.AccountState); + Assert.Same(apiConnection, twitterApi.Connection); // 複数回 Initialize を実行した場合は新たに TwitterApiConnection が生成される var credential2 = new TwitterCredentialOAuth1(TwitterAppToken.GetDefault(), "*** AccessToken2 ***", "*** AccessSecret2 ***"); - var accountState2 = new TwitterAccountState(200L, "foobar"); - twitterApi.Initialize(credential2, accountState2); + using var apiConnection2 = new TwitterApiConnection(credential2, new()); + twitterApi.Initialize(apiConnection2); - var oldApiConnection = apiConnection; - Assert.True(oldApiConnection.IsDisposed); - - apiConnection = Assert.IsType(twitterApi.Connection); - Assert.Same(credential2, apiConnection.Credential); - Assert.Same(accountState2, twitterApi.AccountState); + Assert.Same(apiConnection2, twitterApi.Connection); } private Mock CreateApiConnectionMock(Action verifyRequest) diff --git a/OpenTween/Api/TwitterApi.cs b/OpenTween/Api/TwitterApi.cs index 3ce2ddd6c..07f6714a1 100644 --- a/OpenTween/Api/TwitterApi.cs +++ b/OpenTween/Api/TwitterApi.cs @@ -32,38 +32,24 @@ using OpenTween.Api.DataModel; using OpenTween.Connection; using OpenTween.Models; -using OpenTween.SocialProtocol.Twitter; namespace OpenTween.Api { public sealed class TwitterApi : IDisposable { - public long CurrentUserId - => this.AccountState.UserId; - - public string CurrentScreenName - => this.AccountState.UserName; - public IApiConnection Connection => this.ApiConnection; internal IApiConnection ApiConnection; - public APIAuthType AuthType { get; private set; } = APIAuthType.None; - - public TwitterAccountState AccountState { get; private set; } = new(); + public APIAuthType AuthType + => ((TwitterApiConnection)this.ApiConnection).Credential.AuthType; public TwitterApi() - => this.ApiConnection = new TwitterApiConnection(new TwitterCredentialNone()); + => this.ApiConnection = new TwitterApiConnection(); - public void Initialize(ITwitterCredential credential, TwitterAccountState accountState) + public void Initialize(IApiConnection apiConnection) { - this.AuthType = credential.AuthType; - - var newInstance = new TwitterApiConnection(credential); - var oldInstance = Interlocked.Exchange(ref this.ApiConnection, newInstance); - oldInstance?.Dispose(); - - this.AccountState = accountState; + this.ApiConnection = apiConnection; } public async Task StatusesHomeTimeline(int? count = null, TwitterStatusId? maxId = null, TwitterStatusId? sinceId = null) diff --git a/OpenTween/AppendSettingDialog.cs b/OpenTween/AppendSettingDialog.cs index 8ce7e7c8d..aecd38fac 100644 --- a/OpenTween/AppendSettingDialog.cs +++ b/OpenTween/AppendSettingDialog.cs @@ -188,7 +188,8 @@ private async void AddAccountButton_Click(object sender, EventArgs e) }; using var twitterApi = new TwitterApi(); - twitterApi.Initialize(new TwitterCredentialCookie(appToken), new()); + using var apiConnection = new TwitterApiConnection(new TwitterCredentialCookie(appToken), new()); + twitterApi.Initialize(apiConnection); var twitterUser = await twitterApi.AccountVerifyCredentials(); newAccount.UserId = twitterUser.Id; newAccount.Username = twitterUser.ScreenName; diff --git a/OpenTween/Connection/TwitterApiConnection.cs b/OpenTween/Connection/TwitterApiConnection.cs index 64833db4f..60c6ec4cf 100644 --- a/OpenTween/Connection/TwitterApiConnection.cs +++ b/OpenTween/Connection/TwitterApiConnection.cs @@ -36,6 +36,7 @@ using System.Web; using OpenTween.Api; using OpenTween.Api.DataModel; +using OpenTween.SocialProtocol.Twitter; namespace OpenTween.Connection { @@ -56,14 +57,17 @@ public static string RestApiHost internal ITwitterCredential Credential { get; } + private readonly TwitterAccountState accountState; + public TwitterApiConnection() - : this(new TwitterCredentialNone()) + : this(new TwitterCredentialNone(), new()) { } - public TwitterApiConnection(ITwitterCredential credential) + public TwitterApiConnection(ITwitterCredential credential, TwitterAccountState accountState) { this.Credential = credential; + this.accountState = accountState; this.InitializeHttpClients(); Networking.WebProxyChanged += this.Networking_WebProxyChanged; @@ -99,7 +103,7 @@ public async Task SendAsync(IHttpRequest request) if (endpointName != null) MyCommon.TwitterApiInfo.UpdateFromHeader(responseMessage.Headers, endpointName); - await TwitterApiConnection.CheckStatusCode(responseMessage) + await TwitterApiConnection.CheckStatusCode(responseMessage, this.accountState) .ConfigureAwait(false); var response = new ApiResponse(responseMessage); @@ -165,13 +169,14 @@ public static async Task HandleTimeout(Func> fu return await task; } - protected static async Task CheckStatusCode(HttpResponseMessage response) + protected static async Task CheckStatusCode(HttpResponseMessage response, TwitterAccountState? accountState) { var statusCode = response.StatusCode; if ((int)statusCode >= 200 && (int)statusCode <= 299) { - Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid; + if (accountState != null) + accountState.HasUnrecoverableError = false; return; } @@ -185,7 +190,10 @@ protected static async Task CheckStatusCode(HttpResponseMessage response) if (string.IsNullOrWhiteSpace(responseText)) { if (statusCode == HttpStatusCode.Unauthorized) - Twitter.AccountState = MyCommon.ACCOUNT_STATE.Invalid; + { + if (accountState != null) + accountState.HasUnrecoverableError = true; + } throw new TwitterApiException(statusCode, responseText); } @@ -200,7 +208,8 @@ protected static async Task CheckStatusCode(HttpResponseMessage response) var errorCodes = error.Errors.Select(x => x.Code); if (errorCodes.Any(x => x == TwitterErrorCode.InternalError || x == TwitterErrorCode.SuspendedAccount)) { - Twitter.AccountState = MyCommon.ACCOUNT_STATE.Invalid; + if (accountState != null) + accountState.HasUnrecoverableError = true; } throw new TwitterApiException(statusCode, error, responseText); @@ -324,7 +333,7 @@ TwitterCredentialOAuth1 credential var responseText = await content.ReadAsStringAsync() .ConfigureAwait(false); - await TwitterApiConnection.CheckStatusCode(response) + await TwitterApiConnection.CheckStatusCode(response, accountState: null) .ConfigureAwait(false); var responseParams = HttpUtility.ParseQueryString(responseText); diff --git a/OpenTween/MyCommon.cs b/OpenTween/MyCommon.cs index 0732c2e2b..64b0fae69 100644 --- a/OpenTween/MyCommon.cs +++ b/OpenTween/MyCommon.cs @@ -191,12 +191,6 @@ public static class DEFAULTTAB public static bool DebugBuild = false; #endif - public enum ACCOUNT_STATE - { - Valid, - Invalid, - } - public enum REPLY_ICONSTATE { None, diff --git a/OpenTween/MyLists.cs b/OpenTween/MyLists.cs index 80fba4739..c0c88306c 100644 --- a/OpenTween/MyLists.cs +++ b/OpenTween/MyLists.cs @@ -43,7 +43,7 @@ namespace OpenTween { public partial class MyLists : OTBaseForm { - private readonly TwitterApi twitterApi = null!; + private readonly Twitter twitter = null!; private readonly string contextScreenName = null!; /// 自分が所有しているリスト @@ -55,11 +55,11 @@ public partial class MyLists : OTBaseForm public MyLists() => this.InitializeComponent(); - public MyLists(string screenName, TwitterApi twitterApi) + public MyLists(string screenName, Twitter twitter) { this.InitializeComponent(); - this.twitterApi = twitterApi; + this.twitter = twitter; this.contextScreenName = screenName; this.Text = screenName + Properties.Resources.MyLists1; @@ -92,13 +92,13 @@ private async Task RefreshListBox() private async Task FetchMembershipListIds() { var ownedListData = await TwitterLists.GetAllItemsAsync(x => - this.twitterApi.ListsOwnerships(this.twitterApi.CurrentScreenName, cursor: x, count: 1000)) + this.twitter.Api.ListsOwnerships(this.twitter.Username, cursor: x, count: 1000)) .ConfigureAwait(false); this.ownedLists = ownedListData.Select(x => new ListElement(x, null!)).ToArray(); var listsUserAddedTo = await TwitterLists.GetAllItemsAsync(x => - this.twitterApi.ListsMemberships(this.contextScreenName, cursor: x, count: 1000, filterToOwnedLists: true)) + this.twitter.Api.ListsMemberships(this.contextScreenName, cursor: x, count: 1000, filterToOwnedLists: true)) .ConfigureAwait(false); this.addedListIds = listsUserAddedTo.Select(x => x.Id).ToArray(); @@ -108,7 +108,7 @@ private async Task AddToList(ListElement list) { try { - await this.twitterApi.ListsMembersCreate(list.Id, this.contextScreenName) + await this.twitter.Api.ListsMembersCreate(list.Id, this.contextScreenName) .IgnoreResponse(); var index = this.ListsCheckedListBox.Items.IndexOf(list); @@ -124,7 +124,7 @@ private async Task RemoveFromList(ListElement list) { try { - await this.twitterApi.ListsMembersDestroy(list.Id, this.contextScreenName) + await this.twitter.Api.ListsMembersDestroy(list.Id, this.contextScreenName) .IgnoreResponse(); var index = this.ListsCheckedListBox.Items.IndexOf(list); diff --git a/OpenTween/SendErrorReportForm.cs b/OpenTween/SendErrorReportForm.cs index c08f947e2..067d030b3 100644 --- a/OpenTween/SendErrorReportForm.cs +++ b/OpenTween/SendErrorReportForm.cs @@ -204,7 +204,7 @@ private bool CheckDmAvailable() if (this.tw == null || !this.tw.AccessLevel.HasFlag(TwitterApiAccessLevel.DirectMessage)) return false; - if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) + if (this.tw.AccountState.HasUnrecoverableError) return false; return true; diff --git a/OpenTween/SocialProtocol/Twitter/TwitterAccount.cs b/OpenTween/SocialProtocol/Twitter/TwitterAccount.cs index 6de15b790..e0a5f3261 100644 --- a/OpenTween/SocialProtocol/Twitter/TwitterAccount.cs +++ b/OpenTween/SocialProtocol/Twitter/TwitterAccount.cs @@ -30,6 +30,7 @@ namespace OpenTween.SocialProtocol.Twitter public class TwitterAccount : ISocialAccount { private readonly OpenTween.Twitter twLegacy = new(new()); + private TwitterApiConnection apiConnection = new(); public Guid UniqueKey { get; } @@ -54,7 +55,7 @@ public APIAuthType AuthType => this.Legacy.Api.AuthType; public IApiConnection Connection - => this.Legacy.Api.Connection; + => this.apiConnection; public TwitterAccount(Guid uniqueKey) { @@ -68,11 +69,20 @@ public void Initialize(UserAccount accountSettings, SettingCommon settingCommon) Debug.Assert(accountSettings.UniqueKey == this.UniqueKey, "UniqueKey must be same as current value."); var credential = accountSettings.GetTwitterCredential(); - this.AccountState = new TwitterAccountState(accountSettings.UserId, accountSettings.Username); + + this.AccountState = new TwitterAccountState(accountSettings.UserId, accountSettings.Username) + { + HasUnrecoverableError = credential is TwitterCredentialNone, + }; + + var newConnection = new TwitterApiConnection(credential, this.AccountState); + (this.apiConnection, var oldConnection) = (newConnection, this.apiConnection); + oldConnection.Dispose(); + this.Query = this.CreateQueryInstance(credential.AuthType); this.Mutation = this.CreateMutationInstance(credential.AuthType); - this.twLegacy.Initialize(credential, this.AccountState); + this.twLegacy.Initialize(newConnection, this.AccountState); this.twLegacy.RestrictFavCheck = settingCommon.RestrictFavCheck; } diff --git a/OpenTween/SocialProtocol/Twitter/TwitterAccountState.cs b/OpenTween/SocialProtocol/Twitter/TwitterAccountState.cs index c9bbb26fd..95dd391bf 100644 --- a/OpenTween/SocialProtocol/Twitter/TwitterAccountState.cs +++ b/OpenTween/SocialProtocol/Twitter/TwitterAccountState.cs @@ -42,6 +42,8 @@ public class TwitterAccountState public ISet NoRetweetUserIds { get; set; } = new HashSet(); + public bool HasUnrecoverableError { get; set; } = true; + public TwitterAccountState() : this(0L, "") { diff --git a/OpenTween/SocialProtocol/Twitter/TwitterGraphqlMutation.cs b/OpenTween/SocialProtocol/Twitter/TwitterGraphqlMutation.cs index 7c550547e..1c88834b6 100644 --- a/OpenTween/SocialProtocol/Twitter/TwitterGraphqlMutation.cs +++ b/OpenTween/SocialProtocol/Twitter/TwitterGraphqlMutation.cs @@ -50,7 +50,7 @@ public async Task DeletePost(PostId postId) TweetId = statusId, }; - await request.Send(this.account.Legacy.Api.Connection) + await request.Send(this.account.Connection) .ConfigureAwait(false); } diff --git a/OpenTween/Tween.cs b/OpenTween/Tween.cs index 98ae2a8cd..f2004e2f0 100644 --- a/OpenTween/Tween.cs +++ b/OpenTween/Tween.cs @@ -1259,22 +1259,22 @@ private void NotifyIcon1_BalloonTipClicked(object sender, EventArgs e) this.BringToFront(); } - private static int errorCount = 0; + private int errorCount = 0; - private static bool CheckAccountValid() + private bool CheckAccountValid() { - if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) + if (this.tw.AccountState.HasUnrecoverableError) { - errorCount += 1; - if (errorCount > 5) + this.errorCount += 1; + if (this.errorCount > 5) { - errorCount = 0; - Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid; + this.errorCount = 0; + this.tw.AccountState.HasUnrecoverableError = false; return true; } return false; } - errorCount = 0; + this.errorCount = 0; return true; } @@ -1366,7 +1366,7 @@ private async Task FavAddAsyncInternal(IProgress p, CancellationToken ct if (ct.IsCancellationRequested) return; - if (!CheckAccountValid()) + if (!this.CheckAccountValid()) throw new WebApiException("Auth error. Check your account"); if (!tab.Posts.TryGetValue(statusId, out var post)) @@ -1480,7 +1480,7 @@ private async Task FavRemoveAsyncInternal(IProgress p, CancellationToken if (ct.IsCancellationRequested) return; - if (!CheckAccountValid()) + if (!this.CheckAccountValid()) throw new WebApiException("Auth error. Check your account"); var successIds = new List(); @@ -1598,7 +1598,7 @@ private async Task PostMessageAsyncInternal( if (ct.IsCancellationRequested) return; - if (!CheckAccountValid()) + if (!this.CheckAccountValid()) throw new WebApiException("Auth error. Check your account"); p.Report("Posting..."); @@ -1739,7 +1739,7 @@ private async Task RetweetAsyncInternal(IProgress p, CancellationToken c if (ct.IsCancellationRequested) return; - if (!CheckAccountValid()) + if (!this.CheckAccountValid()) throw new WebApiException("Auth error. Check your account"); p.Report("Posting..."); @@ -2678,7 +2678,7 @@ private async void SettingStripMenuItem_Click(object sender, EventArgs e) } } - Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid; + this.tw.AccountState.HasUnrecoverableError = false; this.TopMost = this.settings.Common.AlwaysTop; this.SaveConfigsAll(false); @@ -8538,7 +8538,7 @@ private void RetweetedByListManageMenuItem_Click(object sender, EventArgs e) public void ListManageUserContext(string screenName) { - using var listSelectForm = new MyLists(screenName, this.tw.Api); + using var listSelectForm = new MyLists(screenName, this.tw); listSelectForm.ShowDialog(this); } @@ -8817,7 +8817,7 @@ private async Task DoShowUserStatus(string id, bool showInputDialog) private async Task DoShowUserStatus(TwitterUser user) { - using var userDialog = new UserInfoDialog(this, this.tw.Api, this.detailsHtmlBuilder); + using var userDialog = new UserInfoDialog(this, this.tw, this.detailsHtmlBuilder); var showUserTask = userDialog.ShowUserAsync(user); userDialog.ShowDialog(this); diff --git a/OpenTween/Twitter.cs b/OpenTween/Twitter.cs index 4dfdb24c8..d1038d75b 100644 --- a/OpenTween/Twitter.cs +++ b/OpenTween/Twitter.cs @@ -160,6 +160,8 @@ public class Twitter : IDisposable public TwitterApi Api { get; } + public TwitterAccountState AccountState { get; private set; } = new(); + public TwitterConfiguration Configuration { get; private set; } public TwitterTextConfiguration TextConfiguration { get; private set; } @@ -195,7 +197,7 @@ protected void ResetApiStatus() public void ClearAuthInfo() { - Twitter.AccountState = MyCommon.ACCOUNT_STATE.Invalid; + this.AccountState.HasUnrecoverableError = true; this.ResetApiStatus(); } @@ -216,17 +218,15 @@ public async Task VerifyCredentialsAsync() var user = await this.Api.AccountVerifyCredentials() .ConfigureAwait(false); - this.Api.AccountState.UpdateFromUser(user); + this.AccountState.UpdateFromUser(user); } - public void Initialize(ITwitterCredential credential, TwitterAccountState accountState) + public void Initialize(TwitterApiConnection apiConnection, TwitterAccountState accountState) { - // OAuth認証 - if (credential is TwitterCredentialNone) - Twitter.AccountState = MyCommon.ACCOUNT_STATE.Invalid; + this.AccountState = accountState; this.ResetApiStatus(); - this.Api.Initialize(credential, accountState); + this.Api.Initialize(apiConnection); } public async Task PostStatus(PostStatusParams param) @@ -274,7 +274,7 @@ await this.SendDirectMessage(param.Text, mediaId) .ConfigureAwait(false); } - this.Api.AccountState.UpdateFromUser(status.User); + this.AccountState.UpdateFromUser(status.User); if (status.IdStr == this.previousStatusId) throw new WebApiException("OK:Delaying?"); @@ -393,23 +393,21 @@ public async Task GetUserInfo(string screenName) } public string Username - => this.Api.CurrentScreenName; + => this.AccountState.UserName; public long UserId - => this.Api.CurrentUserId; - - public static MyCommon.ACCOUNT_STATE AccountState { get; set; } = MyCommon.ACCOUNT_STATE.Valid; + => this.AccountState.UserId; public bool RestrictFavCheck { get; set; } public int? FollowersCount - => this.Api.AccountState.FollowersCount; + => this.AccountState.FollowersCount; public int? FriendsCount - => this.Api.AccountState.FriendsCount; + => this.AccountState.FriendsCount; public int? StatusesCount - => this.Api.AccountState.StatusesCount; + => this.AccountState.StatusesCount; /// /// 渡された取得件数がWORKERTYPEに応じた取得可能範囲に収まっているか検証する @@ -628,7 +626,7 @@ private PostClass CreatePostsFromStatusData(TwitterStatus status, bool firstLoad internal PostClass CreatePostsFromStatusData(TwitterStatus status, bool firstLoad, bool favTweet) { - var post = this.postFactory.CreateFromStatus(status, this.UserId, this.Api.AccountState.FollowerIds, firstLoad, favTweet); + var post = this.postFactory.CreateFromStatus(status, this.UserId, this.AccountState.FollowerIds, firstLoad, favTweet); _ = this.urlExpander.Expand(post); return post; @@ -644,7 +642,7 @@ internal PostClass[] CreatePostsFromJson(TwitterStatus[] statuses, bool firstLoa } internal PostClass[] FilterNoRetweetUserPosts(PostClass[] posts) - => posts.Where(x => x.RetweetedByUserId == null || !this.Api.AccountState.NoRetweetUserIds.Contains(x.RetweetedByUserId.Value)).ToArray(); + => posts.Where(x => x.RetweetedByUserId == null || !this.AccountState.NoRetweetUserIds.Contains(x.RetweetedByUserId.Value)).ToArray(); public async Task GetListStatus(ListTimelineTabModel tab, bool more, bool firstLoad) { @@ -1089,8 +1087,8 @@ public async Task RefreshFollowerIds() } while (cursor != 0); - this.Api.AccountState.FollowerIds = newFollowerIds.ToHashSet(); - TabInformations.GetInstance().RefreshOwl(this.Api.AccountState.FollowerIds); + this.AccountState.FollowerIds = newFollowerIds.ToHashSet(); + TabInformations.GetInstance().RefreshOwl(this.AccountState.FollowerIds); this.GetFollowersSuccess = true; } @@ -1106,7 +1104,7 @@ public async Task RefreshNoRetweetIds() var noRetweetUserIds = await this.Api.NoRetweetIds() .ConfigureAwait(false); - this.Api.AccountState.NoRetweetUserIds = new HashSet(noRetweetUserIds); + this.AccountState.NoRetweetUserIds = new HashSet(noRetweetUserIds); this.GetNoRetweetSuccess = true; } @@ -1209,7 +1207,8 @@ await this.Api.ListsMembersShow(listId, user) public async Task GetInfoApi() { - if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return null; + if (this.AccountState.HasUnrecoverableError) + return null; if (MyCommon.EndingFlag) return null; @@ -1266,7 +1265,7 @@ public string[] GetHashList() internal void CheckAccountState() { - if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) + if (this.AccountState.HasUnrecoverableError) throw new WebApiException("Auth error. Check your account"); } diff --git a/OpenTween/UserInfoDialog.cs b/OpenTween/UserInfoDialog.cs index e8c06e9cd..ff27d2a65 100644 --- a/OpenTween/UserInfoDialog.cs +++ b/OpenTween/UserInfoDialog.cs @@ -54,13 +54,13 @@ public partial class UserInfoDialog : OTBaseForm private CancellationTokenSource? cancellationTokenSource = null; private readonly TweenMain mainForm; - private readonly TwitterApi twitterApi; + private readonly Twitter twitter; private readonly DetailsHtmlBuilder detailsHtmlBuilder; - public UserInfoDialog(TweenMain mainForm, TwitterApi twitterApi, DetailsHtmlBuilder detailsHtmlBuilder) + public UserInfoDialog(TweenMain mainForm, Twitter twitter, DetailsHtmlBuilder detailsHtmlBuilder) { this.mainForm = mainForm; - this.twitterApi = twitterApi; + this.twitter = twitter; this.detailsHtmlBuilder = detailsHtmlBuilder; this.InitializeComponent(); @@ -138,7 +138,7 @@ public async Task ShowUserAsync(TwitterUser user) this.LinkLabelTweet.Tag = profileUrl; this.ToolTip1.SetToolTip(this.LinkLabelTweet, profileUrl); - if (this.twitterApi.CurrentUserId == user.Id) + if (this.twitter.UserId == user.Id) { this.ButtonEdit.Enabled = true; this.ChangeIconToolStripMenuItem.Enabled = true; @@ -288,13 +288,13 @@ private async Task LoadFriendshipAsync(string screenName, CancellationToken canc this.ButtonFollow.Enabled = false; this.ButtonUnFollow.Enabled = false; - if (this.twitterApi.CurrentScreenName == screenName) + if (this.twitter.Username == screenName) return; TwitterFriendship friendship; try { - friendship = await this.twitterApi.FriendshipsShow(this.twitterApi.CurrentScreenName, screenName); + friendship = await this.twitter.Api.FriendshipsShow(this.twitter.Username, screenName); } catch (WebApiException) { @@ -363,7 +363,7 @@ private async void ButtonFollow_Click(object sender, EventArgs e) { try { - await this.twitterApi.FriendshipsCreate(this.displayUser.ScreenName) + await this.twitter.Api.FriendshipsCreate(this.displayUser.ScreenName) .IgnoreResponse(); } catch (WebApiException ex) @@ -392,7 +392,7 @@ private async void ButtonUnFollow_Click(object sender, EventArgs e) { try { - await this.twitterApi.FriendshipsDestroy(this.displayUser.ScreenName) + await this.twitter.Api.FriendshipsDestroy(this.displayUser.ScreenName) .IgnoreResponse(); } catch (WebApiException ex) @@ -484,7 +484,7 @@ private async void UserPicture_Click(object sender, EventArgs e) private async void ButtonEdit_Click(object sender, EventArgs e) { // 自分以外のプロフィールは変更できない - if (this.twitterApi.CurrentUserId != this.displayUser.Id) + if (this.twitter.UserId != this.displayUser.Id) return; using (ControlTransaction.Disabled(this.ButtonEdit)) @@ -530,7 +530,7 @@ private async void ButtonEdit_Click(object sender, EventArgs e) { try { - using var response = await this.twitterApi.AccountUpdateProfile( + using var response = await this.twitter.Api.AccountUpdateProfile( this.TextBoxName.Text, this.TextBoxWeb.Text, this.TextBoxLocation.Text, @@ -578,7 +578,7 @@ private async Task DoChangeIcon(string filename) { var mediaItem = new FileMediaItem(filename); - await this.twitterApi.AccountUpdateProfileImage(mediaItem) + await this.twitter.Api.AccountUpdateProfileImage(mediaItem) .IgnoreResponse(); } catch (WebApiException ex) @@ -591,7 +591,7 @@ await this.twitterApi.AccountUpdateProfileImage(mediaItem) try { - var user = await this.twitterApi.UsersShow(this.displayUser.ScreenName); + var user = await this.twitter.Api.UsersShow(this.displayUser.ScreenName); if (user != null) await this.ShowUserAsync(user); @@ -639,7 +639,7 @@ private async void ButtonBlock_Click(object sender, EventArgs e) { try { - await this.twitterApi.BlocksCreate(this.displayUser.ScreenName) + await this.twitter.Api.BlocksCreate(this.displayUser.ScreenName) .IgnoreResponse(); } catch (WebApiException ex) @@ -666,7 +666,7 @@ private async void ButtonReportSpam_Click(object sender, EventArgs e) { try { - await this.twitterApi.UsersReportSpam(this.displayUser.ScreenName) + await this.twitter.Api.UsersReportSpam(this.displayUser.ScreenName) .IgnoreResponse(); } catch (WebApiException ex) @@ -693,7 +693,7 @@ private async void ButtonBlockDestroy_Click(object sender, EventArgs e) { try { - await this.twitterApi.BlocksDestroy(this.displayUser.ScreenName) + await this.twitter.Api.BlocksDestroy(this.displayUser.ScreenName) .IgnoreResponse(); } catch (WebApiException ex)