From 7df5e63e8b2eaa5b4f83ee72a32eeedd480cde47 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 11 Aug 2020 17:59:44 +0800 Subject: Post list modified since now consider username change. And make all datetime utc. --- Timeline/Services/TimelineService.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Timeline/Services/TimelineService.cs') diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index 283938fb..0070fe3e 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -565,11 +565,13 @@ namespace Timeline.Services public async Task> GetPosts(string timelineName, DateTime? modifiedSince = null, bool includeDeleted = false) { + modifiedSince = modifiedSince?.MyToUtc(); + if (timelineName == null) throw new ArgumentNullException(nameof(timelineName)); var timelineId = await FindTimelineId(timelineName); - var query = _database.TimelinePosts.OrderBy(p => p.Time).Where(p => p.TimelineId == timelineId); + IQueryable query = _database.TimelinePosts.Where(p => p.TimelineId == timelineId); if (!includeDeleted) { @@ -578,9 +580,11 @@ namespace Timeline.Services if (modifiedSince.HasValue) { - query = query.Where(p => p.LastUpdated >= modifiedSince); + query = query.Include(p => p.Author).Where(p => p.LastUpdated >= modifiedSince || (p.Author != null && p.Author.UsernameChangeTime >= modifiedSince)); } + query = query.OrderBy(p => p.Time); + var postEntities = await query.ToListAsync(); var posts = new List(); @@ -663,6 +667,8 @@ namespace Timeline.Services public async Task CreateTextPost(string timelineName, long authorId, string text, DateTime? time) { + time = time?.MyToUtc(); + if (timelineName == null) throw new ArgumentNullException(nameof(timelineName)); if (text == null) @@ -704,6 +710,8 @@ namespace Timeline.Services public async Task CreateImagePost(string timelineName, long authorId, byte[] data, DateTime? time) { + time = time?.MyToUtc(); + if (timelineName == null) throw new ArgumentNullException(nameof(timelineName)); if (data == null) -- cgit v1.2.3