Skip to content

Commit

Permalink
Merge pull request #343 from opentween/refresh-configuration
Browse files Browse the repository at this point in the history
ISocialProtocolClient.RefreshConfigurationメソッドを追加
  • Loading branch information
upsilon authored May 21, 2024
2 parents 9339345 + a4b10a0 commit 9c81949
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 267 deletions.
58 changes: 55 additions & 3 deletions OpenTween.Tests/Models/TabInformationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ public void ClearTabIds_NotAffectToOtherTabs_Test()
[Fact]
public void RefreshOwl_HomeTabTest()
{
var accountId = Guid.NewGuid();
var post = new PostClass
{
StatusId = new TwitterStatusId("100"),
Expand All @@ -1211,14 +1212,15 @@ public void RefreshOwl_HomeTabTest()
this.tabinfo.SubmitUpdate();

var followerIds = new HashSet<PersonId> { new TwitterUserId("123") };
this.tabinfo.RefreshOwl(followerIds);
this.tabinfo.RefreshOwl(accountId, followerIds, isPrimary: true);

Assert.False(post.IsOwl);
}

[Fact]
public void RefreshOwl_InnerStoregeTabTest()
{
var accountId = Guid.NewGuid();
var tab = new PublicSearchTabModel("search");
this.tabinfo.AddTab(tab);

Expand All @@ -1234,14 +1236,15 @@ public void RefreshOwl_InnerStoregeTabTest()
this.tabinfo.SubmitUpdate();

var followerIds = new HashSet<PersonId> { new TwitterUserId("123") };
this.tabinfo.RefreshOwl(followerIds);
this.tabinfo.RefreshOwl(accountId, followerIds, isPrimary: true);

Assert.False(post.IsOwl);
}

[Fact]
public void RefreshOwl_UnfollowedTest()
{
var accountId = Guid.NewGuid();
var post = new PostClass
{
StatusId = new TwitterStatusId("100"),
Expand All @@ -1254,7 +1257,56 @@ public void RefreshOwl_UnfollowedTest()
this.tabinfo.SubmitUpdate();

var followerIds = new HashSet<PersonId> { new TwitterUserId("456") };
this.tabinfo.RefreshOwl(followerIds);
this.tabinfo.RefreshOwl(accountId, followerIds, isPrimary: true);

Assert.True(post.IsOwl);
}

[Fact]
public void RefreshOwl_SecondaryAccountTabTest()
{
var accountId = Guid.NewGuid();
var tab = new HomeSpecifiedAccountTabModel("secondary", accountId);
this.tabinfo.AddTab(tab);

var post = new PostClass
{
StatusId = new TwitterStatusId("100"),
ScreenName = "aaa",
UserId = new TwitterUserId("234"),
IsOwl = true,
};
tab.AddPostQueue(post);
this.tabinfo.DistributePosts();
this.tabinfo.SubmitUpdate();

var followerIds = new HashSet<PersonId> { new TwitterUserId("123") };
this.tabinfo.RefreshOwl(accountId, followerIds, isPrimary: false);

Assert.True(post.IsOwl);
}

[Fact]
public void RefreshOwl_SecondaryAccountTab_AccountNotMatchedTest()
{
var accountId = Guid.NewGuid();
var tab = new HomeSpecifiedAccountTabModel("secondary", accountId);
this.tabinfo.AddTab(tab);

var post = new PostClass
{
StatusId = new TwitterStatusId("100"),
ScreenName = "aaa",
UserId = new TwitterUserId("234"),
IsOwl = true,
};
tab.AddPostQueue(post);
this.tabinfo.DistributePosts();
this.tabinfo.SubmitUpdate();

var otherAccountId = Guid.NewGuid(); // 他アカウントの followerIds なので IsOwl は更新されない
var followerIds = new HashSet<PersonId> { new TwitterUserId("123") };
this.tabinfo.RefreshOwl(otherAccountId, followerIds, isPrimary: false);

Assert.True(post.IsOwl);
}
Expand Down
37 changes: 16 additions & 21 deletions OpenTween/Models/TabInformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -866,34 +866,29 @@ public void ClearTabIds(string tabName)
}
}

public void RefreshOwl(ISet<PersonId> follower)
public void RefreshOwl(Guid accountId, ISet<PersonId> follower, bool isPrimary)
{
lock (this.lockObj)
{
var allPosts = this.GetTabsByType<InternalStorageTabModel>()
.SelectMany(x => x.Posts.Values)
.Concat(this.Posts.Values);
static bool DetermineOwl(PostClass post, ISet<PersonId> followers)
=> !post.IsMe && followers.Count > 0 && !followers.Contains(post.UserId);

if (follower.Count > 0)
static bool SourceAccountIdMatched(TabModel tab, Guid accountId, bool isPrimary)
=> tab.SourceAccountId == accountId || (isPrimary && tab.SourceAccountId == null);

if (isPrimary)
{
foreach (var post in allPosts)
{
if (post.IsMe)
{
post.IsOwl = false;
}
else
{
post.IsOwl = !follower.Contains(post.UserId);
}
}
foreach (var post in this.Posts.Values)
post.IsOwl = DetermineOwl(post, follower);
}
else

foreach (var tab in this.GetTabsByType<InternalStorageTabModel>())
{
foreach (var post in allPosts)
{
post.IsOwl = false;
}
if (!SourceAccountIdMatched(tab, accountId, isPrimary))
continue;

foreach (var post in tab.Posts.Values)
post.IsOwl = DetermineOwl(post, follower);
}
}
}
Expand Down
108 changes: 27 additions & 81 deletions OpenTween/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions OpenTween/Properties/Resources.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ Available service: {1}</value></data>
<data name="PostWorker_RunWorkerCompletedText5"><value>Recent refreshing...</value></data>
<data name="QuoteStatus_AccessibleText"><value>[Quote @{0}: {1}]</value></data>
<data name="ReAuthorizeText"><value>Please do Authentication processing to get/send Direct Messages again.</value></data>
<data name="RefreshConfiguration_Error"><value>Failed to get configuration: </value></data>
<data name="RefreshConfiguration_Start"><value>Getting configuration...</value></data>
<data name="RefreshConfiguration_Success"><value>Done to get configuration</value></data>
<data name="RefreshStripMenuItem_ClickText1"><value>Recent refreshing...</value></data>
<data name="RefreshStripMenuItem_ClickText2"><value>Reply refreshing...</value></data>
<data name="RefreshStripMenuItem_ClickText3"><value>DMRcv refreshing...</value></data>
Expand Down Expand Up @@ -331,15 +334,6 @@ Do you retry to update status?</value></data>
<data name="UnhandledExceptionText7"><value>{0}.exe Version: {1}</value></data>
<data name="UnhandledExceptionText8"><value>Exception {0}: {1}</value></data>
<data name="UnhandledExceptionText9"><value>We are sorry but error was happened. A log text was created as {0} in same folder of %AppName%. Please send this to {1} or{3}tweet to {2} in Twitter.{3}[OK] to open log file. [Cancel] to continue.</value></data>
<data name="UpdateBlockUserText1"><value>Getting BlockIds...</value></data>
<data name="UpdateBlockUserText2"><value>Failed to get BlockIds: </value></data>
<data name="UpdateBlockUserText3"><value>Done to get BlockIds</value></data>
<data name="UpdateFollowersMenuItem1_ClickText1"><value>Followers refreshing...</value></data>
<data name="UpdateFollowersMenuItem1_ClickText2"><value>Followers refresh error: </value></data>
<data name="UpdateFollowersMenuItem1_ClickText3"><value>Followers refreshed</value></data>
<data name="UpdateMuteUserIds_Error"><value>Failed to get MuteUserIds: {0}</value></data>
<data name="UpdateMuteUserIds_Finish"><value>Done to get MuteUserIds</value></data>
<data name="UpdateMuteUserIds_Start"><value>Getting MuteUserIds...</value></data>
<data name="UrlConvert_BitlyAuthRequired"><value>To use Bitly, you must perform the Bitly authentication in settings dialog.</value></data>
<data name="UserInfoButtonEdit_ClickText1"><value>Accept</value></data>
<data name="UserInfoButtonEdit_ClickText2"><value>Updating Profile...</value></data>
Expand Down
12 changes: 3 additions & 9 deletions OpenTween/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@
<data name="Refresh2" type="System.Resources.ResXFileRef, System.Windows.Forms"><value>..\Resources\re2.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value></data>
<data name="Refresh3" type="System.Resources.ResXFileRef, System.Windows.Forms"><value>..\Resources\re3.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value></data>
<data name="Refresh4" type="System.Resources.ResXFileRef, System.Windows.Forms"><value>..\Resources\re4.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value></data>
<data name="RefreshConfiguration_Error"><value>Configuration取得エラー :</value></data>
<data name="RefreshConfiguration_Start"><value>Configuration取得中...</value></data>
<data name="RefreshConfiguration_Success"><value>Configuration取得完了</value></data>
<data name="RefreshStripMenuItem_ClickText1"><value>Recent更新中...</value></data>
<data name="RefreshStripMenuItem_ClickText2"><value>Reply更新中...</value></data>
<data name="RefreshStripMenuItem_ClickText3"><value>DMRcv更新中...</value></data>
Expand Down Expand Up @@ -365,15 +368,6 @@
<data name="UnhandledExceptionText7"><value> {0}.exeのバージョン: {1}</value></data>
<data name="UnhandledExceptionText8"><value>例外 {0}: {1}</value></data>
<data name="UnhandledExceptionText9"><value>エラーが発生しました。ごめんなさい。ログをexeファイルのある場所に {0} として作ったので、{1}まで送っていただけると助かります。{3}ご面倒なら{2}までお知らせ頂くだけでも助かります。{3}「はい」ボタンをクリックするとログを開きます。ログを開かない場合は「いいえ」、このまま終了する場合は「キャンセル」ボタンをクリックしてください。</value></data>
<data name="UpdateBlockUserText1"><value>BlockIds取得中...</value></data>
<data name="UpdateBlockUserText2"><value>BlockIds取得エラー :</value></data>
<data name="UpdateBlockUserText3"><value>BlockIds取得完了</value></data>
<data name="UpdateFollowersMenuItem1_ClickText1"><value>Followers取得中...</value></data>
<data name="UpdateFollowersMenuItem1_ClickText2"><value>Followers取得エラー:</value></data>
<data name="UpdateFollowersMenuItem1_ClickText3"><value>Followers取得完了</value></data>
<data name="UpdateMuteUserIds_Error"><value>MuteUserIds取得エラー: {0}</value></data>
<data name="UpdateMuteUserIds_Finish"><value>MuteUserIds取得完了</value></data>
<data name="UpdateMuteUserIds_Start"><value>MuteUserIds取得中...</value></data>
<data name="UrlConvert_BitlyAuthRequired"><value>Bitlyを使用するには設定画面で認証情報を入力する必要があります</value></data>
<data name="UserInfoButtonEdit_ClickText1"><value>適用</value></data>
<data name="UserInfoButtonEdit_ClickText2"><value>プロフィール更新中・・・</value></data>
Expand Down
2 changes: 2 additions & 0 deletions OpenTween/SocialProtocol/ISocialProtocolClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ public interface ISocialProtocolClient
public Task<PostClass?> RetweetPost(PostId postId);

