aboutsummaryrefslogtreecommitdiff
path: root/Timeline
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline')
-rw-r--r--Timeline/Resources/Services/TimelineService.Designer.cs9
-rw-r--r--Timeline/Resources/Services/TimelineService.resx3
-rw-r--r--Timeline/Services/TimelineService.cs24
3 files changed, 35 insertions, 1 deletions
diff --git a/Timeline/Resources/Services/TimelineService.Designer.cs b/Timeline/Resources/Services/TimelineService.Designer.cs
index 3ee5959f..f4d41fb8 100644
--- a/Timeline/Resources/Services/TimelineService.Designer.cs
+++ b/Timeline/Resources/Services/TimelineService.Designer.cs
@@ -70,6 +70,15 @@ namespace Timeline.Resources.Services {
}
/// <summary>
+ /// Looks up a localized string similar to Unknown post content type &quot;{0}&quot; is saved in database..
+ /// </summary>
+ internal static string ExceptionDatabaseUnknownContentType {
+ get {
+ return ResourceManager.GetString("ExceptionDatabaseUnknownContentType", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to The owner username of personal timeline is of bad format..
/// </summary>
internal static string ExceptionFindTimelineUsernameBadFormat {
diff --git a/Timeline/Resources/Services/TimelineService.resx b/Timeline/Resources/Services/TimelineService.resx
index e0d76c9a..7df55fdf 100644
--- a/Timeline/Resources/Services/TimelineService.resx
+++ b/Timeline/Resources/Services/TimelineService.resx
@@ -120,6 +120,9 @@
<data name="ExceptionChangeMemberUsernameBadFormat" xml:space="preserve">
<value>The number {0} username is invalid.</value>
</data>
+ <data name="ExceptionDatabaseUnknownContentType" xml:space="preserve">
+ <value>Unknown post content type "{0}" is saved in database.</value>
+ </data>
<data name="ExceptionFindTimelineUsernameBadFormat" xml:space="preserve">
<value>The owner username of personal timeline is of bad format.</value>
</data>
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)