From 1eb71943ad8d4769cb6166a6f33c0eecea80fffe Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 18 Jun 2020 17:13:08 +0800 Subject: feat(back): Timeline service add last modified. --- Timeline/Services/TimelineService.cs | 55 +++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 14 deletions(-) (limited to 'Timeline/Services/TimelineService.cs') diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index ba5576d1..6c1e91c6 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -15,6 +15,23 @@ using static Timeline.Resources.Services.TimelineService; namespace Timeline.Services { + public static class TimelineHelper + { + public static string ExtractTimelineName(string name, out bool isPersonal) + { + if (name.StartsWith("@", StringComparison.OrdinalIgnoreCase)) + { + isPersonal = true; + return name.Substring(1); + } + else + { + isPersonal = false; + return name; + } + } + } + public enum TimelineUserRelationshipType { Own = 0b1, @@ -383,19 +400,7 @@ namespace Timeline.Services }; } - private static string ExtractTimelineName(string name, out bool isPersonal) - { - if (name.StartsWith("@", StringComparison.OrdinalIgnoreCase)) - { - isPersonal = true; - return name.Substring(1); - } - else - { - isPersonal = false; - return name; - } - } + // Get timeline id by name. If it is a personal timeline and it does not exist, it will be created. // @@ -407,7 +412,7 @@ namespace Timeline.Services // It follows all timeline-related function common interface contracts. private async Task FindTimelineId(string timelineName) { - timelineName = ExtractTimelineName(timelineName, out var isPersonal); + timelineName = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal); if (isPersonal) { @@ -713,16 +718,26 @@ namespace Timeline.Services var timelineEntity = await _database.Timelines.Where(t => t.Id == timelineId).SingleAsync(); + var changed = false; + if (newProperties.Description != null) { + changed = true; timelineEntity.Description = newProperties.Description; } if (newProperties.Visibility.HasValue) { + changed = true; timelineEntity.Visibility = newProperties.Visibility.Value; } + if (changed) + { + var currentTime = _clock.GetCurrentTime(); + timelineEntity.LastModified = currentTime; + } + await _database.SaveChangesAsync(); } @@ -768,8 +783,17 @@ namespace Timeline.Services simplifiedAdd.Remove(u); simplifiedRemove.Remove(u); } + + if (simplifiedAdd.Count == 0) + simplifiedAdd = null; + + if (simplifiedRemove.Count == 0) + simplifiedRemove = null; } + if (simplifiedAdd == null && simplifiedRemove == null) + return; + var timelineId = await FindTimelineId(timelineName); async Task?> CheckExistenceAndGetId(List? list) @@ -799,6 +823,9 @@ namespace Timeline.Services _database.TimelineMembers.RemoveRange(membersToRemove); } + var timelineEntity = await _database.Timelines.Where(t => t.Id == timelineId).SingleAsync(); + timelineEntity.LastModified = _clock.GetCurrentTime(); + await _database.SaveChangesAsync(); } -- cgit v1.2.3