}
[Fact]
- public void Query_V1_Test()
+ public void Client_V1_Test()
{
var accountKey = Guid.NewGuid();
using var account = new TwitterAccount(accountKey);
var settingCommon = new SettingCommon();
account.Initialize(accountSettings, settingCommon);
- Assert.IsType<TwitterV1Query>(account.Query);
+ Assert.IsType<TwitterV1Client>(account.Client);
}
[Fact]
- public void Query_Graphql_Test()
+ public void Client_Graphql_Test()
{
var accountKey = Guid.NewGuid();
using var account = new TwitterAccount(accountKey);
var settingCommon = new SettingCommon();
account.Initialize(accountSettings, settingCommon);
- Assert.IsType<TwitterGraphqlQuery>(account.Query);
- }
-
- [Fact]
- public void Mutation_V1_Test()
- {
- var accountKey = Guid.NewGuid();
- using var account = new TwitterAccount(accountKey);
-
- var accountSettings = new UserAccount
- {
- UniqueKey = accountKey,
- TwitterAuthType = APIAuthType.OAuth1,
- Token = "aaaaa",
- TokenSecret = "aaaaa",
- UserId = 11111L,
- Username = "tetete",
- };
- var settingCommon = new SettingCommon();
- account.Initialize(accountSettings, settingCommon);
-
- Assert.IsType<TwitterV1Mutation>(account.Mutation);
- }
-
- [Fact]
- public void Mutation_Graphql_Test()
- {
- var accountKey = Guid.NewGuid();
- using var account = new TwitterAccount(accountKey);
-
- var accountSettings = new UserAccount
- {
- UniqueKey = accountKey,
- TwitterAuthType = APIAuthType.TwitterComCookie,
- TwitterComCookie = "auth_token=foo; ct0=bar",
- UserId = 11111L,
- Username = "tetete",
- };
- var settingCommon = new SettingCommon();
- account.Initialize(accountSettings, settingCommon);
-
- Assert.IsType<TwitterGraphqlMutation>(account.Mutation);
+ Assert.IsType<TwitterGraphqlClient>(account.Client);
}
}
}
var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, backward, firstLoad);
var cursor = backward ? this.CursorBottom : this.CursorTop;
- var response = await account.Query.GetHomeTimeline(count, cursor, firstLoad)
+ var response = await account.Client.GetHomeTimeline(count, cursor, firstLoad)
.ConfigureAwait(false);
foreach (var post in response.Posts)
public IApiConnection Connection { get; }
- public ISocialProtocolQuery Query { get; }
-
- public ISocialProtocolMutation Mutation { get; }
+ public ISocialProtocolClient Client { get; }
public bool IsDisposed { get; }
namespace OpenTween.SocialProtocol
{
- public interface ISocialProtocolMutation
+ public interface ISocialProtocolClient
{
+ public Task<TimelineResponse> GetHomeTimeline(int count, IQueryCursor? cursor, bool firstLoad);
+
public Task DeletePost(PostId postId);
public Task FavoritePost(PostId postId);
+++ /dev/null
-// OpenTween - Client of Twitter
-// Copyright (c) 2024 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
-// All rights reserved.
-//
-// This file is part of OpenTween.
-//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by the Free
-// Software Foundation; either version 3 of the License, or (at your option)
-// any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-// for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
-// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
-// Boston, MA 02110-1301, USA.
-
-#nullable enable
-
-using System.Threading.Tasks;
-using OpenTween.Models;
-
-namespace OpenTween.SocialProtocol
-{
- public interface ISocialProtocolQuery
- {
- public Task<TimelineResponse> GetHomeTimeline(int count, IQueryCursor? cursor, bool firstLoad);
- }
-}
public Guid UniqueKey { get; }
- public ISocialProtocolQuery Query { get; private set; }
-
- public ISocialProtocolMutation Mutation { get; private set; }
+ public ISocialProtocolClient Client { get; private set; }
public bool IsDisposed { get; private set; }
public TwitterAccount(Guid uniqueKey)
{
this.UniqueKey = uniqueKey;
- this.Query = this.CreateQueryInstance(APIAuthType.None);
- this.Mutation = this.CreateMutationInstance(APIAuthType.None);
+ this.Client = this.CreateClientInstance(APIAuthType.None);
}
public void Initialize(UserAccount accountSettings, SettingCommon settingCommon)
(this.apiConnection, var oldConnection) = (newConnection, this.apiConnection);
oldConnection.Dispose();
- this.Query = this.CreateQueryInstance(credential.AuthType);
- this.Mutation = this.CreateMutationInstance(credential.AuthType);
+ this.Client = this.CreateClientInstance(credential.AuthType);
this.twLegacy.Initialize(newConnection, this.AccountState);
this.twLegacy.RestrictFavCheck = settingCommon.RestrictFavCheck;
this.IsDisposed = true;
}
- private ISocialProtocolQuery CreateQueryInstance(APIAuthType authType)
- {
- return authType switch
- {
- APIAuthType.TwitterComCookie => new TwitterGraphqlQuery(this),
- _ => new TwitterV1Query(this),
- };
- }
-
- private ISocialProtocolMutation CreateMutationInstance(APIAuthType authType)
+ private ISocialProtocolClient CreateClientInstance(APIAuthType authType)
{
return authType switch
{
- APIAuthType.TwitterComCookie => new TwitterGraphqlMutation(this),
- _ => new TwitterV1Mutation(this),
+ APIAuthType.TwitterComCookie => new TwitterGraphqlClient(this),
+ _ => new TwitterV1Client(this),
};
}
}
namespace OpenTween.SocialProtocol.Twitter
{
- public class TwitterGraphqlMutation : ISocialProtocolMutation
+ public class TwitterGraphqlClient : ISocialProtocolClient
{
private readonly TwitterAccount account;
- public TwitterGraphqlMutation(TwitterAccount account)
+ public TwitterGraphqlClient(TwitterAccount account)
{
this.account = account;
}
+ public async Task<TimelineResponse> GetHomeTimeline(int count, IQueryCursor? cursor, bool firstLoad)
+ {
+ this.account.Legacy.CheckAccountState();
+
+ var request = new HomeLatestTimelineRequest
+ {
+ Count = count,
+ Cursor = cursor?.As<TwitterGraphqlCursor>(),
+ };
+
+ var response = await request.Send(this.account.Connection)
+ .ConfigureAwait(false);
+
+ var statuses = response.ToTwitterStatuses();
+ var cursorTop = response.CursorTop;
+ var cursorBottom = response.CursorBottom;
+
+ var posts = this.account.Legacy.CreatePostsFromJson(statuses, firstLoad);
+ posts = this.account.Legacy.FilterNoRetweetUserPosts(posts);
+
+ return new(posts, cursorTop, cursorBottom);
+ }
+
public async Task DeletePost(PostId postId)
{
var statusId = this.AssertTwitterStatusId(postId);
+++ /dev/null
-// OpenTween - Client of Twitter
-// Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
-// (c) 2008-2011 Moz (@syo68k)
-// (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
-// (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
-// (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
-// (c) 2011 Egtra (@egtra) <http://dev.activebasic.com/egtra/>
-// (c) 2013 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
-// All rights reserved.
-//
-// This file is part of OpenTween.
-//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by the Free
-// Software Foundation; either version 3 of the License, or (at your option)
-// any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-// for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
-// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
-// Boston, MA 02110-1301, USA.
-
-#nullable enable
-
-using System.Threading.Tasks;
-using OpenTween.Api.GraphQL;
-using OpenTween.Models;
-
-namespace OpenTween.SocialProtocol.Twitter
-{
- public class TwitterGraphqlQuery : ISocialProtocolQuery
- {
- private readonly TwitterAccount account;
-
- public TwitterGraphqlQuery(TwitterAccount account)
- {
- this.account = account;
- }
-
- public async Task<TimelineResponse> GetHomeTimeline(int count, IQueryCursor? cursor, bool firstLoad)
- {
- this.account.Legacy.CheckAccountState();
-
- var request = new HomeLatestTimelineRequest
- {
- Count = count,
- Cursor = cursor?.As<TwitterGraphqlCursor>(),
- };
-
- var response = await request.Send(this.account.Connection)
- .ConfigureAwait(false);
-
- var statuses = response.ToTwitterStatuses();
- var cursorTop = response.CursorTop;
- var cursorBottom = response.CursorBottom;
-
- var posts = this.account.Legacy.CreatePostsFromJson(statuses, firstLoad);
- posts = this.account.Legacy.FilterNoRetweetUserPosts(posts);
-
- return new(posts, cursorTop, cursorBottom);
- }
- }
-}
namespace OpenTween.SocialProtocol.Twitter
{
- public class TwitterV1Mutation : ISocialProtocolMutation
+ public class TwitterV1Client : ISocialProtocolClient
{
private readonly TwitterAccount account;
- public TwitterV1Mutation(TwitterAccount account)
+ public TwitterV1Client(TwitterAccount account)
{
this.account = account;
}
+ public async Task<TimelineResponse> GetHomeTimeline(int count, IQueryCursor? cursor, bool firstLoad)
+ {
+ this.account.Legacy.CheckAccountState();
+
+ TwitterStatusId? maxId = null, sinceId = null;
+
+ if (cursor is QueryCursor<TwitterStatusId> statusIdCursor)
+ {
+ if (statusIdCursor.Type == CursorType.Top)
+ sinceId = statusIdCursor.Value;
+ else if (statusIdCursor.Type == CursorType.Bottom)
+ maxId = statusIdCursor.Value;
+ }
+
+ var statuses = await this.account.Legacy.Api.StatusesHomeTimeline(count, maxId, sinceId)
+ .ConfigureAwait(false);
+
+ IQueryCursor? cursorTop = null, cursorBottom = null;
+
+ if (statuses.Length > 0)
+ {
+ var (min, max) = statuses.Select(x => new TwitterStatusId(x.IdStr)).MinMax();
+ cursorTop = new QueryCursor<TwitterStatusId>(CursorType.Top, max);
+ cursorBottom = new QueryCursor<TwitterStatusId>(CursorType.Bottom, min);
+ }
+
+ var posts = this.account.Legacy.CreatePostsFromJson(statuses, firstLoad);
+ posts = this.account.Legacy.FilterNoRetweetUserPosts(posts);
+
+ return new(posts, cursorTop, cursorBottom);
+ }
+
public async Task DeletePost(PostId postId)
{
var statusId = this.AssertTwitterStatusId(postId);
+++ /dev/null
-// OpenTween - Client of Twitter
-// Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
-// (c) 2008-2011 Moz (@syo68k)
-// (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
-// (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
-// (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
-// (c) 2011 Egtra (@egtra) <http://dev.activebasic.com/egtra/>
-// (c) 2013 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
-// All rights reserved.
-//
-// This file is part of OpenTween.
-//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by the Free
-// Software Foundation; either version 3 of the License, or (at your option)
-// any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-// for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
-// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
-// Boston, MA 02110-1301, USA.
-
-#nullable enable
-
-using System.Linq;
-using System.Threading.Tasks;
-using OpenTween.Models;
-
-namespace OpenTween.SocialProtocol.Twitter
-{
- public class TwitterV1Query : ISocialProtocolQuery
- {
- private readonly TwitterAccount account;
-
- public TwitterV1Query(TwitterAccount account)
- {
- this.account = account;
- }
-
- public async Task<TimelineResponse> GetHomeTimeline(int count, IQueryCursor? cursor, bool firstLoad)
- {
- this.account.Legacy.CheckAccountState();
-
- TwitterStatusId? maxId = null, sinceId = null;
-
- if (cursor is QueryCursor<TwitterStatusId> statusIdCursor)
- {
- if (statusIdCursor.Type == CursorType.Top)
- sinceId = statusIdCursor.Value;
- else if (statusIdCursor.Type == CursorType.Bottom)
- maxId = statusIdCursor.Value;
- }
-
- var statuses = await this.account.Legacy.Api.StatusesHomeTimeline(count, maxId, sinceId)
- .ConfigureAwait(false);
-
- IQueryCursor? cursorTop = null, cursorBottom = null;
-
- if (statuses.Length > 0)
- {
- var (min, max) = statuses.Select(x => new TwitterStatusId(x.IdStr)).MinMax();
- cursorTop = new QueryCursor<TwitterStatusId>(CursorType.Top, max);
- cursorBottom = new QueryCursor<TwitterStatusId>(CursorType.Bottom, min);
- }
-
- var posts = this.account.Legacy.CreatePostsFromJson(statuses, firstLoad);
- posts = this.account.Legacy.FilterNoRetweetUserPosts(posts);
-
- return new(posts, cursorTop, cursorBottom);
- }
- }
-}
{
var originalPostId = post.RetweetedId ?? post.StatusId;
- await this.CurrentTabAccount.Mutation.FavoritePost(originalPostId)
+ await this.CurrentTabAccount.Client.FavoritePost(originalPostId)
.ConfigureAwait(false);
if (this.settings.Common.RestrictFavCheck)
{
var originalPostId = post.RetweetedId ?? post.StatusId;
- await this.CurrentTabAccount.Mutation.UnfavoritePost(originalPostId)
+ await this.CurrentTabAccount.Client.UnfavoritePost(originalPostId)
.ConfigureAwait(false);
}
catch (WebApiException)
{
var statusId = post.RetweetedId ?? post.StatusId;
- var retweetedPost = await this.CurrentTabAccount.Mutation.RetweetPost(statusId)
+ var retweetedPost = await this.CurrentTabAccount.Client.RetweetPost(statusId)
.ConfigureAwait(false);
if (retweetedPost != null)
{
// 自分が RT したツイート (自分が RT した自分のツイートも含む)
// => RT を取り消し
- await this.CurrentTabAccount.Mutation.UnretweetPost(post.RetweetedId);
+ await this.CurrentTabAccount.Client.UnretweetPost(post.RetweetedId);
}
else
{
{
// 他人に RT された自分のツイート
// => RT 元の自分のツイートを削除
- await this.CurrentTabAccount.Mutation.DeletePost(post.RetweetedId);
+ await this.CurrentTabAccount.Client.DeletePost(post.RetweetedId);
}
else
{
// 自分のツイート
// => ツイートを削除
- await this.CurrentTabAccount.Mutation.DeletePost(post.StatusId);
+ await this.CurrentTabAccount.Client.DeletePost(post.StatusId);
}
}
}