diff options
author | crupest <crupest@outlook.com> | 2020-03-07 23:58:21 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-03-07 23:58:21 +0800 |
commit | 40df655a8d9b85a7f08ab221d5f85aaa20d7272e (patch) | |
tree | be6364087386d56c00b1e482e656559edd60afd1 /Timeline/Services/TimelineService.cs | |
parent | b686b383022e6d9db2bd61ad441be753cae3dbcf (diff) | |
download | timeline-40df655a8d9b85a7f08ab221d5f85aaa20d7272e.tar.gz timeline-40df655a8d9b85a7f08ab221d5f85aaa20d7272e.tar.bz2 timeline-40df655a8d9b85a7f08ab221d5f85aaa20d7272e.zip |
...
Diffstat (limited to 'Timeline/Services/TimelineService.cs')
-rw-r--r-- | Timeline/Services/TimelineService.cs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index edd0a0ab..ff2532ea 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -432,10 +432,20 @@ namespace Timeline.Services if (entity.Content != null) // otherwise it is deleted
{
var author = Mapper.Map<UserInfo>(await UserService.GetUserById(entity.AuthorId));
+
+ var type = entity.ContentType;
+
+ ITimelinePostContent content = type switch
+ {
+ TimelinePostContentTypes.Text => new TextTimelinePostContent(entity.Content),
+ TimelinePostContentTypes.Image => new ImageTimelinePostContent(entity.Content),
+ _ => throw new DatabaseCorruptedException(string.Format(CultureInfo.InvariantCulture, ExceptionDatabaseUnknownContentType, type))
+ };
+
posts.Add(new TimelinePostInfo
{
Id = entity.LocalId,
- Content = entity.Content,
+ Content = content,
Author = author,
Time = entity.Time,
LastUpdated = entity.LastUpdated
@@ -544,10 +554,22 @@ namespace Timeline.Services if (post == null)
throw new TimelinePostNotExistException(id);
+ string? dataTag = null;
+
+ if (post.ContentType == TimelinePostContentTypes.Image)
+ {
+ dataTag = post.Content;
+ }
+
post.Content = null;
post.LastUpdated = Clock.GetCurrentTime();
await Database.SaveChangesAsync();
+
+ if (dataTag != null)
+ {
+ await DataManager.FreeEntry(dataTag);
+ }
}
public async Task ChangeProperty(string name, TimelinePatchRequest newProperties)
|