Skip to content

Commit

Permalink
Fix issue with re-using forwarded attachment pointers.
Browse files Browse the repository at this point in the history
We were deleting upload data for incoming attachments when we shouldn't
have.

Fixes #9570
  • Loading branch information
greyson-signal committed Apr 30, 2020
1 parent c9f2f57 commit 9d35fb3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,10 @@ public void insertAttachmentsForPlaceholder(long mmsId, @NonNull AttachmentId at
}

values.put(TRANSFER_STATE, TRANSFER_PROGRESS_DONE);
values.put(CDN_NUMBER, 0);
values.put(CONTENT_LOCATION, (String)null);
values.put(CONTENT_DISPOSITION, (String)null);
values.put(DIGEST, (byte[])null);
values.put(NAME, (String) null);
values.put(FAST_PREFLIGHT_ID, (String)null);
values.put(TRANSFER_FILE, (String)null);

values.put(TRANSFORM_PROPERTIES, TransformProperties.forSkipTransform().serialize());

if (database.update(TABLE_NAME, values, PART_ID_WHERE, attachmentId.toStrings()) == 0) {
//noinspection ResultOfMethodCallIgnored
dataInfo.file.delete();
Expand Down Expand Up @@ -1198,7 +1194,9 @@ private AttachmentId insertAttachment(long mmsId, Attachment attachment, boolean
}
}

boolean useTemplateUpload = template.getUploadTimestamp() > attachment.getUploadTimestamp() && template.getTransferState() == TRANSFER_PROGRESS_DONE;
boolean useTemplateUpload = template.getUploadTimestamp() > attachment.getUploadTimestamp() &&
template.getTransferState() == TRANSFER_PROGRESS_DONE &&
template.getTransformProperties().shouldSkipTransform();

ContentValues contentValues = new ContentValues();
contentValues.put(MMS_ID, mmsId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.media.MediaDataSource;
import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -114,7 +115,7 @@ public void onRun() throws Exception {
}

long timeSinceUpload = System.currentTimeMillis() - databaseAttachment.getUploadTimestamp();
if (timeSinceUpload < UPLOAD_REUSE_THRESHOLD) {
if (timeSinceUpload < UPLOAD_REUSE_THRESHOLD && !TextUtils.isEmpty(databaseAttachment.getLocation())) {
Log.i(TAG, "We can re-use an already-uploaded file. It was uploaded " + timeSinceUpload + " ms ago. Skipping.");
return;
} else if (databaseAttachment.getUploadTimestamp() > 0) {
Expand Down

0 comments on commit 9d35fb3

Please sign in to comment.