-
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.
Merge pull request #318 from opentween/home-specified-account
メインアカウント以外のホームタイムラインを表示する機能を追加
- Loading branch information
Showing
8 changed files
with
327 additions
and
10 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,52 @@ | ||
// 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. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using OpenTween.Connection; | ||
using Xunit; | ||
|
||
namespace OpenTween.SocialProtocol | ||
{ | ||
public class InvalidAccountTest | ||
{ | ||
[Fact] | ||
public async Task Connection_Test() | ||
{ | ||
using var account = new InvalidAccount(Guid.NewGuid()); | ||
var requeset = new GetRequest { RequestUri = new("https://example.com/aaa") }; | ||
|
||
await Assert.ThrowsAsync<WebApiException>( | ||
() => account.Connection.SendAsync(requeset) | ||
); | ||
} | ||
|
||
[Fact] | ||
public async Task Client_Test() | ||
{ | ||
using var account = new InvalidAccount(Guid.NewGuid()); | ||
|
||
await Assert.ThrowsAsync<WebApiException>( | ||
() => account.Client.VerifyCredentials() | ||
); | ||
} | ||
} | ||
} |
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,74 @@ | ||
// 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; | ||
using System.Threading.Tasks; | ||
using OpenTween.SocialProtocol; | ||
|
||
namespace OpenTween.Models | ||
{ | ||
public class HomeSpecifiedAccountTabModel : InternalStorageTabModel | ||
{ | ||
public override MyCommon.TabUsageType TabType | ||
=> MyCommon.TabUsageType.Undefined; | ||
|
||
public override bool IsPermanentTabType | ||
=> false; | ||
|
||
public override Guid? SourceAccountId { get; } | ||
|
||
public HomeSpecifiedAccountTabModel(string tabName, Guid accountId) | ||
: base(tabName) | ||
{ | ||
this.SourceAccountId = accountId; | ||
} | ||
|
||
public override async Task RefreshAsync(ISocialAccount account, bool backward, IProgress<string> progress) | ||
{ | ||
progress.Report("Home refreshing..."); | ||
|
||
var firstLoad = !this.IsFirstLoadCompleted; | ||
var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, backward, firstLoad); | ||
var cursor = backward ? this.CursorBottom : this.CursorTop; | ||
|
||
var response = await account.Client.GetHomeTimeline(count, cursor, firstLoad) | ||
.ConfigureAwait(false); | ||
|
||
foreach (var post in response.Posts) | ||
this.AddPostQueue(post); | ||
|
||
TabInformations.GetInstance().DistributePosts(); | ||
|
||
if (response.CursorTop != null && !backward) | ||
this.CursorTop = response.CursorTop; | ||
|
||
if (response.CursorBottom != null) | ||
this.CursorBottom = response.CursorBottom; | ||
|
||
if (firstLoad) | ||
this.IsFirstLoadCompleted = true; | ||
|
||
progress.Report("Home refreshed"); | ||
} | ||
} | ||
} |
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,106 @@ | ||
// 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; | ||
using System.Threading.Tasks; | ||
using OpenTween.Connection; | ||
using OpenTween.Models; | ||
|
||
namespace OpenTween.SocialProtocol | ||
{ | ||
public class InvalidAccount : ISocialAccount | ||
{ | ||
public string AccountType | ||
=> "InvalidAccount"; | ||
|
||
public Guid UniqueKey { get; } | ||
|
||
public PersonId UserId | ||
=> new TwitterUserId("0"); | ||
|
||
public string UserName | ||
=> "(Unknown account)"; | ||
|
||
public IApiConnection Connection { get; } = new InvalidAccountConnection(); | ||
|
||
public ISocialProtocolClient Client { get; } = new InvalidAccountClient(); | ||
|
||
public bool IsDisposed { get; private set; } | ||
|
||
public InvalidAccount(Guid uniqueKey) | ||
=> this.UniqueKey = uniqueKey; | ||
|
||
public void Initialize(UserAccount accountSettings, SettingCommon settingCommon) | ||
{ | ||
} | ||
|
||
public void Dispose() | ||
=> this.IsDisposed = true; | ||
|
||
private class InvalidAccountConnection : IApiConnection | ||
{ | ||
public Task<ApiResponse> SendAsync(IHttpRequest request) | ||
=> throw new WebApiException("Invalid account"); | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
|
||
private class InvalidAccountClient : ISocialProtocolClient | ||
{ | ||
public Task<UserInfo> VerifyCredentials() | ||
=> throw this.CreateException(); | ||
|
||
public Task<PostClass> GetPostById(PostId postId, bool firstLoad) | ||
=> throw this.CreateException(); | ||
|
||
public Task<TimelineResponse> GetHomeTimeline(int count, IQueryCursor? cursor, bool firstLoad) | ||
=> throw this.CreateException(); | ||
|
||
public Task<TimelineResponse> GetSearchTimeline(string query, string lang, int count, IQueryCursor? cursor, bool firstLoad) | ||
=> throw this.CreateException(); | ||
|
||
public Task<PostClass[]> GetRelatedPosts(PostClass targetPost, bool firstLoad) | ||
=> throw this.CreateException(); | ||
|
||
public Task DeletePost(PostId postId) | ||
=> throw this.CreateException(); | ||
|
||
public Task FavoritePost(PostId postId) | ||
=> throw this.CreateException(); | ||
|
||
public Task UnfavoritePost(PostId postId) | ||
=> throw this.CreateException(); | ||
|
||
public Task<PostClass?> RetweetPost(PostId postId) | ||
=> throw this.CreateException(); | ||
|
||
public Task UnretweetPost(PostId postId) | ||
=> throw this.CreateException(); | ||
|
||
private WebApiException CreateException() | ||
=> new("Invalid account"); | ||
} | ||
} | ||
} |
Oops, something went wrong.