diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ef29d2d0b..71eea24ad 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -2,6 +2,7 @@ ==== Unreleased * CHG: 設定画面でのアカウント一覧の表示形式を変更 + * CHG: 新規タブの初回に読み込まれた発言を既読状態にする(起動時の初回の読み込みと同じ動作となる) ==== Ver 3.13.0(2024/01/27) * NEW: Cookie使用時のReplyタブの更新に対応(/statuses/mentions_timeline.json 廃止に伴う対応) diff --git a/OpenTween/Models/DirectMessagesTabModel.cs b/OpenTween/Models/DirectMessagesTabModel.cs index 31a7b74f0..7b07e2ef0 100644 --- a/OpenTween/Models/DirectMessagesTabModel.cs +++ b/OpenTween/Models/DirectMessagesTabModel.cs @@ -53,21 +53,20 @@ public DirectMessagesTabModel(string tabName) { } - public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override async Task RefreshAsync(Twitter tw, bool backward, IProgress progress) { - bool read; - if (!SettingManager.Instance.Common.UnreadManage) - read = true; - else - read = startup && SettingManager.Instance.Common.Read; - progress.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText8, backward ? -1 : 1)); - await tw.GetDirectMessageEvents(read, this, backward) + var firstLoad = !this.IsFirstLoadCompleted; + + await tw.GetDirectMessageEvents(this, backward, firstLoad) .ConfigureAwait(false); TabInformations.GetInstance().DistributePosts(); + if (firstLoad) + this.IsFirstLoadCompleted = true; + progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText11); } } diff --git a/OpenTween/Models/FavoritesTabModel.cs b/OpenTween/Models/FavoritesTabModel.cs index 4030b2a2a..d8b7e5474 100644 --- a/OpenTween/Models/FavoritesTabModel.cs +++ b/OpenTween/Models/FavoritesTabModel.cs @@ -57,21 +57,20 @@ public FavoritesTabModel(string tabName) { } - public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override async Task RefreshAsync(Twitter tw, bool backward, IProgress progress) { - bool read; - if (!SettingManager.Instance.Common.UnreadManage) - read = true; - else - read = startup && SettingManager.Instance.Common.Read; - progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19); - await tw.GetFavoritesApi(read, this, backward) + var firstLoad = !this.IsFirstLoadCompleted; + + await tw.GetFavoritesApi(this, backward, firstLoad) .ConfigureAwait(false); TabInformations.GetInstance().DistributePosts(); + if (firstLoad) + this.IsFirstLoadCompleted = true; + progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText20); } } diff --git a/OpenTween/Models/FilterTabModel.cs b/OpenTween/Models/FilterTabModel.cs index a6c32b8a0..649cdcccb 100644 --- a/OpenTween/Models/FilterTabModel.cs +++ b/OpenTween/Models/FilterTabModel.cs @@ -171,11 +171,11 @@ public PostFilterRule[] FilterArray } } - public override Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override Task RefreshAsync(Twitter tw, bool backward, IProgress progress) { var homeTab = TabInformations.GetInstance().HomeTab; - return homeTab.RefreshAsync(tw, backward, startup, progress); + return homeTab.RefreshAsync(tw, backward, progress); } } } diff --git a/OpenTween/Models/HomeTabModel.cs b/OpenTween/Models/HomeTabModel.cs index dac76ac4e..7cacae5a3 100644 --- a/OpenTween/Models/HomeTabModel.cs +++ b/OpenTween/Models/HomeTabModel.cs @@ -71,17 +71,13 @@ public override void AddPostQueue(PostClass post) this.UpdateTimelineSpeed(post.CreatedAt); } - public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override async Task RefreshAsync(Twitter tw, bool backward, IProgress progress) { - bool read; - if (!SettingManager.Instance.Common.UnreadManage) - read = true; - else - read = startup && SettingManager.Instance.Common.Read; - progress.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5, backward ? -1 : 1)); - await tw.GetHomeTimelineApi(read, this, backward, startup) + var firstLoad = !this.IsFirstLoadCompleted; + + await tw.GetHomeTimelineApi(this, backward, firstLoad) .ConfigureAwait(false); // 新着時未読クリア @@ -90,6 +86,9 @@ await tw.GetHomeTimelineApi(read, this, backward, startup) TabInformations.GetInstance().DistributePosts(); + if (firstLoad) + this.IsFirstLoadCompleted = true; + progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText1); } diff --git a/OpenTween/Models/ListTimelineTabModel.cs b/OpenTween/Models/ListTimelineTabModel.cs index 04e2a1b7a..101a832ba 100644 --- a/OpenTween/Models/ListTimelineTabModel.cs +++ b/OpenTween/Models/ListTimelineTabModel.cs @@ -55,24 +55,23 @@ public ListTimelineTabModel(string tabName, ListElement list) this.ListInfo = list; } - public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override async Task RefreshAsync(Twitter tw, bool backward, IProgress progress) { if (this.ListInfo == null || this.ListInfo.Id == 0) return; - bool read; - if (!SettingManager.Instance.Common.UnreadManage) - read = true; - else - read = startup && SettingManager.Instance.Common.Read; - progress.Report("List refreshing..."); - await tw.GetListStatus(read, this, backward, startup) + var firstLoad = !this.IsFirstLoadCompleted; + + await tw.GetListStatus(this, backward, firstLoad) .ConfigureAwait(false); TabInformations.GetInstance().DistributePosts(); + if (firstLoad) + this.IsFirstLoadCompleted = true; + progress.Report("List refreshed"); } } diff --git a/OpenTween/Models/LocalSearchTabModel.cs b/OpenTween/Models/LocalSearchTabModel.cs index 4776c1015..762af0581 100644 --- a/OpenTween/Models/LocalSearchTabModel.cs +++ b/OpenTween/Models/LocalSearchTabModel.cs @@ -41,7 +41,7 @@ public LocalSearchTabModel(string tabName) { } - public override Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override Task RefreshAsync(Twitter tw, bool backward, IProgress progress) => Task.CompletedTask; // 何もしない } } diff --git a/OpenTween/Models/MentionsTabModel.cs b/OpenTween/Models/MentionsTabModel.cs index a56675bd9..4ea09f0a9 100644 --- a/OpenTween/Models/MentionsTabModel.cs +++ b/OpenTween/Models/MentionsTabModel.cs @@ -57,21 +57,20 @@ public MentionsTabModel(string tabName) { } - public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override async Task RefreshAsync(Twitter tw, bool backward, IProgress progress) { - bool read; - if (!SettingManager.Instance.Common.UnreadManage) - read = true; - else - read = startup && SettingManager.Instance.Common.Read; - progress.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4, backward ? -1 : 1)); - await tw.GetMentionsTimelineApi(read, this, backward, startup) + var firstLoad = !this.IsFirstLoadCompleted; + + await tw.GetMentionsTimelineApi(this, backward, firstLoad) .ConfigureAwait(false); TabInformations.GetInstance().DistributePosts(); + if (firstLoad) + this.IsFirstLoadCompleted = true; + progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText9); } } diff --git a/OpenTween/Models/MuteTabModel.cs b/OpenTween/Models/MuteTabModel.cs index 9af031b84..7ec1ecc6b 100644 --- a/OpenTween/Models/MuteTabModel.cs +++ b/OpenTween/Models/MuteTabModel.cs @@ -48,7 +48,7 @@ public override void AddPostQueue(PostClass post) { } - public override Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override Task RefreshAsync(Twitter tw, bool backward, IProgress progress) => Task.CompletedTask; // 何もしない } } diff --git a/OpenTween/Models/PublicSearchTabModel.cs b/OpenTween/Models/PublicSearchTabModel.cs index 51fab0dc1..ca54d2ad3 100644 --- a/OpenTween/Models/PublicSearchTabModel.cs +++ b/OpenTween/Models/PublicSearchTabModel.cs @@ -77,24 +77,23 @@ public PublicSearchTabModel(string tabName) { } - public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override async Task RefreshAsync(Twitter tw, bool backward, IProgress progress) { if (MyCommon.IsNullOrEmpty(this.SearchWords)) return; - bool read; - if (!SettingManager.Instance.Common.UnreadManage) - read = true; - else - read = startup && SettingManager.Instance.Common.Read; - progress.Report("Search refreshing..."); - await tw.GetSearch(read, this, backward) + var firstLoad = !this.IsFirstLoadCompleted; + + await tw.GetSearch(this, backward, firstLoad) .ConfigureAwait(false); TabInformations.GetInstance().DistributePosts(); + if (firstLoad) + this.IsFirstLoadCompleted = true; + progress.Report("Search refreshed"); } @@ -107,6 +106,7 @@ public void ResetFetchIds() this.OldestId = null; this.CursorTop = null; this.CursorBottom = null; + this.IsFirstLoadCompleted = false; } } } diff --git a/OpenTween/Models/RelatedPostsTabModel.cs b/OpenTween/Models/RelatedPostsTabModel.cs index 9f46cd5bd..4fb7fd157 100644 --- a/OpenTween/Models/RelatedPostsTabModel.cs +++ b/OpenTween/Models/RelatedPostsTabModel.cs @@ -51,24 +51,23 @@ public RelatedPostsTabModel(string tabName, PostClass targetPost) this.TargetPost = targetPost; } - public Task RefreshAsync(Twitter tw, bool startup, IProgress progress) - => this.RefreshAsync(tw, false, startup, progress); + public Task RefreshAsync(Twitter tw, IProgress progress) + => this.RefreshAsync(tw, false, progress); - public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override async Task RefreshAsync(Twitter tw, bool backward, IProgress progress) { - bool read; - if (!SettingManager.Instance.Common.UnreadManage) - read = true; - else - read = startup && SettingManager.Instance.Common.Read; - try { progress.Report("Related refreshing..."); - await tw.GetRelatedResult(read, this) + var firstLoad = !this.IsFirstLoadCompleted; + + await tw.GetRelatedResult(this, firstLoad) .ConfigureAwait(false); + if (firstLoad) + this.IsFirstLoadCompleted = true; + progress.Report("Related refreshed"); } finally diff --git a/OpenTween/Models/TabModel.cs b/OpenTween/Models/TabModel.cs index e5dc4e1d8..46a0d7f56 100644 --- a/OpenTween/Models/TabModel.cs +++ b/OpenTween/Models/TabModel.cs @@ -55,6 +55,8 @@ public abstract class TabModel public SortOrder SortOrder { get; private set; } + public bool IsFirstLoadCompleted { get; protected set; } = false; + public abstract MyCommon.TabUsageType TabType { get; } public virtual ConcurrentDictionary Posts @@ -128,7 +130,7 @@ public int UpdateCount protected TabModel(string tabName) => this.TabName = tabName; - public abstract Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress); + public abstract Task RefreshAsync(Twitter tw, bool backward, IProgress progress); private readonly record struct TemporaryId( PostId StatusId, diff --git a/OpenTween/Models/UserTimelineTabModel.cs b/OpenTween/Models/UserTimelineTabModel.cs index ab82511bd..647ae7d60 100644 --- a/OpenTween/Models/UserTimelineTabModel.cs +++ b/OpenTween/Models/UserTimelineTabModel.cs @@ -57,24 +57,23 @@ public UserTimelineTabModel(string tabName, string screenName) this.ScreenName = screenName; } - public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + public override async Task RefreshAsync(Twitter tw, bool backward, IProgress progress) { if (MyCommon.IsNullOrEmpty(this.ScreenName)) return; - bool read; - if (!SettingManager.Instance.Common.UnreadManage) - read = true; - else - read = startup && SettingManager.Instance.Common.Read; - progress.Report("UserTimeline refreshing..."); - await tw.GetUserTimelineApi(read, this, backward) + var firstLoad = !this.IsFirstLoadCompleted; + + await tw.GetUserTimelineApi(this, backward, firstLoad) .ConfigureAwait(false); TabInformations.GetInstance().DistributePosts(); + if (firstLoad) + this.IsFirstLoadCompleted = true; + progress.Report("UserTimeline refreshed"); } } diff --git a/OpenTween/Tween.cs b/OpenTween/Tween.cs index e0e5a14f8..27ddd026b 100644 --- a/OpenTween/Tween.cs +++ b/OpenTween/Tween.cs @@ -1302,7 +1302,7 @@ private async Task RefreshTabAsync(TabModel tab, bool backward) try { this.RefreshTasktrayIcon(); - await Task.Run(() => tab.RefreshAsync(this.tw, backward, this.initial, this.workerProgress)); + await Task.Run(() => tab.RefreshAsync(this.tw, backward, this.workerProgress)); tab.IncrementUpdateCount(); } catch (WebApiException ex) @@ -1730,12 +1730,6 @@ private async Task RetweetAsyncInternal(IProgress p, CancellationToken c if (!CheckAccountValid()) throw new WebApiException("Auth error. Check your account"); - bool read; - if (!this.settings.Common.UnreadManage) - read = true; - else - read = this.initial && this.settings.Common.Read; - p.Report("Posting..."); var posts = new List(); @@ -1744,7 +1738,7 @@ await Task.Run(async () => { foreach (var statusId in statusIds) { - var post = await this.tw.PostRetweet(statusId, read).ConfigureAwait(false); + var post = await this.tw.PostRetweet(statusId).ConfigureAwait(false); if (post != null) posts.Add(post); } }); @@ -5217,7 +5211,7 @@ private async Task GoInReplyToPostTree() { try { - var post = await this.tw.GetStatusApi(false, currentPost.StatusId.ToTwitterStatusId()); + var post = await this.tw.GetStatusApi(currentPost.StatusId.ToTwitterStatusId()); currentPost = currentPost with { @@ -5265,9 +5259,8 @@ from post in tab.Posts.Values { await Task.Run(async () => { - var post = await this.tw.GetStatusApi(false, currentPost.InReplyToStatusId.ToTwitterStatusId()) + var post = await this.tw.GetStatusApi(currentPost.InReplyToStatusId.ToTwitterStatusId()) .ConfigureAwait(false); - post.IsRead = true; this.statuses.AddPost(post); this.statuses.DistributePosts(); @@ -9182,7 +9175,7 @@ public async Task OpenRelatedTab(PostId statusId) { try { - post = await this.tw.GetStatusApi(false, statusId.ToTwitterStatusId()); + post = await this.tw.GetStatusApi(statusId.ToTwitterStatusId()); } catch (WebApiException ex) { diff --git a/OpenTween/TweetDetailsView.cs b/OpenTween/TweetDetailsView.cs index d0d90970e..b1a46798f 100644 --- a/OpenTween/TweetDetailsView.cs +++ b/OpenTween/TweetDetailsView.cs @@ -363,7 +363,7 @@ private async Task CreateQuoteTweetHtml(PostId statusId, bool isReply) { try { - post = await this.Owner.TwitterInstance.GetStatusApi(false, statusId.ToTwitterStatusId()) + post = await this.Owner.TwitterInstance.GetStatusApi(statusId.ToTwitterStatusId()) .ConfigureAwait(false); } catch (WebApiException ex) @@ -371,7 +371,6 @@ private async Task CreateQuoteTweetHtml(PostId statusId, bool isReply) return FormatQuoteTweetHtml(statusId, WebUtility.HtmlEncode($"Err:{ex.Message}(GetStatus)"), isReply); } - post.IsRead = true; if (!TabInformations.GetInstance().AddQuoteTweet(post)) return FormatQuoteTweetHtml(statusId, "This Tweet is unavailable.", isReply); } diff --git a/OpenTween/Twitter.cs b/OpenTween/Twitter.cs index aaa8b7c04..7dc1b1479 100644 --- a/OpenTween/Twitter.cs +++ b/OpenTween/Twitter.cs @@ -284,7 +284,8 @@ await this.SendDirectMessage(param.Text, mediaId) // 投稿したものを返す var post = this.CreatePostsFromStatusData(status); - if (this.ReadOwnPost) post.IsRead = true; + this.SetInitialUnreadState(post, firstLoad: false); + return post; } @@ -381,11 +382,11 @@ public async Task SendDirectMessage(string postStr, long? mediaId = null) var messageEventSingle = await response.LoadJsonAsync() .ConfigureAwait(false); - await this.CreateDirectMessagesEventFromJson(messageEventSingle, read: true) + await this.CreateDirectMessagesEventFromJson(messageEventSingle, firstLoad: false) .ConfigureAwait(false); } - public async Task PostRetweet(PostId id, bool read) + public async Task PostRetweet(PostId id) { this.CheckAccountState(); @@ -425,12 +426,10 @@ await this.CreateDirectMessagesEventFromJson(messageEventSingle, read: true) throw new WebApiException("Invalid Json!"); // Retweetしたものを返す - return this.CreatePostsFromStatusData(status) with - { - IsMe = true, - IsRead = this.ReadOwnPost ? true : read, - IsOwl = false, - }; + var retweetPost = this.CreatePostsFromStatusData(status); + this.SetInitialUnreadState(retweetPost, firstLoad: false); + + return retweetPost; } public async Task DeleteRetweet(PostClass post) @@ -595,7 +594,7 @@ public static int GetMaxApiResultCount(MyCommon.WORKERTYPE type) /// /// WORKERTYPEに応じた取得件数を取得する /// - public static int GetApiResultCount(MyCommon.WORKERTYPE type, bool more, bool startup) + public static int GetApiResultCount(MyCommon.WORKERTYPE type, bool more, bool firstLoad) { if (SettingManager.Instance.Common.UseAdditionalCount) { @@ -622,7 +621,7 @@ public static int GetApiResultCount(MyCommon.WORKERTYPE type, bool more, bool st { return Math.Min(SettingManager.Instance.Common.MoreCountApi, GetMaxApiResultCount(type)); } - if (startup && SettingManager.Instance.Common.FirstCountApi != 0 && type != MyCommon.WORKERTYPE.Reply) + if (firstLoad && SettingManager.Instance.Common.FirstCountApi != 0 && type != MyCommon.WORKERTYPE.Reply) { return Math.Min(SettingManager.Instance.Common.FirstCountApi, GetMaxApiResultCount(type)); } @@ -637,11 +636,11 @@ public static int GetApiResultCount(MyCommon.WORKERTYPE type, bool more, bool st return Math.Min(count, GetMaxApiResultCount(type)); } - public async Task GetHomeTimelineApi(bool read, HomeTabModel tab, bool more, bool startup) + public async Task GetHomeTimelineApi(HomeTabModel tab, bool more, bool firstLoad) { this.CheckAccountState(); - var count = GetApiResultCount(MyCommon.WORKERTYPE.Timeline, more, startup); + var count = GetApiResultCount(MyCommon.WORKERTYPE.Timeline, more, firstLoad); TwitterStatus[] statuses; if (this.Api.AuthType == APIAuthType.TwitterComCookie) @@ -688,16 +687,16 @@ public async Task GetHomeTimelineApi(bool read, HomeTabModel tab, bool more, boo .ConfigureAwait(false); } - var minimumId = this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.Timeline, tab, read); + var minimumId = this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.Timeline, tab, firstLoad); if (minimumId != null) tab.OldestId = minimumId; } - public async Task GetMentionsTimelineApi(bool read, MentionsTabModel tab, bool more, bool startup) + public async Task GetMentionsTimelineApi(MentionsTabModel tab, bool more, bool firstLoad) { this.CheckAccountState(); - var count = GetApiResultCount(MyCommon.WORKERTYPE.Reply, more, startup); + var count = GetApiResultCount(MyCommon.WORKERTYPE.Reply, more, firstLoad); TwitterStatus[] statuses; if (this.Api.AuthType == APIAuthType.TwitterComCookie) @@ -731,16 +730,16 @@ public async Task GetMentionsTimelineApi(bool read, MentionsTabModel tab, bool m } } - var minimumId = this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.Reply, tab, read); + var minimumId = this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.Reply, tab, firstLoad); if (minimumId != null) tab.OldestId = minimumId; } - public async Task GetUserTimelineApi(bool read, UserTimelineTabModel tab, bool more) + public async Task GetUserTimelineApi(UserTimelineTabModel tab, bool more, bool firstLoad) { this.CheckAccountState(); - var count = GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, more, false); + var count = GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, more, firstLoad); TwitterStatus[] statuses; if (this.Api.AuthType == APIAuthType.TwitterComCookie) @@ -786,13 +785,13 @@ public async Task GetUserTimelineApi(bool read, UserTimelineTabModel tab, bool m } } - var minimumId = this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.UserTimeline, tab, read); + var minimumId = this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.UserTimeline, tab, firstLoad); if (minimumId != null) tab.OldestId = minimumId; } - public async Task GetStatusApi(bool read, TwitterStatusId id) + public async Task GetStatusApi(TwitterStatusId id, bool firstLoad = false) { this.CheckAccountState(); @@ -815,25 +814,11 @@ public async Task GetStatusApi(bool read, TwitterStatusId id) } var item = this.CreatePostsFromStatusData(status); - - item.IsRead = read; - if (item.IsMe && !read && this.ReadOwnPost) item.IsRead = true; + this.SetInitialUnreadState(item, firstLoad); return item; } - public async Task GetStatusApi(bool read, TwitterStatusId id, TabModel tab) - { - var post = await this.GetStatusApi(read, id) - .ConfigureAwait(false); - - // 非同期アイコン取得&StatusDictionaryに追加 - if (tab != null && tab.IsInnerStorageTabType) - tab.AddPostQueue(post); - else - TabInformations.GetInstance().AddPost(post); - } - private PostClass CreatePostsFromStatusData(TwitterStatus status) => this.CreatePostsFromStatusData(status, favTweet: false); @@ -845,7 +830,7 @@ private PostClass CreatePostsFromStatusData(TwitterStatus status, bool favTweet) return post; } - private PostId? CreatePostsFromJson(TwitterStatus[] items, MyCommon.WORKERTYPE gType, TabModel? tab, bool read) + private PostId? CreatePostsFromJson(TwitterStatus[] items, MyCommon.WORKERTYPE gType, TabModel? tab, bool firstLoad) { PostId? minimumId = null; @@ -879,8 +864,7 @@ private PostClass CreatePostsFromStatusData(TwitterStatus status, bool favTweet) if (gType != MyCommon.WORKERTYPE.UserTimeline && post.RetweetedByUserId != null && this.noRTId.Contains(post.RetweetedByUserId.Value)) continue; - post.IsRead = read; - if (post.IsMe && !read && this.ReadOwnPost) post.IsRead = true; + this.SetInitialUnreadState(post, firstLoad); if (tab != null && tab.IsInnerStorageTabType) tab.AddPostQueue(post); @@ -891,7 +875,7 @@ private PostClass CreatePostsFromStatusData(TwitterStatus status, bool favTweet) return minimumId; } - private PostId? CreatePostsFromSearchJson(TwitterStatus[] statuses, PublicSearchTabModel tab, bool read, bool more) + private PostId? CreatePostsFromSearchJson(TwitterStatus[] statuses, PublicSearchTabModel tab, bool more, bool firstLoad) { PostId? minimumId = null; @@ -917,8 +901,7 @@ private PostClass CreatePostsFromStatusData(TwitterStatus status, bool favTweet) continue; } - post.IsRead = read; - if ((post.IsMe && !read) && this.ReadOwnPost) post.IsRead = true; + this.SetInitialUnreadState(post, firstLoad); tab.AddPostQueue(post); } @@ -926,7 +909,7 @@ private PostClass CreatePostsFromStatusData(TwitterStatus status, bool favTweet) return minimumId; } - private long? CreateFavoritePostsFromJson(TwitterStatus[] items, bool read) + private long? CreateFavoritePostsFromJson(TwitterStatus[] items, bool firstLoad) { var favTab = TabInformations.GetInstance().FavoriteTab; long? minimumId = null; @@ -945,7 +928,7 @@ private PostClass CreatePostsFromStatusData(TwitterStatus status, bool favTweet) var post = this.CreatePostsFromStatusData(status, true); - post.IsRead = read; + this.SetInitialUnreadState(post, firstLoad); TabInformations.GetInstance().AddPost(post); } @@ -953,9 +936,22 @@ private PostClass CreatePostsFromStatusData(TwitterStatus status, bool favTweet) return minimumId; } - public async Task GetListStatus(bool read, ListTimelineTabModel tab, bool more, bool startup) + private void SetInitialUnreadState(PostClass post, bool firstLoad) + { + bool isRead; + if (post.IsMe && this.ReadOwnPost) + isRead = true; + else if (firstLoad && SettingManager.Instance.Common.Read) + isRead = true; + else + isRead = false; + + post.IsRead = isRead; + } + + public async Task GetListStatus(ListTimelineTabModel tab, bool more, bool firstLoad) { - var count = GetApiResultCount(MyCommon.WORKERTYPE.List, more, startup); + var count = GetApiResultCount(MyCommon.WORKERTYPE.List, more, firstLoad); TwitterStatus[] statuses; if (this.Api.AuthType == APIAuthType.TwitterComCookie) @@ -990,7 +986,7 @@ public async Task GetListStatus(bool read, ListTimelineTabModel tab, bool more, .ConfigureAwait(false); } - var minimumId = this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.List, tab, read); + var minimumId = this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.List, tab, firstLoad); if (minimumId != null) tab.OldestId = minimumId; @@ -1016,7 +1012,7 @@ internal static PostClass FindTopOfReplyChain(IDictionary pos return nextPost; } - public async Task GetRelatedResult(bool read, RelatedPostsTabModel tab) + public async Task GetRelatedResult(RelatedPostsTabModel tab, bool firstLoad) { var targetPost = tab.TargetPost; @@ -1042,7 +1038,7 @@ public async Task GetRelatedResult(bool read, RelatedPostsTabModel tab) } else { - p = await this.GetStatusApi(read, targetPost.StatusId.ToTwitterStatusId()) + p = await this.GetStatusApi(targetPost.StatusId.ToTwitterStatusId(), firstLoad) .ConfigureAwait(false); targetPost = p; } @@ -1063,7 +1059,7 @@ public async Task GetRelatedResult(bool read, RelatedPostsTabModel tab) { try { - inReplyToPost = await this.GetStatusApi(read, inReplyToId.ToTwitterStatusId()) + inReplyToPost = await this.GetStatusApi(inReplyToId.ToTwitterStatusId(), firstLoad) .ConfigureAwait(false); } catch (WebApiException ex) @@ -1092,7 +1088,7 @@ public async Task GetRelatedResult(bool read, RelatedPostsTabModel tab) { try { - p = await this.GetStatusApi(read, statusId) + p = await this.GetStatusApi(statusId, firstLoad) .ConfigureAwait(false); } catch (WebApiException ex) @@ -1133,10 +1129,6 @@ public async Task GetRelatedResult(bool read, RelatedPostsTabModel tab) relPosts.Values.ToList().ForEach(p => { var post = p with { }; - if (post.IsMe && !read && this.ReadOwnPost) - post.IsRead = true; - else - post.IsRead = read; tab.AddPostQueue(post); }); @@ -1175,9 +1167,9 @@ private async Task GetConversationPosts(PostClass firstPost, PostCl return statuses.Select(x => this.CreatePostsFromStatusData(x)).ToArray(); } - public async Task GetSearch(bool read, PublicSearchTabModel tab, bool more) + public async Task GetSearch(PublicSearchTabModel tab, bool more, bool firstLoad) { - var count = GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, more, false); + var count = GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, more, firstLoad); TwitterStatus[] statuses; if (this.Api.AuthType == APIAuthType.TwitterComCookie) @@ -1224,13 +1216,13 @@ public async Task GetSearch(bool read, PublicSearchTabModel tab, bool more) if (!TabInformations.GetInstance().ContainsTab(tab)) return; - var minimumId = this.CreatePostsFromSearchJson(statuses, tab, read, more); + var minimumId = this.CreatePostsFromSearchJson(statuses, tab, more, firstLoad); if (minimumId != null) tab.OldestId = minimumId; } - public async Task GetDirectMessageEvents(bool read, DirectMessagesTabModel dmTab, bool backward) + public async Task GetDirectMessageEvents(DirectMessagesTabModel dmTab, bool backward, bool firstLoad) { this.CheckAccountState(); this.CheckAccessLevel(TwitterApiAccessLevel.ReadWriteAndDirectMessage); @@ -1251,11 +1243,11 @@ public async Task GetDirectMessageEvents(bool read, DirectMessagesTabModel dmTab dmTab.NextCursor = eventList.NextCursor; - await this.CreateDirectMessagesEventFromJson(eventList, read) + await this.CreateDirectMessagesEventFromJson(eventList, firstLoad) .ConfigureAwait(false); } - private async Task CreateDirectMessagesEventFromJson(TwitterMessageEventSingle eventSingle, bool read) + private async Task CreateDirectMessagesEventFromJson(TwitterMessageEventSingle eventSingle, bool firstLoad) { var eventList = new TwitterMessageEventList { @@ -1263,11 +1255,11 @@ private async Task CreateDirectMessagesEventFromJson(TwitterMessageEventSingle e Events = new[] { eventSingle.Event }, }; - await this.CreateDirectMessagesEventFromJson(eventList, read) + await this.CreateDirectMessagesEventFromJson(eventList, firstLoad) .ConfigureAwait(false); } - private async Task CreateDirectMessagesEventFromJson(TwitterMessageEventList eventList, bool read) + private async Task CreateDirectMessagesEventFromJson(TwitterMessageEventList eventList, bool firstLoad) { var events = eventList.Events .Where(x => x.Type == "message_create") @@ -1286,35 +1278,33 @@ private async Task CreateDirectMessagesEventFromJson(TwitterMessageEventList eve var apps = eventList.Apps ?? new Dictionary(); - this.CreateDirectMessagesEventFromJson(events, users, apps, read); + this.CreateDirectMessagesEventFromJson(events, users, apps, firstLoad); } private void CreateDirectMessagesEventFromJson( IEnumerable events, IReadOnlyDictionary users, IReadOnlyDictionary apps, - bool read) + bool firstLoad) { var dmTab = TabInformations.GetInstance().DirectMessageTab; foreach (var eventItem in events) { var post = this.postFactory.CreateFromDirectMessageEvent(eventItem, users, apps, this.UserId); - _ = this.urlExpander.Expand(post); + this.SetInitialUnreadState(post, firstLoad); - post.IsRead = read; - if (post.IsMe && !read && this.ReadOwnPost) - post.IsRead = true; + _ = this.urlExpander.Expand(post); dmTab.AddPostQueue(post); } } - public async Task GetFavoritesApi(bool read, FavoritesTabModel tab, bool backward) + public async Task GetFavoritesApi(FavoritesTabModel tab, bool backward, bool firstLoad) { this.CheckAccountState(); - var count = GetApiResultCount(MyCommon.WORKERTYPE.Favorites, backward, false); + var count = GetApiResultCount(MyCommon.WORKERTYPE.Favorites, backward, firstLoad); TwitterStatus[] statuses; if (this.Api.AuthType == APIAuthType.TwitterComCookie) @@ -1349,7 +1339,7 @@ public async Task GetFavoritesApi(bool read, FavoritesTabModel tab, bool backwar } } - var minimumId = this.CreateFavoritePostsFromJson(statuses, read); + var minimumId = this.CreateFavoritePostsFromJson(statuses, firstLoad); if (minimumId != null) tab.OldestId = minimumId.Value;