Assert.Single(filteredPosts);
Assert.Equal(new TwitterStatusId("100"), filteredPosts[0].StatusId);
}
+
+ [Fact]
+ public void Run_FilterByBlockedUser_FilteredTest()
+ {
+ var accountState = new TwitterAccountState
+ {
+ BlockedUserIds = new HashSet<PersonId>
+ {
+ new TwitterUserId("111"),
+ },
+ };
+ var posts = new[]
+ {
+ new PostClass
+ {
+ StatusId = new TwitterStatusId("100"),
+ UserId = new TwitterUserId("111"),
+ },
+ };
+
+ var filter = new TimelineResponseFilter(accountState)
+ {
+ IsHomeTimeline = true,
+ };
+ var filteredPosts = filter.Run(posts);
+
+ Assert.Empty(filteredPosts);
+ }
+
+ [Fact]
+ public void Run_FilterByBlockedUser_NotFilteredTest()
+ {
+ var accountState = new TwitterAccountState
+ {
+ BlockedUserIds = new HashSet<PersonId>
+ {
+ new TwitterUserId("111"),
+ },
+ };
+ var posts = new[]
+ {
+ new PostClass
+ {
+ StatusId = new TwitterStatusId("100"),
+ UserId = new TwitterUserId("222"), // ブロックされたユーザーではない
+ },
+ };
+
+ var filter = new TimelineResponseFilter(accountState)
+ {
+ IsHomeTimeline = true,
+ };
+ var filteredPosts = filter.Run(posts);
+
+ Assert.Single(filteredPosts);
+ Assert.Equal(new TwitterStatusId("100"), filteredPosts[0].StatusId);
+ }
+
+ [Fact]
+ public void Run_FilterByBlockedUser_NotHomeTimelineTest()
+ {
+ var accountState = new TwitterAccountState
+ {
+ BlockedUserIds = new HashSet<PersonId>
+ {
+ new TwitterUserId("111"),
+ },
+ };
+ var posts = new[]
+ {
+ new PostClass
+ {
+ StatusId = new TwitterStatusId("100"),
+ UserId = new TwitterUserId("111"),
+ },
+ };
+
+ var filter = new TimelineResponseFilter(accountState)
+ {
+ IsHomeTimeline = false, // ホームタイムライン以外では BlockedUserIds によるフィルタを行わない
+ };
+ var filteredPosts = filter.Run(posts);
+
+ Assert.Single(filteredPosts);
+ Assert.Equal(new TwitterStatusId("100"), filteredPosts[0].StatusId);
+ }
}
}
public Stack<TabModel> RemovedTab { get; } = new();
- public ISet<PersonId> BlockIds { get; set; } = new HashSet<PersonId>();
-
public ISet<PersonId> MuteUserIds { get; set; } = new HashSet<PersonId>();
// 発言の追加
return;
}
- if (this.BlockIds.Contains(item.UserId))
- return;
-
this.Posts.TryAdd(item.StatusId, item);
}
if (item.IsFav && this.retweetsCount.ContainsKey(item.StatusId))
{
lock (this.lockObj)
{
- if (this.IsMuted(item, isHomeTimeline: false) || this.BlockIds.Contains(item.UserId))
+ if (this.IsMuted(item, isHomeTimeline: false))
return false;
this.quotes[item.StatusId] = item;
{
private readonly TwitterAccountState accountState;
+ public bool IsHomeTimeline { get; set; }
+
public TimelineResponseFilter(TwitterAccountState accountState)
{
this.accountState = accountState;
filteredPosts = this.FilterNoRetweetUserPosts(filteredPosts);
+ if (this.IsHomeTimeline)
+ filteredPosts = this.FilterBlockedUserPosts(filteredPosts);
+
return filteredPosts.ToArray();
}
private IEnumerable<PostClass> FilterNoRetweetUserPosts(IEnumerable<PostClass> posts)
=> posts.Where(x => x.RetweetedByUserId == null || !this.accountState.NoRetweetUserIds.Contains(x.RetweetedByUserId));
+
+ private IEnumerable<PostClass> FilterBlockedUserPosts(IEnumerable<PostClass> posts)
+ => posts.Where(x => !this.accountState.BlockedUserIds.Contains(x.UserId));
}
}
public ISet<PersonId> FollowerIds { get; set; } = new HashSet<PersonId>();
+ public ISet<PersonId> BlockedUserIds { get; set; } = new HashSet<PersonId>();
+
public ISet<TwitterUserId> NoRetweetUserIds { get; set; } = new HashSet<TwitterUserId>();
public bool HasUnrecoverableError { get; set; } = true;
var posts = this.account.Legacy.CreatePostsFromJson(statuses, firstLoad);
- var filter = new TimelineResponseFilter(this.account.AccountState);
+ var filter = new TimelineResponseFilter(this.account.AccountState)
+ {
+ IsHomeTimeline = true,
+ };
posts = filter.Run(posts);
return new(posts, cursorTop, cursorBottom);
var (cursorTop, cursorBottom) = GetCursorFromResponse(statuses);
var posts = this.account.Legacy.CreatePostsFromJson(statuses, firstLoad);
- var filter = new TimelineResponseFilter(this.account.AccountState);
+ var filter = new TimelineResponseFilter(this.account.AccountState)
+ {
+ IsHomeTimeline = true,
+ };
posts = filter.Run(posts);
return new(posts, cursorTop, cursorBottom);
using System.Windows.Forms;
using OpenTween.Models;
using OpenTween.Setting;
+using OpenTween.SocialProtocol.Twitter;
namespace OpenTween
{
return FormatQuoteTweetHtml(statusId, WebUtility.HtmlEncode($"Err:{ex.Message}(GetStatus)"), isReply);
}
+ if (this.Owner.CurrentTabAccount is TwitterAccount twAccount)
+ {
+ if (twAccount.AccountState.BlockedUserIds.Contains(post.UserId))
+ return FormatQuoteTweetHtml(statusId, "This Tweet is unavailable.", isReply);
+ }
+
if (!TabInformations.GetInstance().AddQuoteTweet(post))
return FormatQuoteTweetHtml(statusId, "This Tweet is unavailable.", isReply);
}
var blockIdsSet = newBlockIds.ToHashSet();
blockIdsSet.Remove(this.UserId); // 元のソースにあったので一応残しておく
- TabInformations.GetInstance().BlockIds = blockIdsSet;
+ this.AccountState.BlockedUserIds = blockIdsSet;
}
/// <summary>