Skip to content

Commit

Permalink
Account{Id,Key} で表記揺れしていた識別子をAccountKeyに統一
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Jun 10, 2024
1 parent 3026ebc commit 1f8101c
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 52 deletions.
26 changes: 13 additions & 13 deletions OpenTween.Tests/Models/TabInformationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ public void ClearTabIds_NotAffectToOtherTabs_Test()
[Fact]
public void RefreshOwl_HomeTabTest()
{
var accountId = AccountKey.New();
var accountKey = AccountKey.New();
var post = new PostClass
{
StatusId = new TwitterStatusId("100"),
Expand All @@ -1213,15 +1213,15 @@ public void RefreshOwl_HomeTabTest()
this.tabinfo.SubmitUpdate();

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

Assert.False(post.IsOwl);
}

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

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

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

Assert.False(post.IsOwl);
}

[Fact]
public void RefreshOwl_UnfollowedTest()
{
var accountId = AccountKey.New();
var accountKey = AccountKey.New();
var post = new PostClass
{
StatusId = new TwitterStatusId("100"),
Expand All @@ -1258,16 +1258,16 @@ public void RefreshOwl_UnfollowedTest()
this.tabinfo.SubmitUpdate();

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

Assert.True(post.IsOwl);
}

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

var post = new PostClass
Expand All @@ -1282,16 +1282,16 @@ public void RefreshOwl_SecondaryAccountTabTest()
this.tabinfo.SubmitUpdate();

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

Assert.True(post.IsOwl);
}

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

var post = new PostClass
Expand All @@ -1305,9 +1305,9 @@ public void RefreshOwl_SecondaryAccountTab_AccountNotMatchedTest()
this.tabinfo.DistributePosts();
this.tabinfo.SubmitUpdate();

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

Assert.True(post.IsOwl);
}
Expand Down
18 changes: 9 additions & 9 deletions OpenTween.Tests/SocialProtocol/AccountCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ public void GetAccountForTab_DefaultTest()
SelectedAccountKey = new("00000000-0000-4000-8000-000000000000"),
});

var tabWithoutAccountId = new PublicSearchTabModel("hoge");
var tabWithoutAccountKey = new PublicSearchTabModel("hoge");

// SourceAccountId が null のタブに対しては Primary のアカウントを返す
var actual = accounts.GetAccountForTab(tabWithoutAccountId);
// SourceAccountKey が null のタブに対しては Primary のアカウントを返す
var actual = accounts.GetAccountForTab(tabWithoutAccountKey);
Assert.IsType<TwitterAccount>(actual);
Assert.Equal(new("00000000-0000-4000-8000-000000000000"), actual.UniqueKey);
}
Expand All @@ -215,10 +215,10 @@ public void GetAccountForTab_SpecifiedAccountTest()
SelectedAccountKey = new("00000000-0000-4000-8000-000000000000"),
});

var tabWithAccountId = new RelatedPostsTabModel("hoge", new("00000000-0000-4000-8000-111111111111"), new());
var tabWithAccountKey = new RelatedPostsTabModel("hoge", new("00000000-0000-4000-8000-111111111111"), new());

// SourceAccountId が設定されているタブに対しては対応するアカウントを返す
var actual = accounts.GetAccountForTab(tabWithAccountId);
// SourceAccountKey が設定されているタブに対しては対応するアカウントを返す
var actual = accounts.GetAccountForTab(tabWithAccountKey);
Assert.IsType<TwitterAccount>(actual);
Assert.Equal(new("00000000-0000-4000-8000-111111111111"), actual.UniqueKey);
}
Expand All @@ -236,10 +236,10 @@ public void GetAccountForTab_NotExistsTest()
SelectedAccountKey = new("00000000-0000-4000-8000-000000000000"),
});

var tabWithAccountId = new RelatedPostsTabModel("hoge", new("00000000-0000-4000-8000-999999999999"), new());
var tabWithAccountKey = new RelatedPostsTabModel("hoge", new("00000000-0000-4000-8000-999999999999"), new());

// SourceAccountId に存在しない ID が設定されていた場合は InvalidAccount を返す
var actual = accounts.GetAccountForTab(tabWithAccountId);
// 存在しない AccountKey が設定されていた場合は InvalidAccount を返す
var actual = accounts.GetAccountForTab(tabWithAccountKey);
Assert.IsType<InvalidAccount>(actual);
Assert.Equal(new("00000000-0000-4000-8000-999999999999"), actual.UniqueKey);
}
Expand Down
6 changes: 3 additions & 3 deletions OpenTween/Models/HomeSpecifiedAccountTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public override MyCommon.TabUsageType TabType
public override bool IsPermanentTabType
=> false;

public override AccountKey? SourceAccountId { get; }
public override AccountKey? SourceAccountKey { get; }

public HomeSpecifiedAccountTabModel(string tabName, AccountKey accountId)
public HomeSpecifiedAccountTabModel(string tabName, AccountKey accountKey)
: base(tabName)
{
this.SourceAccountId = accountId;
this.SourceAccountKey = accountKey;
}

public override async Task RefreshAsync(ISocialAccount account, bool backward, IProgress<string> progress)
Expand Down
6 changes: 3 additions & 3 deletions OpenTween/Models/RelatedPostsTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public override MyCommon.TabUsageType TabType

public override bool IsPermanentTabType => false;

public override AccountKey? SourceAccountId { get; }
public override AccountKey? SourceAccountKey { get; }

public PostClass TargetPost { get; }

public RelatedPostsTabModel(string tabName, AccountKey accountId, PostClass targetPost)
public RelatedPostsTabModel(string tabName, AccountKey accountKey, PostClass targetPost)
: base(tabName)
{
this.SourceAccountId = accountId;
this.SourceAccountKey = accountKey;
this.TargetPost = targetPost;
}

Expand Down
8 changes: 4 additions & 4 deletions OpenTween/Models/TabInformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -867,15 +867,15 @@ public void ClearTabIds(string tabName)
}
}

public void RefreshOwl(AccountKey accountId, ISet<PersonId> follower, bool isPrimary)
public void RefreshOwl(AccountKey accountKey, ISet<PersonId> follower, bool isPrimary)
{
lock (this.lockObj)
{
static bool DetermineOwl(PostClass post, ISet<PersonId> followers)
=> !post.IsMe && followers.Count > 0 && !followers.Contains(post.UserId);

static bool SourceAccountIdMatched(TabModel tab, AccountKey accountId, bool isPrimary)
=> tab.SourceAccountId == accountId || (isPrimary && tab.SourceAccountId == null);
static bool SourceAccountKeyMatched(TabModel tab, AccountKey accountKey, bool isPrimary)
=> tab.SourceAccountKey == accountKey || (isPrimary && tab.SourceAccountKey == null);

if (isPrimary)
{
Expand All @@ -885,7 +885,7 @@ static bool SourceAccountIdMatched(TabModel tab, AccountKey accountId, bool isPr

foreach (var tab in this.GetTabsByType<InternalStorageTabModel>())
{
if (!SourceAccountIdMatched(tab, accountId, isPrimary))
if (!SourceAccountKeyMatched(tab, accountKey, isPrimary))
continue;

foreach (var post in tab.Posts.Values)
Expand Down
2 changes: 1 addition & 1 deletion OpenTween/Models/TabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class TabModel

public abstract MyCommon.TabUsageType TabType { get; }

public virtual AccountKey? SourceAccountId
public virtual AccountKey? SourceAccountKey
=> null;

public virtual ConcurrentDictionary<PostId, PostClass> Posts
Expand Down
14 changes: 7 additions & 7 deletions OpenTween/SocialProtocol/AccountCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ namespace OpenTween.SocialProtocol
public sealed class AccountCollection : IDisposable
{
private Dictionary<AccountKey, ISocialAccount> accounts = new();
private AccountKey? primaryId;
private AccountKey? primaryAccountKey;
private readonly ISocialAccount emptyAccount = new TwitterAccount(AccountKey.Empty);

public bool IsDisposed { get; private set; }

public ISocialAccount Primary
=> this.primaryId != null ? this.accounts[this.primaryId.Value] : this.emptyAccount;
=> this.primaryAccountKey != null ? this.accounts[this.primaryAccountKey.Value] : this.emptyAccount;

public ISocialAccount[] Items
=> this.accounts.Values.ToArray();

public ISocialAccount[] SecondaryAccounts
=> this.accounts.Values.Where(x => x.UniqueKey != this.primaryId).ToArray();
=> this.accounts.Values.Where(x => x.UniqueKey != this.primaryAccountKey).ToArray();

public void LoadFromSettings(SettingCommon settingCommon)
{
Expand All @@ -68,7 +68,7 @@ public void LoadFromSettings(SettingCommon settingCommon)
}

this.accounts = newAccounts;
this.primaryId = settingCommon.SelectedAccountKey is { } guid ? new(guid) : null;
this.primaryAccountKey = settingCommon.SelectedAccountKey is { } guid ? new(guid) : null;

var removedAccounts = oldAccounts
.Where(x => !newAccounts.ContainsKey(x.Key))
Expand Down Expand Up @@ -96,13 +96,13 @@ private void DisposeAccounts(IEnumerable<ISocialAccount> accounts)

public ISocialAccount GetAccountForTab(TabModel tab)
{
if (tab.SourceAccountId is { } accountId)
if (tab.SourceAccountKey is { } accountKey)
{
if (this.accounts.TryGetValue(accountId, out var account))
if (this.accounts.TryGetValue(accountKey, out var account))
return account;

// タブ追加後に設定画面からアカウントの情報を削除した場合
return new InvalidAccount(accountId);
return new InvalidAccount(accountKey);
}

return this.Primary;
Expand Down
6 changes: 3 additions & 3 deletions OpenTween/SocialProtocol/AccountFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public AccountFactory()

public ISocialAccount Create(UserAccount accountSettings, SettingCommon settingCommon)
{
var accountId = new AccountKey(accountSettings.UniqueKey);
var accountKey = new AccountKey(accountSettings.UniqueKey);

var account = this.factories.TryGetValue(accountSettings.AccountType, out var createAccount)
? createAccount(accountId)
: new InvalidAccount(accountId);
? createAccount(accountKey)
: new InvalidAccount(accountKey);

account.Initialize(accountSettings, settingCommon);

Expand Down
4 changes: 2 additions & 2 deletions OpenTween/SocialProtocol/InvalidAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public string UserName

public bool IsDisposed { get; private set; }

public InvalidAccount(AccountKey uniqueKey)
=> this.UniqueKey = uniqueKey;
public InvalidAccount(AccountKey accountKey)
=> this.UniqueKey = accountKey;

public void Initialize(UserAccount accountSettings, SettingCommon settingCommon)
{
Expand Down
4 changes: 2 additions & 2 deletions OpenTween/SocialProtocol/Twitter/TwitterAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public APIAuthType AuthType
public IApiConnection Connection
=> this.apiConnection;

public TwitterAccount(AccountKey uniqueKey)
public TwitterAccount(AccountKey accountKey)
{
this.UniqueKey = uniqueKey;
this.UniqueKey = accountKey;
this.Client = this.CreateClientInstance(APIAuthType.None);
}

Expand Down
10 changes: 5 additions & 5 deletions OpenTween/Tween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ await Task.Run(async () =>
else
{
var secondaryAccountTab = this.statuses.GetTabsByType<HomeSpecifiedAccountTabModel>()
.FirstOrDefault(x => x.SourceAccountId == account.UniqueKey) ?? null;
.FirstOrDefault(x => x.SourceAccountKey == account.UniqueKey) ?? null;

secondaryAccountTab?.AddPostQueue(post);
}
Expand Down Expand Up @@ -2390,7 +2390,7 @@ private DialogResult ShowSettingDialog()
private async void SettingStripMenuItem_Click(object sender, EventArgs e)
{
// 設定画面表示前のユーザー情報
var previousAccountId = this.settings.Common.SelectedAccountKey is { } guid ? new AccountKey(guid) : (AccountKey?)null;
var previousAccountKey = this.settings.Common.SelectedAccountKey is { } guid ? new AccountKey(guid) : (AccountKey?)null;
var previousSecondaryAccounts = this.accounts.SecondaryAccounts;
var oldIconCol = this.Use2ColumnsMode;

Expand Down Expand Up @@ -2583,7 +2583,7 @@ private async void SettingStripMenuItem_Click(object sender, EventArgs e)
this.TopMost = this.settings.Common.AlwaysTop;
this.SaveConfigsAll(false);

if (this.PrimaryAccount.UniqueKey != previousAccountId)
if (this.PrimaryAccount.UniqueKey != previousAccountKey)
{
this.SubscribePrimaryAccountRatelimit();
await this.RefreshConfigurationAsync();
Expand All @@ -2602,7 +2602,7 @@ private void AddSecondaryAccountTabs(IEnumerable<ISocialAccount> accounts)
{
var isPrimary = account.UniqueKey == this.accounts.Primary.UniqueKey;
var tabExists = this.statuses.GetTabsByType<HomeSpecifiedAccountTabModel>()
.Any(x => x.SourceAccountId == account.UniqueKey);
.Any(x => x.SourceAccountKey == account.UniqueKey);
if (tabExists)
continue;

Expand All @@ -2620,7 +2620,7 @@ private void RemoveMissingAccountTabs()

foreach (var tab in secondaryAccountTabs)
{
var isAccountExists = secondaryAccounts.Any(x => x.UniqueKey == tab.SourceAccountId);
var isAccountExists = secondaryAccounts.Any(x => x.UniqueKey == tab.SourceAccountKey);
if (!isAccountExists)
this.RemoveSpecifiedTab(tab.TabName, confirm: false);
}
Expand Down

0 comments on commit 1f8101c

Please sign in to comment.