Fix caption sending for outgoing image and video stories.
This commit is contained in:
parent
c863e9ed4d
commit
0a07800eba
2 changed files with 25 additions and 3 deletions
|
@ -7,6 +7,7 @@ import io.reactivex.rxjava3.core.Maybe
|
||||||
import io.reactivex.rxjava3.core.Observable
|
import io.reactivex.rxjava3.core.Observable
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
import org.signal.core.util.BreakIteratorCompat
|
||||||
import org.signal.core.util.ThreadUtil
|
import org.signal.core.util.ThreadUtil
|
||||||
import org.signal.core.util.logging.Log
|
import org.signal.core.util.logging.Log
|
||||||
import org.signal.imageeditor.core.model.EditorModel
|
import org.signal.imageeditor.core.model.EditorModel
|
||||||
|
@ -38,6 +39,7 @@ import org.thoughtcrime.securesms.scribbles.ImageEditorFragment
|
||||||
import org.thoughtcrime.securesms.sms.MessageSender
|
import org.thoughtcrime.securesms.sms.MessageSender
|
||||||
import org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult
|
import org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult
|
||||||
import org.thoughtcrime.securesms.sms.OutgoingStoryMessage
|
import org.thoughtcrime.securesms.sms.OutgoingStoryMessage
|
||||||
|
import org.thoughtcrime.securesms.stories.Stories
|
||||||
import org.thoughtcrime.securesms.util.MessageUtil
|
import org.thoughtcrime.securesms.util.MessageUtil
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
@ -85,7 +87,7 @@ class MediaSelectionRepository(context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return Maybe.create<MediaSendActivityResult> { emitter ->
|
return Maybe.create<MediaSendActivityResult> { emitter ->
|
||||||
val trimmedBody: String = if (isViewOnce) "" else message?.toString()?.trim() ?: ""
|
val trimmedBody: String = if (isViewOnce) "" else getTruncatedBody(message?.toString()?.trim()) ?: ""
|
||||||
val trimmedMentions: List<Mention> = if (isViewOnce) emptyList() else mentions
|
val trimmedMentions: List<Mention> = if (isViewOnce) emptyList() else mentions
|
||||||
val modelsToTransform: Map<Media, MediaTransform> = buildModelsToTransform(selectedMedia, stateMap, quality)
|
val modelsToTransform: Map<Media, MediaTransform> = buildModelsToTransform(selectedMedia, stateMap, quality)
|
||||||
val oldToNewMediaMap: Map<Media, Media> = MediaRepository.transformMediaSync(context, selectedMedia, modelsToTransform)
|
val oldToNewMediaMap: Map<Media, Media> = MediaRepository.transformMediaSync(context, selectedMedia, modelsToTransform)
|
||||||
|
@ -93,7 +95,6 @@ class MediaSelectionRepository(context: Context) {
|
||||||
|
|
||||||
for (media in updatedMedia) {
|
for (media in updatedMedia) {
|
||||||
Log.w(TAG, media.uri.toString() + " : " + media.transformProperties.map { t: TransformProperties -> "" + t.isVideoTrim }.orElse("null"))
|
Log.w(TAG, media.uri.toString() + " : " + media.transformProperties.map { t: TransformProperties -> "" + t.isVideoTrim }.orElse("null"))
|
||||||
media.setCaption(trimmedBody)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val singleRecipient: Recipient? = singleContact?.let { Recipient.resolved(it.recipientId) }
|
val singleRecipient: Recipient? = singleContact?.let { Recipient.resolved(it.recipientId) }
|
||||||
|
@ -144,6 +145,16 @@ class MediaSelectionRepository(context: Context) {
|
||||||
}.subscribeOn(Schedulers.io()).cast(MediaSendActivityResult::class.java)
|
}.subscribeOn(Schedulers.io()).cast(MediaSendActivityResult::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getTruncatedBody(body: String?): String? {
|
||||||
|
return if (body.isNullOrEmpty()) {
|
||||||
|
body
|
||||||
|
} else {
|
||||||
|
val iterator = BreakIteratorCompat.getInstance()
|
||||||
|
iterator.setText(body)
|
||||||
|
iterator.take(Stories.MAX_BODY_SIZE).toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun deleteBlobs(media: List<Media>) {
|
fun deleteBlobs(media: List<Media>) {
|
||||||
media
|
media
|
||||||
.map(Media::getUri)
|
.map(Media::getUri)
|
||||||
|
|
|
@ -74,7 +74,6 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientUtil;
|
import org.thoughtcrime.securesms.recipients.RecipientUtil;
|
||||||
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
|
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
|
||||||
import org.thoughtcrime.securesms.stories.Stories;
|
|
||||||
import org.thoughtcrime.securesms.util.ParcelUtil;
|
import org.thoughtcrime.securesms.util.ParcelUtil;
|
||||||
import org.thoughtcrime.securesms.util.SignalLocalMetrics;
|
import org.thoughtcrime.securesms.util.SignalLocalMetrics;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
@ -236,6 +235,11 @@ public class MessageSender {
|
||||||
null);
|
null);
|
||||||
|
|
||||||
attachmentDatabase.updateMessageId(preUploadAttachmentIds, primaryMessageId, primaryMessage.getStoryType().isStory());
|
attachmentDatabase.updateMessageId(preUploadAttachmentIds, primaryMessageId, primaryMessage.getStoryType().isStory());
|
||||||
|
if (primaryMessage.getStoryType() != StoryType.NONE) {
|
||||||
|
for (final AttachmentId preUploadAttachmentId : preUploadAttachmentIds) {
|
||||||
|
attachmentDatabase.updateAttachmentCaption(preUploadAttachmentId, primaryMessage.getBody());
|
||||||
|
}
|
||||||
|
}
|
||||||
messageIds.add(primaryMessageId);
|
messageIds.add(primaryMessageId);
|
||||||
|
|
||||||
List<DatabaseAttachment> preUploadAttachments = Stream.of(preUploadAttachmentIds)
|
List<DatabaseAttachment> preUploadAttachments = Stream.of(preUploadAttachmentIds)
|
||||||
|
@ -265,6 +269,12 @@ public class MessageSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentDatabase.updateMessageId(attachmentIds, messageId, secondaryMessage.getStoryType().isStory());
|
attachmentDatabase.updateMessageId(attachmentIds, messageId, secondaryMessage.getStoryType().isStory());
|
||||||
|
if (primaryMessage.getStoryType() != StoryType.NONE) {
|
||||||
|
for (final AttachmentId preUploadAttachmentId : preUploadAttachmentIds) {
|
||||||
|
attachmentDatabase.updateAttachmentCaption(preUploadAttachmentId, primaryMessage.getBody());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
messageIds.add(messageId);
|
messageIds.add(messageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,6 +304,7 @@ public class MessageSender {
|
||||||
} else {
|
} else {
|
||||||
AttachmentId attachmentCopyId = attachmentDatabase.insertAttachmentForPreUpload(preUploadAttachment.get()).getAttachmentId();
|
AttachmentId attachmentCopyId = attachmentDatabase.insertAttachmentForPreUpload(preUploadAttachment.get()).getAttachmentId();
|
||||||
attachmentDatabase.updateMessageId(Collections.singletonList(attachmentCopyId), messageId, true);
|
attachmentDatabase.updateMessageId(Collections.singletonList(attachmentCopyId), messageId, true);
|
||||||
|
attachmentDatabase.updateAttachmentCaption(attachmentCopyId, storyMessage.getOutgoingSecureMediaMessage().getBody());
|
||||||
messageIds.add(messageId);
|
messageIds.add(messageId);
|
||||||
messages.add(storyMessage.getOutgoingSecureMediaMessage());
|
messages.add(storyMessage.getOutgoingSecureMediaMessage());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue