-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Twitter.GetHomeTimelineApiメソッドをISocialProtocolQueryの各実装クラスに移動
- Loading branch information
Showing
7 changed files
with
190 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// 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.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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// 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.Linq; | ||
using System.Threading.Tasks; | ||
using OpenTween.Api.GraphQL; | ||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters