Skip to content

Commit

Permalink
Merge pull request #316 from opentween/drop-inner-storage-type-getter
Browse files Browse the repository at this point in the history
TabModel.IsInnerStorageTabTypeプロパティを削除
  • Loading branch information
upsilon authored Feb 6, 2024
2 parents e1d598c + 3c5ee4c commit 70b55cc
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 58 deletions.
9 changes: 0 additions & 9 deletions OpenTween.Tests/Models/TabInformationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,15 +1379,6 @@ public void GetTabsByType_Enum_Test()
Assert.Equal(new[] { tab1, tab2 }, this.tabinfo.GetTabsByType(MyCommon.TabUsageType.PublicSearch));
}

[Fact]
public void GetTabsInnerStorageType_Test()
{
Assert.Equal(
new TabModel[] { this.tabinfo.DirectMessageTab },
this.tabinfo.GetTabsInnerStorageType()
);
}

[Fact]
public void GetTabByName_Test()
{
Expand Down
13 changes: 0 additions & 13 deletions OpenTween.Tests/Models/TabModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,18 +1029,5 @@ public void IsDefault_Test(MyCommon.TabUsageType tabType, bool expected)
[InlineData(MyCommon.TabUsageType.Related, false)]
public void IsDistributable_Test(MyCommon.TabUsageType tabType, bool expected)
=> Assert.Equal(expected, tabType.IsDistributable());

[Theory]
[InlineData(MyCommon.TabUsageType.Home, false)]
[InlineData(MyCommon.TabUsageType.Mentions, false)]
[InlineData(MyCommon.TabUsageType.DirectMessage, true)]
[InlineData(MyCommon.TabUsageType.Favorites, false)]
[InlineData(MyCommon.TabUsageType.UserDefined, false)]
[InlineData(MyCommon.TabUsageType.Lists, true)]
[InlineData(MyCommon.TabUsageType.UserTimeline, true)]
[InlineData(MyCommon.TabUsageType.PublicSearch, true)]
[InlineData(MyCommon.TabUsageType.Related, true)]
public void IsInnerStorage_Test(MyCommon.TabUsageType tabType, bool expected)
=> Assert.Equal(expected, tabType.IsInnerStorage());
}
}
3 changes: 0 additions & 3 deletions OpenTween/Models/FilterTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public FilterTabModel(string tabName)
// フィルタに合致したら追加
public MyCommon.HITRESULT AddFiltered(PostClass post, bool immediately = false)
{
if (this.IsInnerStorageTabType)
return MyCommon.HITRESULT.None;

var rslt = MyCommon.HITRESULT.None;

// 全フィルタ評価(優先順位あり)
Expand Down
18 changes: 4 additions & 14 deletions OpenTween/Models/TabInformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void RemoveTab(string tabName)
var tb = this.GetTabByName(tabName);
if (tb == null || tb.IsDefaultTabType) return; // 念のため

if (!tb.IsInnerStorageTabType)
if (tb is not InternalStorageTabModel)
{
var homeTab = this.HomeTab;
var dmTab = this.DirectMessageTab;
Expand Down Expand Up @@ -725,7 +725,7 @@ public PostClass? this[PostId id]
if (this.quotes.TryGetValue(id, out status))
return status;

return this.GetTabsInnerStorageType()
return this.GetTabsByType<InternalStorageTabModel>()
.Select(x => x.Posts.TryGetValue(id, out status) ? status : null)
.FirstOrDefault(x => x != null);
}
Expand Down Expand Up @@ -856,7 +856,7 @@ public void ClearTabIds(string tabName)
lock (this.lockObj)
{
var tb = this.Tabs[tabName];
if (!tb.IsInnerStorageTabType)
if (tb is not InternalStorageTabModel)
{
foreach (var id in tb.StatusIds)
{
Expand Down Expand Up @@ -889,7 +889,7 @@ public void RefreshOwl(ISet<long> follower)
{
lock (this.lockObj)
{
var allPosts = this.GetTabsInnerStorageType()
var allPosts = this.GetTabsByType<InternalStorageTabModel>()
.SelectMany(x => x.Posts.Values)
.Concat(this.Posts.Values);

Expand Down Expand Up @@ -964,16 +964,6 @@ public T[] GetTabsByType<T>()
return this.Tabs.OfType<T>().ToArray();
}

public TabModel[] GetTabsInnerStorageType()
{
lock (this.lockObj)
{
return this.Tabs
.Where(x => x.IsInnerStorageTabType)
.ToArray();
}
}

public TabModel? GetTabByName(string tabName)
{
lock (this.lockObj)
Expand Down
2 changes: 0 additions & 2 deletions OpenTween/Models/TabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public virtual ConcurrentDictionary<PostId, PostClass> Posts

public bool IsDistributableTabType => this.TabType.IsDistributable();

public bool IsInnerStorageTabType => this.TabType.IsInnerStorage();

/// <summary>
/// 次回起動時にも保持されるタブか(SettingTabsに保存されるか)
/// </summary>
Expand Down
14 changes: 0 additions & 14 deletions OpenTween/Models/TabUsageTypeExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ public static class TabUsageTypeExt
MyCommon.TabUsageType.UserDefined |
MyCommon.TabUsageType.Mute;

private const MyCommon.TabUsageType InnerStorageTabTypeMask =
MyCommon.TabUsageType.DirectMessage |
MyCommon.TabUsageType.PublicSearch |
MyCommon.TabUsageType.Lists |
MyCommon.TabUsageType.UserTimeline |
MyCommon.TabUsageType.Related |
MyCommon.TabUsageType.SearchResults;

/// <summary>
/// デフォルトタブかどうかを示す値を取得します。
/// </summary>
Expand All @@ -65,11 +57,5 @@ public static bool IsDefault(this MyCommon.TabUsageType tabType)
/// </summary>
public static bool IsDistributable(this MyCommon.TabUsageType tabType)
=> (tabType & DistributableTabTypeMask) != 0;

/// <summary>
/// 内部ストレージを使用するタブかどうかを示す値を取得します。
/// </summary>
public static bool IsInnerStorage(this MyCommon.TabUsageType tabType)
=> (tabType & InnerStorageTabTypeMask) != 0;
}
}
4 changes: 2 additions & 2 deletions OpenTween/Tween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ await this.tw.PostFavAdd(twitterStatusId)
}

// 検索,リスト,UserTimeline,Relatedの各タブに反映
foreach (var tb in this.statuses.GetTabsInnerStorageType())
foreach (var tb in this.statuses.GetTabsByType<InternalStorageTabModel>())
{
if (tb.Contains(statusId))
tb.Posts[statusId].IsFav = true;
Expand Down Expand Up @@ -1509,7 +1509,7 @@ await Task.Run(async () =>
tabinfoPost.IsFav = false;

// 検索,リスト,UserTimeline,Relatedの各タブに反映
foreach (var tb in this.statuses.GetTabsInnerStorageType())
foreach (var tb in this.statuses.GetTabsByType<InternalStorageTabModel>())
{
if (tb.Contains(statusId))
tb.Posts[statusId].IsFav = false;
Expand Down
2 changes: 1 addition & 1 deletion OpenTween/Twitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ private PostClass CreatePostsFromStatusData(TwitterStatus status, bool favTweet)

this.SetInitialUnreadState(post, firstLoad);

if (tab != null && tab.IsInnerStorageTabType)
if (tab != null && tab is InternalStorageTabModel)
tab.AddPostQueue(post);
else
TabInformations.GetInstance().AddPost(post);
Expand Down

0 comments on commit 70b55cc

Please sign in to comment.