Allow attaching https URLs directly

This commit is contained in:
Stephen Paul Weber 2024-08-14 17:08:24 +02:00 committed by Arne
parent 2c2ed3e71f
commit e63f3445a9
3 changed files with 13 additions and 4 deletions

View file

@ -43,6 +43,7 @@ public class AttachFileToConversationRunnable implements Runnable, TranscoderLis
private final Message message;
private final Conversation conversation;
private final Uri uri;
private final String mimeType;
private final String type;
private final UiCallback<Message> callback;
private final long maxUploadSize;
@ -59,7 +60,7 @@ public class AttachFileToConversationRunnable implements Runnable, TranscoderLis
this.conversation = conversation;
this.callback = callback;
this.maxUploadSize = maxUploadSize;
final String mimeType = MimeUtils.guessMimeTypeFromUriAndMime(mXmppConnectionService, uri, type);
mimeType = MimeUtils.guessMimeTypeFromUriAndMime(mXmppConnectionService, uri, type);
this.originalFileSize = FileBackend.getFileSize(mXmppConnectionService, uri);
this.isVideoMessage = !getFileBackend().useFileAsIs(uri)
&& (mimeType != null && mimeType.startsWith("video/"))
@ -73,7 +74,16 @@ public class AttachFileToConversationRunnable implements Runnable, TranscoderLis
private void processAsFile() {
final String path = mXmppConnectionService.getFileBackend().getOriginalPath(uri);
if (path != null && !FileBackend.isPathBlacklisted(path)) {
if ("https".equals(uri.getScheme())) {
message.getFileParams().url = uri.toString();
message.getFileParams().setMediaType(mimeType);
final int encryption = message.getEncryption();
mXmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, false, (file) -> {
message.setEncryption(encryption);
mXmppConnectionService.sendMessage(message);
callback.success(message);
});
} else if (path != null && !FileBackend.isPathBlacklisted(path)) {
message.setRelativeFilePath(path);
mXmppConnectionService.getFileBackend().updateFileParams(message);
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {

View file

@ -769,7 +769,6 @@ public class XmppConnectionService extends Service {
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
}
if (subject.length() > 0) message.setSubject(subject);
if (subject != null && subject.length() > 0) message.setSubject(subject);
if (getBooleanPreference("show_thread_feature", R.bool.show_thread_feature)) {
message.setThread(conversation.getThread());

View file

@ -127,7 +127,7 @@ public class Attachment implements Parcelable {
public static boolean canBeSendInband(final List<Attachment> attachments) {
for (Attachment attachment : attachments) {
if (attachment.type != Type.LOCATION) {
if (attachment.type != Type.LOCATION && !"https".equals(attachment.uri.getScheme())) {
return false;
}
}