Merge branch 'trz/rebase' into trz/merge_1.11.1
This commit is contained in:
commit
c9b7ed3d3f
7 changed files with 96 additions and 38 deletions
|
@ -0,0 +1,20 @@
|
||||||
|
package de.thedevstack.conversationsplus.exceptions;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by lookshe on 15.03.16.
|
||||||
|
*
|
||||||
|
* Exception class if HTTP status code 404 occured
|
||||||
|
*/
|
||||||
|
public class RemoteFileNotFoundException extends IOException {
|
||||||
|
private static final long serialVersionUID = -1010013599132881427L;
|
||||||
|
|
||||||
|
public RemoteFileNotFoundException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RemoteFileNotFoundException(Throwable e) {
|
||||||
|
super(e);
|
||||||
|
}
|
||||||
|
}
|
|
@ -81,6 +81,7 @@ public class Message extends AbstractEntity {
|
||||||
private Message mNextMessage = null;
|
private Message mNextMessage = null;
|
||||||
private Message mPreviousMessage = null;
|
private Message mPreviousMessage = null;
|
||||||
private String axolotlFingerprint = null;
|
private String axolotlFingerprint = null;
|
||||||
|
private Decision mTreatAsDownloadAble = Decision.NOT_DECIDED;
|
||||||
|
|
||||||
private Message() {
|
private Message() {
|
||||||
|
|
||||||
|
@ -467,6 +468,7 @@ public class Message extends AbstractEntity {
|
||||||
MUST,
|
MUST,
|
||||||
SHOULD,
|
SHOULD,
|
||||||
NEVER,
|
NEVER,
|
||||||
|
NOT_DECIDED,
|
||||||
}
|
}
|
||||||
|
|
||||||
private String extractRelevantExtension(URL url) {
|
private String extractRelevantExtension(URL url) {
|
||||||
|
@ -515,44 +517,64 @@ public class Message extends AbstractEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* in case of later found error with decision, set it to a value which does not affect anything, hopefully
|
||||||
|
*/
|
||||||
|
public void setNoDownloadable() {
|
||||||
|
mTreatAsDownloadAble = Decision.NEVER;
|
||||||
|
}
|
||||||
|
|
||||||
public Decision treatAsDownloadable() {
|
public Decision treatAsDownloadable() {
|
||||||
|
// only test this ones, body will not change
|
||||||
|
if (mTreatAsDownloadAble != Decision.NOT_DECIDED) {
|
||||||
|
return mTreatAsDownloadAble;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* there are a few cases where spaces result in an unwanted behavior, e.g.
|
* there are a few cases where spaces result in an unwanted behavior, e.g.
|
||||||
* "http://example.com/image.jpg" text that will not be shown /abc.png"
|
* "http://example.com/image.jpg" text that will not be shown /abc.png"
|
||||||
* or more than one image link in one message.
|
* or more than one image link in one message.
|
||||||
*/
|
*/
|
||||||
if (getBody().contains(" ")) {
|
if (getBody().contains(" ")) {
|
||||||
return Decision.NEVER;
|
mTreatAsDownloadAble = Decision.NEVER;
|
||||||
|
return mTreatAsDownloadAble;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
URL url = new URL(body);
|
URL url = new URL(body);
|
||||||
if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
|
if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
|
||||||
return Decision.NEVER;
|
mTreatAsDownloadAble = Decision.NEVER;
|
||||||
|
return mTreatAsDownloadAble;
|
||||||
} else if (oob) {
|
} else if (oob) {
|
||||||
return Decision.MUST;
|
mTreatAsDownloadAble = Decision.MUST;
|
||||||
|
return mTreatAsDownloadAble;
|
||||||
}
|
}
|
||||||
String extension = extractRelevantExtension(url);
|
String extension = extractRelevantExtension(url);
|
||||||
if (extension == null) {
|
if (extension == null) {
|
||||||
return Decision.NEVER;
|
mTreatAsDownloadAble = Decision.NEVER;
|
||||||
|
return mTreatAsDownloadAble;
|
||||||
}
|
}
|
||||||
String ref = url.getRef();
|
String ref = url.getRef();
|
||||||
boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}");
|
boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}");
|
||||||
|
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
if (MimeUtils.guessMimeTypeFromExtension(extension) != null) {
|
if (MimeUtils.guessMimeTypeFromExtension(extension) != null) {
|
||||||
return Decision.MUST;
|
mTreatAsDownloadAble = Decision.MUST;
|
||||||
|
return mTreatAsDownloadAble;
|
||||||
} else {
|
} else {
|
||||||
return Decision.NEVER;
|
mTreatAsDownloadAble = Decision.NEVER;
|
||||||
|
return mTreatAsDownloadAble;
|
||||||
}
|
}
|
||||||
} else if (Transferable.VALID_IMAGE_EXTENSIONS.contains(extension)
|
} else if (Transferable.VALID_IMAGE_EXTENSIONS.contains(extension)
|
||||||
|| Transferable.WELL_KNOWN_EXTENSIONS.contains(extension)) {
|
|| Transferable.WELL_KNOWN_EXTENSIONS.contains(extension)) {
|
||||||
return Decision.SHOULD;
|
mTreatAsDownloadAble = Decision.SHOULD;
|
||||||
|
return mTreatAsDownloadAble;
|
||||||
} else {
|
} else {
|
||||||
return Decision.NEVER;
|
mTreatAsDownloadAble = Decision.NEVER;
|
||||||
|
return mTreatAsDownloadAble;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
return Decision.NEVER;
|
mTreatAsDownloadAble = Decision.NEVER;
|
||||||
|
return mTreatAsDownloadAble;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.Proxy;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
@ -24,6 +20,7 @@ import javax.net.ssl.SSLHandshakeException;
|
||||||
import de.thedevstack.android.logcat.Logging;
|
import de.thedevstack.android.logcat.Logging;
|
||||||
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
|
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
|
||||||
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
|
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
|
||||||
|
import de.thedevstack.conversationsplus.exceptions.RemoteFileNotFoundException;
|
||||||
import de.thedevstack.conversationsplus.utils.MessageUtil;
|
import de.thedevstack.conversationsplus.utils.MessageUtil;
|
||||||
import de.thedevstack.conversationsplus.utils.StreamUtil;
|
import de.thedevstack.conversationsplus.utils.StreamUtil;
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
|
@ -181,6 +178,10 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
HttpDownloadConnection.this.acceptedAutomatically = false;
|
HttpDownloadConnection.this.acceptedAutomatically = false;
|
||||||
HttpDownloadConnection.this.mXmppConnectionService.getNotificationService().push(message);
|
HttpDownloadConnection.this.mXmppConnectionService.getNotificationService().push(message);
|
||||||
return;
|
return;
|
||||||
|
} catch (RemoteFileNotFoundException e) {
|
||||||
|
message.setNoDownloadable();
|
||||||
|
cancel();
|
||||||
|
return;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(Config.LOGTAG, "io exception in http file size checker: " + e.getMessage());
|
Log.d(Config.LOGTAG, "io exception in http file size checker: " + e.getMessage());
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
|
@ -205,23 +206,31 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
|
|
||||||
private long retrieveFileSize() throws IOException {
|
private long retrieveFileSize() throws IOException {
|
||||||
try {
|
try {
|
||||||
Logging.d(Config.LOGTAG, "retrieve file size. interactive:" + String.valueOf(interactive));
|
Logging.d(Config.LOGTAG, "retrieve file size. interactive:" + String.valueOf(interactive));
|
||||||
changeStatus(STATUS_CHECKING);
|
changeStatus(STATUS_CHECKING);
|
||||||
HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection();
|
||||||
connection.setRequestMethod("HEAD");
|
connection.setRequestMethod("HEAD");
|
||||||
Logging.d(Config.LOGTAG, "url: "+connection.getURL().toString());
|
Logging.d(Config.LOGTAG, "url: " + connection.getURL().toString());
|
||||||
Logging.d(Config.LOGTAG, "connection: "+connection.toString());
|
Logging.d(Config.LOGTAG, "connection: " + connection.toString());
|
||||||
connection.setRequestProperty("User-Agent", ConversationsPlusApplication.getNameAndVersion());
|
connection.setRequestProperty("User-Agent", ConversationsPlusApplication.getNameAndVersion());
|
||||||
if (connection instanceof HttpsURLConnection) {
|
// https://code.google.com/p/android/issues/detail?id=24672
|
||||||
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
|
connection.setRequestProperty("Accept-Encoding", "");
|
||||||
}
|
if (connection instanceof HttpsURLConnection) {
|
||||||
connection.connect();
|
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
|
||||||
String contentLength = connection.getHeaderField("Content-Length");
|
}
|
||||||
connection.disconnect();
|
connection.connect();
|
||||||
if (contentLength == null) {
|
if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||||
return -1;
|
Logging.d(Config.LOGTAG, "remote file not found");
|
||||||
}
|
throw new RemoteFileNotFoundException();
|
||||||
return Long.parseLong(contentLength, 10);
|
}
|
||||||
|
String contentLength = connection.getHeaderField("Content-Length");
|
||||||
|
connection.disconnect();
|
||||||
|
if (contentLength == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return Long.parseLong(contentLength, 10);
|
||||||
|
} catch (RemoteFileNotFoundException e) {
|
||||||
|
throw e;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return -1;
|
return -1;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
|
|
@ -432,7 +432,10 @@ public class MessageParser extends AbstractParser implements
|
||||||
account.activateGracePeriod();
|
account.activateGracePeriod();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message.markUnread();
|
// only not mam messages should be marked as unread
|
||||||
|
if (query == null) {
|
||||||
|
message.markUnread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,17 +457,20 @@ public class MessageParser extends AbstractParser implements
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_NONE || !ConversationsPlusPreferences.dontSaveEncrypted()) {
|
if (message.getEncryption() == Message.ENCRYPTION_NONE || !ConversationsPlusPreferences.dontSaveEncrypted()) {
|
||||||
mXmppConnectionService.databaseBackend.createMessage(message);
|
mXmppConnectionService.databaseBackend.createMessage(message);
|
||||||
}
|
}
|
||||||
final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager();
|
|
||||||
if (message.trusted()
|
if (message.trusted()
|
||||||
&& message.treatAsDownloadable() != Message.Decision.NEVER
|
&& message.treatAsDownloadable() != Message.Decision.NEVER
|
||||||
&& ConversationsPlusPreferences.autoAcceptFileSize() > 0
|
&& ConversationsPlusPreferences.autoAcceptFileSize() > 0
|
||||||
&& ConversationsPlusPreferences.autoDownloadFileLink()) {
|
&& ConversationsPlusPreferences.autoDownloadFileLink()) {
|
||||||
manager.createNewDownloadConnection(message);
|
this.mXmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message);
|
||||||
} else {
|
} else {
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
mXmppConnectionService.getNotificationService().push(message);
|
mXmppConnectionService.getNotificationService().push(message);
|
||||||
} else if (query.getWith() == null) { // mam catchup
|
} else if (query.getWith() == null) { // mam catchup
|
||||||
mXmppConnectionService.getNotificationService().pushFromBacklog(message);
|
/*
|
||||||
|
Like suggested in https://bugs.thedevstack.de/task/156 user should be notified
|
||||||
|
in some other way of loaded messages.
|
||||||
|
*/
|
||||||
|
// mXmppConnectionService.getNotificationService().pushFromBacklog(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!packet.hasChild("body")){ //no body
|
} else if (!packet.hasChild("body")){ //no body
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class FileBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DownloadableFile compressImageAndCopyToPrivateStorage(Message message, Bitmap scaledBitmap) throws FileCopyException {
|
public static DownloadableFile compressImageAndCopyToPrivateStorage(Message message, Bitmap scaledBitmap) throws FileCopyException {
|
||||||
message.setRelativeFilePath(FileBackend.getPrivateImageDirectoryPath() + message.getUuid() + ".png");
|
message.setRelativeFilePath(FileBackend.getPrivateImageDirectoryPath() + message.getUuid() + ".jpg");
|
||||||
DownloadableFile file = getFile(message);
|
DownloadableFile file = getFile(message);
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
OutputStream os = null;
|
OutputStream os = null;
|
||||||
|
@ -118,7 +118,7 @@ public class FileBackend {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
os = new FileOutputStream(file);
|
os = new FileOutputStream(file);
|
||||||
|
|
||||||
boolean success = scaledBitmap.compress(Bitmap.CompressFormat.PNG, 75, os);
|
boolean success = scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 75, os);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw new FileCopyException(R.string.error_compressing_image);
|
throw new FileCopyException(R.string.error_compressing_image);
|
||||||
}
|
}
|
||||||
|
|
|
@ -568,7 +568,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||||
copyUrl.setVisible(true);
|
copyUrl.setVisible(true);
|
||||||
}
|
}
|
||||||
if ((m.getType() == Message.TYPE_TEXT && t == null && m.treatAsDownloadable() != Message.Decision.NEVER)
|
if ((m.getType() == Message.TYPE_TEXT && t == null && m.treatAsDownloadable() != Message.Decision.NEVER)
|
||||||
|| (m.isFileOrImage() && t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())){
|
|| (t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())){
|
||||||
downloadFile.setVisible(true);
|
downloadFile.setVisible(true);
|
||||||
downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
|
downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
|
android:visibility="gone"
|
||||||
app:riv_corner_radius="2dp" />
|
app:riv_corner_radius="2dp" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -26,7 +27,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_toLeftOf="@+id/message_photo"
|
android:layout_alignParentRight="true"
|
||||||
android:background="@drawable/message_bubble_sent"
|
android:background="@drawable/message_bubble_sent"
|
||||||
android:minHeight="53dp"
|
android:minHeight="53dp"
|
||||||
android:layout_marginLeft="-4dp"
|
android:layout_marginLeft="-4dp"
|
||||||
|
|
Loading…
Reference in a new issue