That fuck shit the fascists are using
at master 63 lines 2.0 kB view raw
1package org.tm.archive.util; 2 3import android.content.Context; 4import android.net.Uri; 5 6import androidx.annotation.NonNull; 7 8import org.tm.archive.mms.TextSlide; 9import org.tm.archive.providers.BlobProvider; 10 11import java.text.SimpleDateFormat; 12import java.util.Date; 13import java.util.Locale; 14import java.util.Optional; 15 16public final class MessageUtil { 17 18 private MessageUtil() {} 19 20 /** 21 * @return If the message is longer than the allowed text size, this will return trimmed text with 22 * an accompanying TextSlide. Otherwise it'll just return the original text. 23 */ 24 public static SplitResult getSplitMessage(@NonNull Context context, @NonNull String rawText, int maxPrimaryMessageSize) { 25 String bodyText = rawText; 26 Optional<TextSlide> textSlide = Optional.empty(); 27 28 if (bodyText.length() > maxPrimaryMessageSize) { 29 bodyText = rawText.substring(0, maxPrimaryMessageSize); 30 31 byte[] textData = rawText.getBytes(); 32 String timestamp = new SimpleDateFormat("yyyy-MM-dd-HHmmss", Locale.US).format(new Date()); 33 String filename = String.format("signal-%s.txt", timestamp); 34 Uri textUri = BlobProvider.getInstance() 35 .forData(textData) 36 .withMimeType(MediaUtil.LONG_TEXT) 37 .withFileName(filename) 38 .createForSingleSessionInMemory(); 39 40 textSlide = Optional.of(new TextSlide(context, textUri, filename, textData.length)); 41 } 42 43 return new SplitResult(bodyText, textSlide); 44 } 45 46 public static class SplitResult { 47 private final String body; 48 private final Optional<TextSlide> textSlide; 49 50 private SplitResult(@NonNull String body, @NonNull Optional<TextSlide> textSlide) { 51 this.body = body; 52 this.textSlide = textSlide; 53 } 54 55 public @NonNull String getBody() { 56 return body; 57 } 58 59 public @NonNull Optional<TextSlide> getTextSlide() { 60 return textSlide; 61 } 62 } 63}