aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java2
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java2
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java41
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java2
-rw-r--r--src/main/java/de/pixart/messenger/services/NotificationService.java5
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationActivity.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java18
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java3
-rw-r--r--src/main/java/de/pixart/messenger/utils/UIHelper.java2
9 files changed, 18 insertions, 59 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java b/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java
index 4b0e78764..bcdc7bbed 100644
--- a/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java
+++ b/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java
@@ -123,7 +123,7 @@ public class PgpDecryptionService {
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
final HttpConnectionManager manager = mXmppConnectionService.getHttpConnectionManager();
if (message.trusted()
- && message.treatAsDownloadable() != Message.Decision.NEVER
+ && message.treatAsDownloadable()
&& manager.getAutoAcceptFileSize() > 0) {
manager.createNewDownloadConnection(message);
}
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index 4d9b96fde..a3811a751 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -181,7 +181,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
for (final Message message : this.messages) {
if (message.getUuid().equals(uuid)
&& message.getEncryption() != Message.ENCRYPTION_PGP
- && (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.treatAsDownloadable() != Message.Decision.NEVER)) {
+ && (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.treatAsDownloadable())) {
return message;
}
}
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index be30ced7a..89bd9069d 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -501,8 +501,8 @@ public class Message extends AbstractEntity {
this.getBody().length() + message.getBody().length() <= Config.MAX_DISPLAY_MESSAGE_CHARS &&
!GeoHelper.isGeoUri(message.getBody()) &&
!GeoHelper.isGeoUri(this.body) &&
- message.treatAsDownloadable() == Decision.NEVER &&
- this.treatAsDownloadable() == Decision.NEVER &&
+ !message.treatAsDownloadable() &&
+ !this.treatAsDownloadable() &&
!message.getBody().startsWith(ME_COMMAND) &&
!this.getBody().startsWith(ME_COMMAND) &&
!this.bodyIsHeart() &&
@@ -614,12 +614,6 @@ public class Message extends AbstractEntity {
this.oob = isOob;
}
- public enum Decision {
- MUST,
- SHOULD,
- NEVER,
- }
-
private static String extractRelevantExtension(URL url) {
String path = url.getPath();
return extractRelevantExtension(path);
@@ -662,37 +656,20 @@ public class Message extends AbstractEntity {
}
}
- public Decision treatAsDownloadable() {
+ public boolean treatAsDownloadable() {
if (body.trim().contains(" ")) {
- return Decision.NEVER;
+ return false;
}
try {
- URL url = new URL(body);
- String ref = url.getRef();
+ final URL url = new URL(body);
+ final String ref = url.getRef();
final String protocol = url.getProtocol();
final boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}");
- if (AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted) {
- return Decision.MUST;
- }
- if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
- return Decision.NEVER;
- } else if (oob || encrypted) {
- return Decision.MUST;
- }
- final String extension = extractRelevantExtension(url);
- if (extension == null
- || encryption == Message.ENCRYPTION_OTR
- || encryption == Message.ENCRYPTION_AXOLOTL) {
- return Decision.NEVER;
- } else if (Transferable.VALID_IMAGE_EXTENSIONS.contains(extension)
- || Transferable.WELL_KNOWN_EXTENSIONS.contains(extension)) {
- return Decision.SHOULD;
- } else {
- return Decision.NEVER;
- }
+ return (AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted)
+ || ((protocol.equalsIgnoreCase("http") || protocol.equalsIgnoreCase("https")) && (oob || encrypted));
} catch (MalformedURLException e) {
- return Decision.NEVER;
+ return false;
}
}
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java
index 90b4254f4..f988a1956 100644
--- a/src/main/java/de/pixart/messenger/parser/MessageParser.java
+++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java
@@ -608,7 +608,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
mXmppConnectionService.databaseBackend.createMessage(message);
final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager();
- if (message.trusted() && message.treatAsDownloadable() != Message.Decision.NEVER && manager.getAutoAcceptFileSize() > 0) {
+ if (message.trusted() && message.treatAsDownloadable() && manager.getAutoAcceptFileSize() > 0) {
manager.createNewDownloadConnection(message);
} else if (notify) {
if (query != null && query.isCatchup()) {
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java
index adc106ee5..25b87f761 100644
--- a/src/main/java/de/pixart/messenger/services/NotificationService.java
+++ b/src/main/java/de/pixart/messenger/services/NotificationService.java
@@ -482,10 +482,7 @@ public class NotificationService {
private Message getFirstDownloadableMessage(final Iterable<Message> messages) {
for (final Message message : messages) {
- if (message.getTransferable() != null
- && (message.getType() == Message.TYPE_FILE
- || message.getType() == Message.TYPE_IMAGE
- || message.treatAsDownloadable() != Message.Decision.NEVER)) {
+ if (message.getTransferable() != null || (message.getType() == Message.TYPE_TEXT && message.treatAsDownloadable())) {
return message;
}
}
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
index ef46bf0e3..52899f21e 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
@@ -807,7 +807,7 @@ public class ConversationActivity extends XmppActivity
if (!transferable.start()) {
Toast.makeText(this, R.string.not_connected_try_again, Toast.LENGTH_SHORT).show();
}
- } else if (message.treatAsDownloadable() != Message.Decision.NEVER) {
+ } else if (message.treatAsDownloadable()) {
xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true);
}
}
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index fc735785c..7324f27b0 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -627,14 +627,13 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
MenuItem shareWith = menu.findItem(R.id.share_with);
MenuItem sendAgain = menu.findItem(R.id.send_again);
MenuItem copyUrl = menu.findItem(R.id.copy_url);
- MenuItem downloadFile = menu.findItem(R.id.download_file);
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
MenuItem deleteFile = menu.findItem(R.id.delete_file);
MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
if (!treatAsFile
&& !GeoHelper.isGeoUri(m.getBody())
&& !XmppUri.isXmppUri(m.getBody())
- && m.treatAsDownloadable() != Message.Decision.MUST) {
+ && !m.treatAsDownloadable()) {
copyText.setVisible(true);
selectText.setVisible(ListSelectionManager.isSupported());
}
@@ -662,15 +661,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (m.hasFileOnRemoteHost()
|| GeoHelper.isGeoUri(m.getBody())
|| XmppUri.isXmppUri(m.getBody())
- || m.treatAsDownloadable() == Message.Decision.MUST
+ || m.treatAsDownloadable()
|| (t != null && t instanceof HttpDownloadConnection)) {
copyUrl.setVisible(true);
}
- if ((m.getType() == Message.TYPE_TEXT && t == null && m.treatAsDownloadable() != Message.Decision.NEVER)
- || (m.isFileOrImage() && t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())) {
- downloadFile.setVisible(true);
- downloadFile.setTitle(activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
- }
boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING
|| m.getStatus() == Message.STATUS_UNSEND
|| m.getStatus() == Message.STATUS_OFFERED;
@@ -712,9 +706,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
case R.id.copy_url:
copyUrl(selectedMessage);
return true;
- case R.id.download_file:
- downloadFile(selectedMessage);
- return true;
case R.id.cancel_transmission:
cancelTransmission(selectedMessage);
return true;
@@ -839,11 +830,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
}
- private void downloadFile(Message message) {
- activity.xmppConnectionService.getHttpConnectionManager()
- .createNewDownloadConnection(message, true);
- }
-
private void cancelTransmission(Message message) {
Transferable transferable = message.getTransferable();
if (transferable != null) {
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index 6143f382f..4519406f9 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -936,8 +936,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
displayHeartMessage(viewHolder, message.getBody().trim());
} else if (message.bodyIsXmpp()) {
displayXmppMessage(viewHolder, message.getBody().trim());
- } else if (message.treatAsDownloadable() == Message.Decision.MUST ||
- message.treatAsDownloadable() == Message.Decision.SHOULD) {
+ } else if (message.treatAsDownloadable()) {
try {
URL url = new URL(message.getBody());
displayDownloadableMessage(viewHolder,
diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java
index 186c45474..0f2a33d13 100644
--- a/src/main/java/de/pixart/messenger/utils/UIHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java
@@ -205,7 +205,7 @@ public class UIHelper {
} else {
return new Pair<>(context.getString(R.string.contact), true);
}
- } else if (message.treatAsDownloadable() == Message.Decision.MUST) {
+ } else if (message.treatAsDownloadable()) {
return new Pair<>(context.getString(R.string.x_file_offered_for_download,
getFileDescriptionString(context, message)), true);
} else {