aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services/TimelineService.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-08-11 01:48:57 +0800
committercrupest <crupest@outlook.com>2020-08-11 01:48:57 +0800
commitc3369742b6e68714d0a7df46a99a0798eb2d6940 (patch)
tree874a30f989e0a9d8080aae76e76828b6950352c2 /Timeline/Services/TimelineService.cs
parente02e1e120693d466679cae2b602085f57b60971f (diff)
downloadtimeline-c3369742b6e68714d0a7df46a99a0798eb2d6940.tar.gz
timeline-c3369742b6e68714d0a7df46a99a0798eb2d6940.tar.bz2
timeline-c3369742b6e68714d0a7df46a99a0798eb2d6940.zip
Handle post deletion on user deletion correctly.
Diffstat (limited to 'Timeline/Services/TimelineService.cs')
-rw-r--r--Timeline/Services/TimelineService.cs35
1 files changed, 35 insertions, 0 deletions
diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs
index ad410d15..283938fb 100644
--- a/Timeline/Services/TimelineService.cs
+++ b/Timeline/Services/TimelineService.cs
@@ -220,6 +220,12 @@ namespace Timeline.Services
Task DeletePost(string timelineName, long postId);
/// <summary>
+ /// Delete all posts of the given user. Used when delete a user.
+ /// </summary>
+ /// <param name="userId">The id of the user.</param>
+ Task DeleteAllPostsOfUser(long userId);
+
+ /// <summary>
/// Change member of timeline.
/// </summary>
/// <param name="timelineName">The name of the timeline.</param>
@@ -776,6 +782,35 @@ namespace Timeline.Services
}
}
+ public async Task DeleteAllPostsOfUser(long userId)
+ {
+ var posts = await _database.TimelinePosts.Where(p => p.AuthorId == userId).ToListAsync();
+
+ var now = _clock.GetCurrentTime();
+
+ var dataTags = new List<string>();
+
+ foreach (var post in posts)
+ {
+ if (post.Content != null)
+ {
+ if (post.ContentType == TimelinePostContentTypes.Image)
+ {
+ dataTags.Add(post.Content);
+ }
+ post.Content = null;
+ }
+ post.LastUpdated = now;
+ }
+
+ await _database.SaveChangesAsync();
+
+ foreach (var dataTag in dataTags)
+ {
+ await _dataManager.FreeEntry(dataTag);
+ }
+ }
+
public async Task ChangeProperty(string timelineName, TimelineChangePropertyRequest newProperties)
{
if (timelineName == null)