OSDN Git Service

TwitterApiクラスにCurrentUserId, CurrentScreenNameプロパティを追加
authorKimura Youichi <kim.upsilon@bucyou.net>
Thu, 28 Apr 2016 01:41:21 +0000 (10:41 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Thu, 28 Apr 2016 14:55:15 +0000 (23:55 +0900)
OpenTween.Tests/Api/TwitterApiTest.cs
OpenTween/Api/TwitterApi.cs
OpenTween/AppendSettingDialog.cs
OpenTween/Tween.cs

index f243b65..df1c608 100644 (file)
@@ -56,7 +56,7 @@ namespace OpenTween.Api
             {
                 Assert.Null(twitterApi.apiConnection);
 
-                twitterApi.Initialize("*** AccessToken ***", "*** AccessSecret ***");
+                twitterApi.Initialize("*** AccessToken ***", "*** AccessSecret ***", userId: 100L, screenName: "hogehoge");
 
                 Assert.IsType<TwitterApiConnection>(twitterApi.apiConnection);
 
@@ -64,8 +64,11 @@ namespace OpenTween.Api
                 Assert.Equal("*** AccessToken ***", apiConnection.AccessToken);
                 Assert.Equal("*** AccessSecret ***", apiConnection.AccessSecret);
 
+                Assert.Equal(100L, twitterApi.CurrentUserId);
+                Assert.Equal("hogehoge", twitterApi.CurrentScreenName);
+
                 // 複数回 Initialize を実行した場合は新たに TwitterApiConnection が生成される
-                twitterApi.Initialize("*** AccessToken2 ***", "*** AccessSecret2 ***");
+                twitterApi.Initialize("*** AccessToken2 ***", "*** AccessSecret2 ***", userId: 200L, screenName: "foobar");
 
                 var oldApiConnection = apiConnection;
                 Assert.True(oldApiConnection.IsDisposed);
@@ -75,6 +78,9 @@ namespace OpenTween.Api
                 apiConnection = (TwitterApiConnection)twitterApi.apiConnection;
                 Assert.Equal("*** AccessToken2 ***", apiConnection.AccessToken);
                 Assert.Equal("*** AccessSecret2 ***", apiConnection.AccessSecret);
+
+                Assert.Equal(200L, twitterApi.CurrentUserId);
+                Assert.Equal("foobar", twitterApi.CurrentScreenName);
             }
         }
 
index 8ca41cd..cfeda43 100644 (file)
@@ -32,13 +32,19 @@ namespace OpenTween.Api
 {
     public sealed class TwitterApi : IDisposable
     {
+        public long CurrentUserId { get; private set; }
+        public string CurrentScreenName { get; private set; }
+
         internal IApiConnection apiConnection;
 
-        public void Initialize(string accessToken, string accessSecret)
+        public void Initialize(string accessToken, string accessSecret, long userId, string screenName)
         {
             var newInstance = new TwitterApiConnection(accessToken, accessSecret);
             var oldInstance = Interlocked.Exchange(ref this.apiConnection, newInstance);
             oldInstance?.Dispose();
+
+            this.CurrentUserId = userId;
+            this.CurrentScreenName = screenName;
         }
 
         public Task<TwitterStatus> StatusesShow(long statusId)
index 806dab5..9d3115f 100644 (file)
@@ -112,7 +112,7 @@ namespace OpenTween
             {
                 var u = settingCommon.UserAccounts[userAccountIdx];
                 this.tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
-                this.twitterApi.Initialize(u.Token, u.TokenSecret);
+                this.twitterApi.Initialize(u.Token, u.TokenSecret, u.UserId, u.Username);
 
                 if (u.UserId == 0)
                 {
index f0727da..4f9a89d 100644 (file)
@@ -781,7 +781,7 @@ namespace OpenTween
             //認証関連
             if (string.IsNullOrEmpty(this._cfgCommon.Token)) this._cfgCommon.UserName = "";
             tw.Initialize(this._cfgCommon.Token, this._cfgCommon.TokenSecret, this._cfgCommon.UserName, this._cfgCommon.UserId);
-            this.twitterApi.Initialize(this._cfgCommon.Token, this._cfgCommon.TokenSecret);
+            this.twitterApi.Initialize(this._cfgCommon.Token, this._cfgCommon.TokenSecret, this._cfgCommon.UserId, this._cfgCommon.UserName);
 
             _initial = true;
 
@@ -4380,7 +4380,7 @@ namespace OpenTween
             {
                 // キャンセル時は Twitter クラスの認証情報を画面表示前の状態に戻す
                 this.tw.Initialize(oldUser.AccessToken, oldUser.AccessTokenSecret, oldUser.Username, oldUser.UserId);
-                this.twitterApi.Initialize(oldUser.AccessToken, oldUser.AccessTokenSecret);
+                this.twitterApi.Initialize(oldUser.AccessToken, oldUser.AccessTokenSecret, oldUser.UserId, oldUser.Username);
             }
 
             Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;