public Task UnretweetPost(PostId postId);

public Task RefreshConfiguration();
}
}
3 changes: 3 additions & 0 deletions OpenTween/SocialProtocol/InvalidAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public Task UnfavoritePost(PostId postId)
public Task UnretweetPost(PostId postId)
=> throw this.CreateException();

public Task RefreshConfiguration()
=> throw this.CreateException();

private WebApiException CreateException()
=> new("Invalid account");
}
Expand Down
4 changes: 4 additions & 0 deletions OpenTween/SocialProtocol/Twitter/TwitterAccountState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class TwitterAccountState

public ISet<TwitterUserId> NoRetweetUserIds { get; set; } = new HashSet<TwitterUserId>();

public TwitterConfiguration Configuration { get; } = TwitterConfiguration.DefaultConfiguration();

public TwitterTextConfiguration TextConfiguration { get; } = TwitterTextConfiguration.DefaultConfiguration();

public bool HasUnrecoverableError { get; set; } = true;

public TwitterAccountState()
Expand Down
11 changes: 11 additions & 0 deletions OpenTween/SocialProtocol/Twitter/TwitterGraphqlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ await request.Send(this.account.Connection)
.ConfigureAwait(false);
}

public async Task RefreshConfiguration()
{
await Task.WhenAll(new[]
{
this.account.Legacy.RefreshFollowerIds(),
this.account.Legacy.RefreshBlockIds(),
this.account.Legacy.RefreshMuteUserIdsAsync(),
this.account.Legacy.RefreshNoRetweetIds(),
});
}

private TwitterStatusId AssertTwitterStatusId(PostId postId)
{
return postId is TwitterStatusId statusId
Expand Down
11 changes: 11 additions & 0 deletions OpenTween/SocialProtocol/Twitter/TwitterV1Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ await this.account.Legacy.Api.StatusesUnretweet(statusId)
.ConfigureAwait(false);
}

public async Task RefreshConfiguration()
{
await Task.WhenAll(new[]
{
this.account.Legacy.RefreshFollowerIds(),
this.account.Legacy.RefreshBlockIds(),
this.account.Legacy.RefreshMuteUserIdsAsync(),
this.account.Legacy.RefreshNoRetweetIds(),
});
}

private TwitterStatusId AssertTwitterStatusId(PostId postId)
{
return postId is TwitterStatusId statusId
Expand Down
Loading

0 comments on commit 9c81949

Please sign in to comment.