mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 11:12:40 +00:00
Added ability to receive long messages.
Send support is in here too. We'll enable it in a future release after enough people have updated.
This commit is contained in:
@@ -37,7 +37,7 @@ public class AttachmentUtil {
|
||||
Set<String> allowedTypes = getAllowedAutoDownloadTypes(context);
|
||||
String contentType = attachment.getContentType();
|
||||
|
||||
if (attachment.isVoiceNote() || (MediaUtil.isAudio(attachment) && TextUtils.isEmpty(attachment.getFileName()))) {
|
||||
if (attachment.isVoiceNote() || (MediaUtil.isAudio(attachment) && TextUtils.isEmpty(attachment.getFileName())) || MediaUtil.isLongTextType(attachment.getContentType())) {
|
||||
return true;
|
||||
} else if (isNonDocumentType(contentType)) {
|
||||
return allowedTypes.contains(MediaUtil.getDiscreteMimeType(contentType));
|
||||
|
||||
@@ -45,14 +45,16 @@ public abstract class CharacterCalculator {
|
||||
}
|
||||
|
||||
public static class CharacterState {
|
||||
public int charactersRemaining;
|
||||
public int messagesSpent;
|
||||
public int maxMessageSize;
|
||||
public final int charactersRemaining;
|
||||
public final int messagesSpent;
|
||||
public final int maxTotalMessageSize;
|
||||
public final int maxPrimaryMessageSize;
|
||||
|
||||
public CharacterState(int messagesSpent, int charactersRemaining, int maxMessageSize) {
|
||||
this.messagesSpent = messagesSpent;
|
||||
this.charactersRemaining = charactersRemaining;
|
||||
this.maxMessageSize = maxMessageSize;
|
||||
public CharacterState(int messagesSpent, int charactersRemaining, int maxTotalMessageSize, int maxPrimaryMessageSize) {
|
||||
this.messagesSpent = messagesSpent;
|
||||
this.charactersRemaining = charactersRemaining;
|
||||
this.maxTotalMessageSize = maxTotalMessageSize;
|
||||
this.maxPrimaryMessageSize = maxPrimaryMessageSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.thoughtcrime.securesms.mms.ImageSlide;
|
||||
import org.thoughtcrime.securesms.mms.MmsSlide;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.mms.Slide;
|
||||
import org.thoughtcrime.securesms.mms.TextSlide;
|
||||
import org.thoughtcrime.securesms.mms.VideoSlide;
|
||||
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
|
||||
|
||||
@@ -45,6 +46,7 @@ public class MediaUtil {
|
||||
public static final String AUDIO_UNSPECIFIED = "audio/*";
|
||||
public static final String VIDEO_UNSPECIFIED = "video/*";
|
||||
public static final String VCARD = "text/x-vcard";
|
||||
public static final String LONG_TEXT = "text/x-signal-plain";
|
||||
|
||||
|
||||
public static Slide getSlideForAttachment(Context context, Attachment attachment) {
|
||||
@@ -59,6 +61,8 @@ public class MediaUtil {
|
||||
slide = new AudioSlide(context, attachment);
|
||||
} else if (isMms(attachment.getContentType())) {
|
||||
slide = new MmsSlide(context, attachment);
|
||||
} else if (isLongTextType(attachment.getContentType())) {
|
||||
slide = new TextSlide(context, attachment);
|
||||
} else if (attachment.getContentType() != null) {
|
||||
slide = new DocumentSlide(context, attachment);
|
||||
}
|
||||
@@ -230,6 +234,10 @@ public class MediaUtil {
|
||||
return (null != contentType) && contentType.startsWith("video/");
|
||||
}
|
||||
|
||||
public static boolean isLongTextType(String contentType) {
|
||||
return (null != contentType) && contentType.equals(LONG_TEXT);
|
||||
}
|
||||
|
||||
public static boolean hasVideoThumbnail(Uri uri) {
|
||||
Log.i(TAG, "Checking: " + uri);
|
||||
|
||||
|
||||
@@ -6,6 +6,6 @@ public class MmsCharacterCalculator extends CharacterCalculator {
|
||||
|
||||
@Override
|
||||
public CharacterState calculateCharacters(String messageBody) {
|
||||
return new CharacterState(1, MAX_SIZE - messageBody.length(), MAX_SIZE);
|
||||
return new CharacterState(1, MAX_SIZE - messageBody.length(), MAX_SIZE, MAX_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,13 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
public class PushCharacterCalculator extends CharacterCalculator {
|
||||
private static final int MAX_SIZE = 2000;
|
||||
// TODO: Switch to 64kb to enable long message sending.
|
||||
// private static final int MAX_TOTAL_SIZE = 64 * 1024;
|
||||
private static final int MAX_TOTAL_SIZE = 2000;
|
||||
private static final int MAX_PRIMARY_SIZE = 2000;
|
||||
@Override
|
||||
public CharacterState calculateCharacters(String messageBody) {
|
||||
return new CharacterState(1, MAX_SIZE - messageBody.length(), MAX_SIZE);
|
||||
return new CharacterState(1, MAX_TOTAL_SIZE - messageBody.length(), MAX_TOTAL_SIZE, MAX_PRIMARY_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SmsCharacterCalculator extends CharacterCalculator {
|
||||
maxMessageSize = (charactersSpent + charactersRemaining);
|
||||
}
|
||||
|
||||
return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize);
|
||||
return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize, maxMessageSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,6 +142,15 @@ public class Util {
|
||||
return map.containsKey(key) ? map.get(key) : defaultValue;
|
||||
}
|
||||
|
||||
public static String getFirstNonEmpty(String... values) {
|
||||
for (String value : values) {
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static <E> List<List<E>> chunk(@NonNull List<E> list, int chunkSize) {
|
||||
List<List<E>> chunks = new ArrayList<>(list.size() / chunkSize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user