using Moq;
using OpenTween.Api.DataModel;
using OpenTween.Connection;
-using OpenTween.SocialProtocol.Twitter;
using Xunit;
namespace OpenTween.Api
Assert.IsType<TwitterCredentialNone>(apiConnectionNone.Credential);
var credential = new TwitterCredentialOAuth1(TwitterAppToken.GetDefault(), "*** AccessToken ***", "*** AccessSecret ***");
- var accountState = new TwitterAccountState(100L, "hogehoge");
- using var apiConnection = new TwitterApiConnection(credential, accountState);
- twitterApi.Initialize(apiConnection, accountState);
+ using var apiConnection = new TwitterApiConnection(credential, new());
+ twitterApi.Initialize(apiConnection);
Assert.Same(apiConnection, twitterApi.Connection);
- Assert.Same(accountState, twitterApi.AccountState);
// 複数回 Initialize を実行した場合は新たに TwitterApiConnection が生成される
var credential2 = new TwitterCredentialOAuth1(TwitterAppToken.GetDefault(), "*** AccessToken2 ***", "*** AccessSecret2 ***");
- var accountState2 = new TwitterAccountState(200L, "foobar");
- using var apiConnection2 = new TwitterApiConnection(credential2, accountState2);
- twitterApi.Initialize(apiConnection2, accountState2);
+ using var apiConnection2 = new TwitterApiConnection(credential2, new());
+ twitterApi.Initialize(apiConnection2);
Assert.Same(apiConnection2, twitterApi.Connection);
- Assert.Same(accountState2, twitterApi.AccountState);
}
private Mock<IApiConnection> CreateApiConnectionMock<T>(Action<T> verifyRequest)
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
=> ((TwitterApiConnection)this.ApiConnection).Credential.AuthType;
- public TwitterAccountState AccountState { get; private set; } = new();
-
public TwitterApi()
=> this.ApiConnection = new TwitterApiConnection();
- public void Initialize(IApiConnection apiConnection, TwitterAccountState accountState)
+ public void Initialize(IApiConnection apiConnection)
{
this.ApiConnection = apiConnection;
- this.AccountState = accountState;
}
public async Task<TwitterStatus[]> StatusesHomeTimeline(int? count = null, TwitterStatusId? maxId = null, TwitterStatusId? sinceId = null)
using var twitterApi = new TwitterApi();
using var apiConnection = new TwitterApiConnection(new TwitterCredentialCookie(appToken), new());
- twitterApi.Initialize(apiConnection, new());
+ twitterApi.Initialize(apiConnection);
var twitterUser = await twitterApi.AccountVerifyCredentials();
newAccount.UserId = twitterUser.Id;
newAccount.Username = twitterUser.ScreenName;
if (this.tw == null || !this.tw.AccessLevel.HasFlag(TwitterApiAccessLevel.DirectMessage))
return false;
- if (this.tw.Api.AccountState.HasUnrecoverableError)
+ if (this.tw.AccountState.HasUnrecoverableError)
return false;
return true;
private bool CheckAccountValid()
{
- if (this.tw.Api.AccountState.HasUnrecoverableError)
+ if (this.tw.AccountState.HasUnrecoverableError)
{
this.errorCount += 1;
if (this.errorCount > 5)
{
this.errorCount = 0;
- this.tw.Api.AccountState.HasUnrecoverableError = false;
+ this.tw.AccountState.HasUnrecoverableError = false;
return true;
}
return false;
}
}
- this.tw.Api.AccountState.HasUnrecoverableError = false;
+ this.tw.AccountState.HasUnrecoverableError = false;
this.TopMost = this.settings.Common.AlwaysTop;
this.SaveConfigsAll(false);
public TwitterApi Api { get; }
+ public TwitterAccountState AccountState { get; private set; } = new();
+
public TwitterConfiguration Configuration { get; private set; }
public TwitterTextConfiguration TextConfiguration { get; private set; }
public void ClearAuthInfo()
{
- this.Api.AccountState.HasUnrecoverableError = true;
+ this.AccountState.HasUnrecoverableError = true;
this.ResetApiStatus();
}
var user = await this.Api.AccountVerifyCredentials()
.ConfigureAwait(false);
- this.Api.AccountState.UpdateFromUser(user);
+ this.AccountState.UpdateFromUser(user);
}
public void Initialize(TwitterApiConnection apiConnection, TwitterAccountState accountState)
{
+ this.AccountState = accountState;
+
this.ResetApiStatus();
- this.Api.Initialize(apiConnection, accountState);
+ this.Api.Initialize(apiConnection);
}
public async Task<PostClass?> PostStatus(PostStatusParams param)
.ConfigureAwait(false);
}
- this.Api.AccountState.UpdateFromUser(status.User);
+ this.AccountState.UpdateFromUser(status.User);
if (status.IdStr == this.previousStatusId)
throw new WebApiException("OK:Delaying?");
}
public string Username
- => this.Api.CurrentScreenName;
+ => this.AccountState.UserName;
public long UserId
- => this.Api.CurrentUserId;
+ => 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;
/// <summary>
/// 渡された取得件数がWORKERTYPEに応じた取得可能範囲に収まっているか検証する
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;
}
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)
{
}
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;
}
var noRetweetUserIds = await this.Api.NoRetweetIds()
.ConfigureAwait(false);
- this.Api.AccountState.NoRetweetUserIds = new HashSet<long>(noRetweetUserIds);
+ this.AccountState.NoRetweetUserIds = new HashSet<long>(noRetweetUserIds);
this.GetNoRetweetSuccess = true;
}
public async Task<TwitterApiStatus?> GetInfoApi()
{
- if (this.Api.AccountState.HasUnrecoverableError)
+ if (this.AccountState.HasUnrecoverableError)
return null;
if (MyCommon.EndingFlag) return null;
internal void CheckAccountState()
{
- if (this.Api.AccountState.HasUnrecoverableError)
+ if (this.AccountState.HasUnrecoverableError)
throw new WebApiException("Auth error. Check your account");
}