progress.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5, backward ? -1 : 1));
var firstLoad = !this.IsFirstLoadCompleted;
+ var count = Twitter.GetApiResultCount(MyCommon.WORKERTYPE.Timeline, backward, firstLoad);
+ var cursor = backward ? this.CursorBottom : this.CursorTop;
- await twAccount.Legacy.GetHomeTimelineApi(this, backward, firstLoad)
+ var response = await twAccount.Legacy.GetHomeTimelineApi(count, cursor, firstLoad)
.ConfigureAwait(false);
+ foreach (var post in response.Posts)
+ TabInformations.GetInstance().AddPost(post);
+
// 新着時未読クリア
if (SettingManager.Instance.Common.ReadOldPosts)
TabInformations.GetInstance().SetReadHomeTab();
TabInformations.GetInstance().DistributePosts();
+ if (response.CursorTop != null && !backward)
+ this.CursorTop = response.CursorTop;
+
+ if (response.CursorBottom != null)
+ this.CursorBottom = response.CursorBottom;
+
if (firstLoad)
this.IsFirstLoadCompleted = true;
--- /dev/null
+// OpenTween - Client of Twitter
+// Copyright (c) 2024 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#nullable enable
+
+namespace OpenTween.Models
+{
+ public record TimelineResponse(
+ PostClass[] Posts,
+ IQueryCursor? CursorTop,
+ IQueryCursor? CursorBottom
+ );
+}
return Math.Min(count, GetMaxApiResultCount(type));
}
- public async Task GetHomeTimelineApi(HomeTabModel tab, bool more, bool firstLoad)
+ public async Task<TimelineResponse> GetHomeTimelineApi(int count, IQueryCursor? cursor, bool firstLoad)
{
this.CheckAccountState();
- var count = GetApiResultCount(MyCommon.WORKERTYPE.Timeline, more, firstLoad);
-
TwitterStatus[] statuses;
+ IQueryCursor? cursorTop = null, cursorBottom = null;
+
if (this.Api.AuthType == APIAuthType.TwitterComCookie)
{
- var cursor = more ? tab.CursorBottom : tab.CursorTop;
var request = new HomeLatestTimelineRequest
{
Count = count,
statuses = response.ToTwitterStatuses();
- tab.CursorBottom = response.CursorBottom;
-
- if (!more)
- tab.CursorTop = response.CursorTop;
+ cursorTop = response.CursorTop;
+ cursorBottom = response.CursorBottom;
}
else
{
- var maxId = more ? tab.CursorBottom?.As<TwitterStatusId>() : null;
+ TwitterStatusId? maxId = null, sinceId = null;
- statuses = await this.Api.StatusesHomeTimeline(count, maxId)
+ if (cursor is QueryCursor<TwitterStatusId> statusIdCursor)
+ {
+ if (statusIdCursor.Type == CursorType.Top)
+ sinceId = statusIdCursor.Value;
+ else if (statusIdCursor.Type == CursorType.Bottom)
+ maxId = statusIdCursor.Value;
+ }
+
+ statuses = await this.Api.StatusesHomeTimeline(count, maxId, sinceId)
.ConfigureAwait(false);
if (statuses.Length > 0)
{
- var min = statuses.Select(x => new TwitterStatusId(x.IdStr)).Min();
- tab.CursorBottom = new QueryCursor<TwitterStatusId>(CursorType.Bottom, min);
+ var (min, max) = statuses.Select(x => new TwitterStatusId(x.IdStr)).MinMax();
+ cursorTop = new QueryCursor<TwitterStatusId>(CursorType.Top, max);
+ cursorBottom = new QueryCursor<TwitterStatusId>(CursorType.Bottom, min);
}
}
var posts = this.CreatePostsFromJson(statuses, firstLoad);
posts = this.FilterNoRetweetUserPosts(posts);
- foreach (var post in posts)
- TabInformations.GetInstance().AddPost(post);
+ return new(posts, cursorTop, cursorBottom);
}
public async Task GetMentionsTimelineApi(MentionsTabModel tab, bool more, bool firstLoad)