Skip to content

Commit

Permalink
ITwitterCredential.AuthTypeを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Dec 10, 2023
1 parent f2c5fb9 commit 043b57e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions OpenTween/Api/TwitterApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public sealed class TwitterApi : IDisposable

internal IApiConnectionLegacy ApiConnection;

public TwitterAppToken AppToken { get; private set; } = TwitterAppToken.GetDefault();
public APIAuthType AuthType { get; private set; } = APIAuthType.None;

public TwitterApi()
=> this.ApiConnection = new TwitterApiConnection(new TwitterCredentialNone());

public void Initialize(ITwitterCredential credential, long userId, string screenName)
{
this.AppToken = credential.AppToken;
this.AuthType = credential.AuthType;

var newInstance = new TwitterApiConnection(credential);
var oldInstance = Interlocked.Exchange(ref this.ApiConnection, newInstance);
Expand Down
2 changes: 1 addition & 1 deletion OpenTween/Connection/ITwitterCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace OpenTween.Connection
{
public interface ITwitterCredential
{
TwitterAppToken AppToken { get; }
APIAuthType AuthType { get; }

HttpMessageHandler CreateHttpHandler(HttpMessageHandler innerHandler);
}
Expand Down
3 changes: 3 additions & 0 deletions OpenTween/Connection/TwitterCredentialCookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace OpenTween.Connection
{
public class TwitterCredentialCookie : ITwitterCredential
{
public APIAuthType AuthType
=> APIAuthType.TwitterComCookie;

public TwitterAppToken AppToken { get; }

public TwitterCredentialCookie(TwitterAppToken appToken)
Expand Down
4 changes: 2 additions & 2 deletions OpenTween/Connection/TwitterCredentialNone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace OpenTween.Connection
{
public class TwitterCredentialNone : ITwitterCredential
{
public TwitterAppToken AppToken
=> TwitterAppToken.GetDefault();
public APIAuthType AuthType
=> APIAuthType.None;

public HttpMessageHandler CreateHttpHandler(HttpMessageHandler innerHandler)
=> innerHandler;
Expand Down
3 changes: 3 additions & 0 deletions OpenTween/Connection/TwitterCredentialOAuth1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace OpenTween.Connection
{
public class TwitterCredentialOAuth1 : ITwitterCredential
{
public APIAuthType AuthType
=> APIAuthType.OAuth1;

public TwitterAppToken AppToken { get; }

public string Token { get; }
Expand Down
1 change: 1 addition & 0 deletions OpenTween/Setting/SettingCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ public override string ToString()

public enum APIAuthType
{
None,
OAuth1,
TwitterComCookie,
}
Expand Down
4 changes: 2 additions & 2 deletions OpenTween/Tween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ private async void PostButton_Click(object sender, EventArgs e)
var status = new PostStatusParams();

var statusTextCompat = this.FormatStatusText(this.StatusText.Text);
if (this.GetRestStatusCount(statusTextCompat) >= 0 && this.tw.Api.AppToken.AuthType == APIAuthType.OAuth1)
if (this.GetRestStatusCount(statusTextCompat) >= 0 && this.tw.Api.AuthType == APIAuthType.OAuth1)
{
// auto_populate_reply_metadata や attachment_url を使用しなくても 140 字以内に
// 収まる場合はこれらのオプションを使用せずに投稿する
Expand Down Expand Up @@ -7047,7 +7047,7 @@ private void SetApiStatusLabel(string? endpointName = null)

if (endpointName == null)
{
var authByCookie = this.tw.Api.AppToken.AuthType == APIAuthType.TwitterComCookie;
var authByCookie = this.tw.Api.AuthType == APIAuthType.TwitterComCookie;

// 表示中のタブに応じて更新
endpointName = tabType switch
Expand Down
18 changes: 9 additions & 9 deletions OpenTween/Twitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ await this.SendDirectMessage(param.Text, mediaId)

TwitterStatus status;

if (this.Api.AppToken.AuthType == APIAuthType.TwitterComCookie)
if (this.Api.AuthType == APIAuthType.TwitterComCookie)
{
var request = new CreateTweetRequest
{
Expand Down Expand Up @@ -287,7 +287,7 @@ await this.SendDirectMessage(param.Text, mediaId)

public async Task DeleteTweet(TwitterStatusId tweetId)
{
if (this.Api.AppToken.AuthType == APIAuthType.TwitterComCookie)
if (this.Api.AuthType == APIAuthType.TwitterComCookie)
{
var request = new DeleteTweetRequest
{
Expand Down Expand Up @@ -393,7 +393,7 @@ await this.CreateDirectMessagesEventFromJson(messageEventSingle, read: true)

var target = post.RetweetedId ?? id; // 再RTの場合は元発言をRT

if (this.Api.AppToken.AuthType == APIAuthType.TwitterComCookie)
if (this.Api.AuthType == APIAuthType.TwitterComCookie)
{
var request = new CreateRetweetRequest
{
Expand Down Expand Up @@ -435,7 +435,7 @@ public async Task DeleteRetweet(PostClass post)
if (post.RetweetedId == null)
throw new ArgumentException("post is not retweeted status", nameof(post));

if (this.Api.AppToken.AuthType == APIAuthType.TwitterComCookie)
if (this.Api.AuthType == APIAuthType.TwitterComCookie)
{
var request = new DeleteRetweetRequest
{
Expand All @@ -452,7 +452,7 @@ await this.Api.StatusesDestroy(post.StatusId.ToTwitterStatusId())

public async Task<TwitterUser> GetUserInfo(string screenName)
{
if (this.Api.AppToken.AuthType == APIAuthType.TwitterComCookie)
if (this.Api.AuthType == APIAuthType.TwitterComCookie)
{
var request = new UserByScreenNameRequest
{
Expand Down Expand Up @@ -655,7 +655,7 @@ public async Task GetUserTimelineApi(bool read, UserTimelineTabModel tab, bool m
var count = GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, more, false);

TwitterStatus[] statuses;
if (this.Api.AppToken.AuthType == APIAuthType.TwitterComCookie)
if (this.Api.AuthType == APIAuthType.TwitterComCookie)
{
var userId = tab.UserId;
if (MyCommon.IsNullOrEmpty(userId))
Expand Down Expand Up @@ -711,7 +711,7 @@ public async Task<PostClass> GetStatusApi(bool read, TwitterStatusId id)
this.CheckAccountState();

TwitterStatus status;
if (this.Api.AppToken.AuthType == APIAuthType.TwitterComCookie)
if (this.Api.AuthType == APIAuthType.TwitterComCookie)
{
var request = new TweetDetailRequest
{
Expand Down Expand Up @@ -867,7 +867,7 @@ public async Task GetListStatus(bool read, ListTimelineTabModel tab, bool more,
var count = GetApiResultCount(MyCommon.WORKERTYPE.List, more, startup);

TwitterStatus[] statuses;
if (this.Api.AppToken.AuthType == APIAuthType.TwitterComCookie)
if (this.Api.AuthType == APIAuthType.TwitterComCookie)
{
var request = new ListLatestTweetsTimelineRequest(tab.ListInfo.Id.ToString())
{
Expand Down Expand Up @@ -1077,7 +1077,7 @@ public async Task GetSearch(bool read, PublicSearchTabModel tab, bool more)
var count = GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, more, false);

TwitterStatus[] statuses;
if (this.Api.AppToken.AuthType == APIAuthType.TwitterComCookie)
if (this.Api.AuthType == APIAuthType.TwitterComCookie)
{
var request = new SearchTimelineRequest(tab.SearchWords)
{
Expand Down

0 comments on commit 043b57e

Please sign in to comment.