From 9aca0af22c08b67dd875cf640592230a24dab409 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Fri, 2 Dec 2022 10:43:31 -0400 Subject: [PATCH] Fix issue with poor sent video viewing behavior. --- .../securesms/database/AttachmentTable.java | 3 ++- .../stories/viewer/post/StoryPostViewModel.kt | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.java b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.java index 3fbcf5b819..17d4bdae69 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.java @@ -697,6 +697,7 @@ public class AttachmentTable extends DatabaseTable { contentValues.put(HEIGHT, sourceAttachment.getHeight()); contentValues.put(CONTENT_TYPE, sourceAttachment.getContentType()); contentValues.put(VISUAL_HASH, getVisualHashStringOrNull(sourceAttachment)); + contentValues.put(TRANSFORM_PROPERTIES, sourceAttachment.getTransformProperties().serialize()); database.update(TABLE_NAME, contentValues, PART_ID_WHERE, destinationId.toStrings()); } @@ -1604,7 +1605,7 @@ public class AttachmentTable extends DatabaseTable { return new TransformProperties(true, false, 0, 0, sentMediaQuality); } - @NonNull String serialize() { + public @NonNull String serialize() { return JsonUtil.toJson(this); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/stories/viewer/post/StoryPostViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/stories/viewer/post/StoryPostViewModel.kt index dec60fa489..3330bc1ad5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/stories/viewer/post/StoryPostViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/stories/viewer/post/StoryPostViewModel.kt @@ -13,6 +13,7 @@ import org.thoughtcrime.securesms.database.model.databaseprotos.StoryTextPost import org.thoughtcrime.securesms.stories.viewer.page.StoryPost import org.thoughtcrime.securesms.util.Base64 import org.thoughtcrime.securesms.util.rx.RxStore +import kotlin.time.Duration import kotlin.time.Duration.Companion.microseconds class StoryPostViewModel(private val repository: StoryTextPostRepository) : ViewModel() { @@ -40,11 +41,25 @@ class StoryPostViewModel(private val repository: StoryTextPostRepository) : View store.update { StoryPostState.None() } } else if (storyPostContent.isVideo()) { store.update { + val shouldSkipTransform = storyPostContent.attachment.transformProperties.shouldSkipTransform() + + val clipStart: Duration = if (shouldSkipTransform) { + 0L.microseconds + } else { + storyPostContent.attachment.transformProperties.videoTrimStartTimeUs.microseconds + } + + val clipEnd: Duration = if (shouldSkipTransform) { + 0L.microseconds + } else { + storyPostContent.attachment.transformProperties.videoTrimEndTimeUs.microseconds + } + StoryPostState.VideoPost( videoUri = storyPostContent.uri, size = storyPostContent.attachment.size, - clipStart = storyPostContent.attachment.transformProperties.videoTrimStartTimeUs.microseconds, - clipEnd = storyPostContent.attachment.transformProperties.videoTrimEndTimeUs.microseconds, + clipStart = clipStart, + clipEnd = clipEnd, blurHash = storyPostContent.attachment.blurHash ) }