Make long text attachments contain the entire message.

Instead of just containing the 'overflow', long text attachments now
contain the entire body in full.
This commit is contained in:
Greyson Parrelli 2019-03-01 18:14:47 -08:00
parent 03aa9e9712
commit 003fa1b059
3 changed files with 13 additions and 11 deletions

View File

@ -1968,20 +1968,20 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private Pair<String, Optional<Slide>> getSplitMessage(String rawText, int maxPrimaryMessageSize) {
String bodyText = rawText;
Optional<Slide> extraText = Optional.absent();
Optional<Slide> textSlide = Optional.absent();
if (bodyText.length() > maxPrimaryMessageSize) {
bodyText = rawText.substring(0, maxPrimaryMessageSize);
byte[] extraData = rawText.substring(maxPrimaryMessageSize).getBytes();
Uri textUri = MemoryBlobProvider.getInstance().createUri(extraData);
byte[] textData = rawText.getBytes();
Uri textUri = MemoryBlobProvider.getInstance().createUri(textData);
String timestamp = new SimpleDateFormat("yyyy-MM-dd-HHmmss", Locale.US).format(new Date());
String filename = String.format("signal-%s.txt", timestamp);
extraText = Optional.of(new TextSlide(this, textUri, filename, extraData.length));
textSlide = Optional.of(new TextSlide(this, textUri, filename, textData.length));
}
return new Pair<>(bodyText, extraText);
return new Pair<>(bodyText, textSlide);
}
private MediaConstraints getCurrentMediaConstraints() {

View File

@ -564,8 +564,8 @@ public class ConversationFragment extends Fragment
if (mediaMessage.getSlideDeck().getTextSlide() != null && mediaMessage.getSlideDeck().getTextSlide().getUri() != null) {
try (InputStream stream = PartAuthority.getAttachmentStream(requireContext(), mediaMessage.getSlideDeck().getTextSlide().getUri())) {
String extraText = Util.readFullyAsString(stream);
composeIntent.putExtra(Intent.EXTRA_TEXT, message.getDisplayBody().toString() + extraText);
String fullBody = Util.readFullyAsString(stream);
composeIntent.putExtra(Intent.EXTRA_TEXT, fullBody);
} catch (IOException e) {
Log.w(TAG, "Failed to read long message text when forwarding.");
}

View File

@ -1,5 +1,7 @@
package org.thoughtcrime.securesms.longmessage;
import android.text.TextUtils;
import org.thoughtcrime.securesms.database.model.MessageRecord;
/**
@ -9,11 +11,11 @@ import org.thoughtcrime.securesms.database.model.MessageRecord;
class LongMessage {
private final MessageRecord messageRecord;
private final String extraBody;
private final String fullBody;
LongMessage(MessageRecord messageRecord, String extraBody) {
LongMessage(MessageRecord messageRecord, String fullBody) {
this.messageRecord = messageRecord;
this.extraBody = extraBody;
this.fullBody = fullBody;
}
MessageRecord getMessageRecord() {
@ -21,6 +23,6 @@ class LongMessage {
}
String getFullBody() {
return messageRecord.getBody() + extraBody;
return !TextUtils.isEmpty(fullBody) ? fullBody : messageRecord.getBody();
}
}