Skip to content

Commit

Permalink
起動時の初回読込と新規タブの初回読込で既読状態にする条件を揃える
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Feb 2, 2024
1 parent a53a80b commit 0dd7ff5
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 145 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

==== Unreleased
* CHG: 設定画面でのアカウント一覧の表示形式を変更
* CHG: 新規タブの初回に読み込まれた発言を既読状態にする(起動時の初回の読み込みと同じ動作となる)

==== Ver 3.13.0(2024/01/27)
* NEW: Cookie使用時のReplyタブの更新に対応(/statuses/mentions_timeline.json 廃止に伴う対応)
Expand Down
15 changes: 7 additions & 8 deletions OpenTween/Models/DirectMessagesTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,20 @@ public DirectMessagesTabModel(string tabName)
{
}

public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress<string> progress)
public override async Task RefreshAsync(Twitter tw, bool backward, IProgress<string> 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);
}
}
Expand Down
15 changes: 7 additions & 8 deletions OpenTween/Models/FavoritesTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,20 @@ public FavoritesTabModel(string tabName)
{
}

public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress<string> progress)
public override async Task RefreshAsync(Twitter tw, bool backward, IProgress<string> 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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions OpenTween/Models/FilterTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ public PostFilterRule[] FilterArray
}
}

public override Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress<string> progress)
public override Task RefreshAsync(Twitter tw, bool backward, IProgress<string> progress)
{
var homeTab = TabInformations.GetInstance().HomeTab;

return homeTab.RefreshAsync(tw, backward, startup, progress);
return homeTab.RefreshAsync(tw, backward, progress);
}
}
}
15 changes: 7 additions & 8 deletions OpenTween/Models/HomeTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> progress)
public override async Task RefreshAsync(Twitter tw, bool backward, IProgress<string> 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);

// 新着時未読クリア
Expand All @@ -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);
}

Expand Down
15 changes: 7 additions & 8 deletions OpenTween/Models/ListTimelineTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> progress)
public override async Task RefreshAsync(Twitter tw, bool backward, IProgress<string> 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");
}
}
Expand Down
2 changes: 1 addition & 1 deletion OpenTween/Models/LocalSearchTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public LocalSearchTabModel(string tabName)
{
}

public override Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress<string> progress)
public override Task RefreshAsync(Twitter tw, bool backward, IProgress<string> progress)
=> Task.CompletedTask; // 何もしない
}
}
15 changes: 7 additions & 8 deletions OpenTween/Models/MentionsTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,20 @@ public MentionsTabModel(string tabName)
{
}

public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress<string> progress)
public override async Task RefreshAsync(Twitter tw, bool backward, IProgress<string> 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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion OpenTween/Models/MuteTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void AddPostQueue(PostClass post)
{
}

public override Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress<string> progress)
public override Task RefreshAsync(Twitter tw, bool backward, IProgress<string> progress)
=> Task.CompletedTask; // 何もしない
}
}
16 changes: 8 additions & 8 deletions OpenTween/Models/PublicSearchTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,23 @@ public PublicSearchTabModel(string tabName)
{
}

public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress<string> progress)
public override async Task RefreshAsync(Twitter tw, bool backward, IProgress<string> 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");
}

Expand All @@ -107,6 +106,7 @@ public void ResetFetchIds()
this.OldestId = null;
this.CursorTop = null;
this.CursorBottom = null;
this.IsFirstLoadCompleted = false;
}
}
}
19 changes: 9 additions & 10 deletions OpenTween/Models/RelatedPostsTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,23 @@ public RelatedPostsTabModel(string tabName, PostClass targetPost)
this.TargetPost = targetPost;
}

public Task RefreshAsync(Twitter tw, bool startup, IProgress<string> progress)
=> this.RefreshAsync(tw, false, startup, progress);
public Task RefreshAsync(Twitter tw, IProgress<string> progress)
=> this.RefreshAsync(tw, false, progress);

public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress<string> progress)
public override async Task RefreshAsync(Twitter tw, bool backward, IProgress<string> 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
Expand Down
4 changes: 3 additions & 1 deletion OpenTween/Models/TabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostId, PostClass> Posts
Expand Down Expand Up @@ -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<string> progress);
public abstract Task RefreshAsync(Twitter tw, bool backward, IProgress<string> progress);

private readonly record struct TemporaryId(
PostId StatusId,
Expand Down
15 changes: 7 additions & 8 deletions OpenTween/Models/UserTimelineTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> progress)
public override async Task RefreshAsync(Twitter tw, bool backward, IProgress<string> 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");
}
}
Expand Down
17 changes: 5 additions & 12 deletions OpenTween/Tween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1730,12 +1730,6 @@ private async Task RetweetAsyncInternal(IProgress<string> 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<PostClass>();
Expand All @@ -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);
}
});
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 1 addition & 2 deletions OpenTween/TweetDetailsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,14 @@ private async Task<string> 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)
{
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);
}
Expand Down
Loading

0 comments on commit 0dd7ff5

Please sign in to comment.