OSDN Git Service

TweenMain内のIServiceAccountで代替可能な箇所を置き換える
authorKimura Youichi <kim.upsilon@bucyou.net>
Tue, 16 Jan 2024 18:04:53 +0000 (03:04 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Tue, 16 Jan 2024 19:40:31 +0000 (04:40 +0900)
OpenTween/Tween.cs

index 93c423c..ea324c8 100644 (file)
@@ -114,9 +114,12 @@ namespace OpenTween
         private readonly AccountCollection accounts;
 
 #pragma warning disable SA1300
-        private Twitter tw => ((TwitterAccount)this.accounts.Primary).Legacy; // AccountCollection への移行用
+        private Twitter tw => ((TwitterAccount)this.PrimaryAccount).Legacy; // AccountCollection への移行用
 #pragma warning restore SA1300
 
+        private ISocialAccount PrimaryAccount
+            => this.accounts.Primary;
+
         // Growl呼び出し部
         private readonly GrowlHelper gh = new(ApplicationSettings.ApplicationName);
 
@@ -313,7 +316,7 @@ namespace OpenTween
             imgazyobizinet.Enabled = this.settings.Common.EnableImgAzyobuziNet;
             imgazyobizinet.DisabledInDM = this.settings.Common.ImgAzyobuziNetDisabledInDM;
 
-            Thumbnail.Services.TonTwitterCom.GetApiConnection = () => this.tw.Api.Connection;
+            Thumbnail.Services.TonTwitterCom.GetApiConnection = () => this.PrimaryAccount.Connection;
 
             // 画像投稿サービス
             this.ImageSelector.Model.InitializeServices(this.tw, this.tw.Configuration);
@@ -903,7 +906,8 @@ namespace OpenTween
         {
             if (this.settings.Common.ReadOwnPost)
             {
-                if (notifyPosts != null && notifyPosts.Length > 0 && notifyPosts.All(x => x.UserId == this.tw.UserId))
+                var primaryUserId = this.PrimaryAccount.UserId;
+                if (notifyPosts != null && notifyPosts.Length > 0 && notifyPosts.All(x => x.UserId == primaryUserId))
                     return;
             }
 
@@ -949,7 +953,7 @@ namespace OpenTween
                             GrowlHelper.NotifyType nt;
                             if (this.settings.Common.DispUsername)
                             {
-                                title.Append(this.tw.Username);
+                                title.Append(this.PrimaryAccount.UserName);
                                 title.Append(" - ");
                             }
 
@@ -1007,7 +1011,7 @@ namespace OpenTween
                         ToolTipIcon ntIcon;
                         if (this.settings.Common.DispUsername)
                         {
-                            title.Append(this.tw.Username);
+                            title.Append(this.PrimaryAccount.UserName);
                             title.Append(" - ");
                         }
 
@@ -2232,7 +2236,7 @@ namespace OpenTween
                 this.StatusOpenMenuItem.Enabled = true;
                 this.ShowRelatedStatusesMenuItem.Enabled = true;  // PublicSearchの時問題出るかも
 
-                if (!post.CanRetweetBy(this.tw.UserId))
+                if (!post.CanRetweetBy(this.PrimaryAccount.UserId))
                 {
                     this.ReTweetStripMenuItem.Enabled = false;
                     this.ReTweetUnofficialStripMenuItem.Enabled = false;
@@ -2261,8 +2265,9 @@ namespace OpenTween
 
             if (this.ExistCurrentPost && post != null)
             {
-                this.DeleteStripMenuItem.Enabled = post.CanDeleteBy(this.tw.UserId);
-                if (post.RetweetedByUserId == this.tw.UserId)
+                var primaryUserId = this.PrimaryAccount.UserId;
+                this.DeleteStripMenuItem.Enabled = post.CanDeleteBy(primaryUserId);
+                if (post.RetweetedByUserId == primaryUserId)
                     this.DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
                 else
                     this.DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
@@ -2282,7 +2287,8 @@ namespace OpenTween
                 return;
 
             // 選択されたツイートの中に削除可能なものが一つでもあるか
-            if (!posts.Any(x => x.CanDeleteBy(this.tw.UserId)))
+            var primaryUserId = this.PrimaryAccount.UserId;
+            if (!posts.Any(x => x.CanDeleteBy(primaryUserId)))
                 return;
 
             var ret = MessageBox.Show(
@@ -2303,7 +2309,7 @@ namespace OpenTween
                 Exception? lastException = null;
                 foreach (var post in posts)
                 {
-                    if (!post.CanDeleteBy(this.tw.UserId))
+                    if (!post.CanDeleteBy(primaryUserId))
                         continue;
 
                     try
@@ -2314,7 +2320,7 @@ namespace OpenTween
                         }
                         else
                         {
-                            if (post.RetweetedByUserId == this.tw.UserId)
+                            if (post.RetweetedByUserId == primaryUserId)
                             {
                                 // 自分が RT したツイート (自分が RT した自分のツイートも含む)
                                 //   => RT を取り消し
@@ -2322,7 +2328,7 @@ namespace OpenTween
                             }
                             else
                             {
-                                if (post.UserId == this.tw.UserId)
+                                if (post.UserId == primaryUserId)
                                 {
                                     if (post.RetweetedId != null)
                                     {
@@ -2681,7 +2687,7 @@ namespace OpenTween
             this.TopMost = this.settings.Common.AlwaysTop;
             this.SaveConfigsAll(false);
 
-            if (this.tw.UserId != previousUserId)
+            if (this.PrimaryAccount.UserId != previousUserId)
                 await this.DoGetFollowersMenu();
         }
 
@@ -3508,9 +3514,10 @@ namespace OpenTween
                 disableFooter = true;
 
             // 自分宛のリプライの場合は先頭の「@screen_name 」の部分を除去する (in_reply_to_status_id は維持される)
-            if (this.inReplyTo != null && this.inReplyTo.Value.ScreenName == this.tw.Username)
+            var primaryUserName = this.PrimaryAccount.UserName;
+            if (this.inReplyTo != null && this.inReplyTo.Value.ScreenName == primaryUserName)
             {
-                var mentionSelf = $"@{this.tw.Username} ";
+                var mentionSelf = $"@{primaryUserName} ";
                 if (statusText.StartsWith(mentionSelf, StringComparison.OrdinalIgnoreCase))
                 {
                     if (statusText.Length > mentionSelf.Length || this.GetSelectedImageService() != null)
@@ -6031,7 +6038,7 @@ namespace OpenTween
                 this.inReplyTo = null;
             }
 
-            var selfScreenName = this.tw.Username;
+            var selfScreenName = this.PrimaryAccount.UserName;
             var targetScreenNames = new List<string>();
             foreach (var post in selectedPosts)
             {
@@ -6865,7 +6872,7 @@ namespace OpenTween
                 }
             }
 
-            if (this.settings.Common.DispUsername) ttl.Append(this.tw.Username).Append(" - ");
+            if (this.settings.Common.DispUsername) ttl.Append(this.PrimaryAccount.UserName).Append(" - ");
             ttl.Append(ApplicationSettings.ApplicationName);
             ttl.Append("  ");
             switch (this.settings.Common.DispLatestPost)
@@ -7027,7 +7034,7 @@ namespace OpenTween
             ur.Remove(0, ur.Length);
             if (this.settings.Common.DispUsername)
             {
-                ur.Append(this.tw.Username);
+                ur.Append(this.PrimaryAccount.UserName);
                 ur.Append(" - ");
             }
             ur.Append(ApplicationSettings.ApplicationName);
@@ -7996,8 +8003,9 @@ namespace OpenTween
             if (this.ExistCurrentPost)
             {
                 var selectedPosts = this.CurrentTab.SelectedPosts;
+                var primaryUserId = this.PrimaryAccount.UserId;
 
-                if (selectedPosts.Any(x => !x.CanRetweetBy(this.tw.UserId)))
+                if (selectedPosts.Any(x => !x.CanRetweetBy(primaryUserId)))
                 {
                     if (selectedPosts.Any(x => x.IsProtect))
                         MessageBox.Show("Protected.");
@@ -8338,7 +8346,7 @@ namespace OpenTween
 
                 try
                 {
-                    var task = this.tw.Api.FriendshipsShow(this.tw.Username, id);
+                    var task = this.tw.Api.FriendshipsShow(this.PrimaryAccount.UserName, id);
                     var friendship = await dialog.WaitForAsync(this, task);
 
                     isFollowing = friendship.Relationship.Source.Following;
@@ -8388,7 +8396,7 @@ namespace OpenTween
 
                     try
                     {
-                        var task = this.tw.Api.FriendshipsShow(this.tw.Username, id);
+                        var task = this.tw.Api.FriendshipsShow(this.PrimaryAccount.UserName, id);
                         var friendship = await dialog.WaitForAsync(this, task);
 
                         isFollowing = friendship.Relationship.Source.Following;
@@ -8448,7 +8456,7 @@ namespace OpenTween
         }
 
         private async void OwnStatusMenuItem_Click(object sender, EventArgs e)
-            => await this.DoShowUserStatus(this.tw.Username, false);
+            => await this.DoShowUserStatus(this.PrimaryAccount.UserName, false);
 
         // TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない)
         // URLから切り出した文字列を渡す
@@ -8789,7 +8797,7 @@ namespace OpenTween
                 this.OpenStatusOpMenuItem.Enabled = true;
                 this.ShowRelatedStatusesMenuItem2.Enabled = true;  // PublicSearchの時問題出るかも
 
-                if (!post.CanRetweetBy(this.tw.UserId))
+                if (!post.CanRetweetBy(this.PrimaryAccount.UserId))
                 {
                     this.RtOpMenuItem.Enabled = false;
                     this.RtUnOpMenuItem.Enabled = false;
@@ -8826,7 +8834,7 @@ namespace OpenTween
 
             if (this.ExistCurrentPost && post != null)
             {
-                this.DelOpMenuItem.Enabled = post.CanDeleteBy(this.tw.UserId);
+                this.DelOpMenuItem.Enabled = post.CanDeleteBy(this.PrimaryAccount.UserId);
             }
         }
 
@@ -9268,7 +9276,7 @@ namespace OpenTween
         }
 
         private async void OpenOwnHomeMenuItem_Click(object sender, EventArgs e)
-            => await MyCommon.OpenInBrowserAsync(this, MyCommon.TwitterUrl + this.tw.Username);
+            => await MyCommon.OpenInBrowserAsync(this, MyCommon.TwitterUrl + this.PrimaryAccount.UserName);
 
         private bool ExistCurrentPost
         {