diff options
Diffstat (limited to 'src/main/java')
5 files changed, 47 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/PgpEngine.java b/src/main/java/de/pixart/messenger/crypto/PgpEngine.java index 3be5ceb23..7fb474429 100644 --- a/src/main/java/de/pixart/messenger/crypto/PgpEngine.java +++ b/src/main/java/de/pixart/messenger/crypto/PgpEngine.java @@ -2,6 +2,7 @@ package de.pixart.messenger.crypto; import android.app.PendingIntent; import android.content.Intent; +import android.support.annotation.StringRes; import android.util.Log; import org.openintents.openpgp.OpenPgpError; @@ -39,7 +40,8 @@ public class PgpEngine { private static void logError(Account account, OpenPgpError error) { if (error != null) { - Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error '" + error.getMessage() + "' code=" + error.getErrorId()); + error.describeContents(); + Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error '" + error.getMessage() + "' code=" + error.getErrorId() + " class=" + error.getClass().getName()); } else { Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error with no message"); } @@ -93,8 +95,16 @@ public class PgpEngine { callback.userInputRequried(result.getParcelableExtra(OpenPgpApi.RESULT_INTENT), message); break; case OpenPgpApi.RESULT_CODE_ERROR: - logError(conversation.getAccount(), result.getParcelableExtra(OpenPgpApi.RESULT_ERROR)); - callback.error(R.string.openpgp_error, message); + OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR); + String errorMessage = error != null ? error.getMessage() : null; + @StringRes final int res; + if (errorMessage != null && errorMessage.startsWith("Bad key for encryption")) { + res = R.string.bad_key_for_encryption; + } else { + res = R.string.openpgp_error; + } + logError(conversation.getAccount(), error); + callback.error(res, message); break; } }); @@ -173,7 +183,7 @@ public class PgpEngine { case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: return 0; case OpenPgpApi.RESULT_CODE_ERROR: - logError(account, (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR)); + logError(account, result.getParcelableExtra(OpenPgpApi.RESULT_ERROR)); return 0; } return 0; diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index c60e652bb..3d19e05c7 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -101,7 +101,7 @@ public class NotificationService { } public static Pattern generateNickHighlightPattern(final String nick) { - return Pattern.compile("(?<=(^|\\s))" + Pattern.quote(nick) + "\\b"); + return Pattern.compile("(?<=(^|\\s))" + Pattern.quote(nick) + "(?=\\s|$|\\p{Punct})"); } @RequiresApi(api = Build.VERSION_CODES.O) diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index e8b3caa3a..45929344c 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -2802,7 +2802,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke public void error(final int error, Message message) { getActivity().runOnUiThread(() -> { doneSendingPgpMessage(); - Toast.makeText(getActivity(), R.string.unable_to_connect_to_keychain, Toast.LENGTH_SHORT).show(); + Toast.makeText(getActivity(), error == 0 ? R.string.unable_to_connect_to_keychain : error, Toast.LENGTH_SHORT).show(); }); } diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 9d5bd279b..775e8f6dc 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -41,6 +41,7 @@ import org.openintents.openpgp.util.OpenPgpUtils; import java.net.URL; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -53,6 +54,7 @@ import de.pixart.messenger.databinding.DialogPresenceBinding; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Presence; import de.pixart.messenger.entities.PresenceTemplate; +import de.pixart.messenger.entities.ServiceDiscoveryResult; import de.pixart.messenger.services.BarcodeProvider; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.services.XmppConnectionService.OnAccountUpdate; @@ -63,6 +65,7 @@ import de.pixart.messenger.ui.util.PendingItem; import de.pixart.messenger.ui.util.SoftKeyboardUtils; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.MenuDoubleTabUtil; +import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xml.Element; @@ -1053,7 +1056,11 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.binding.serverInfoPep.setText(R.string.server_info_unavailable); } if (features.httpUpload(0)) { - this.binding.serverInfoHttpUpload.setText(R.string.server_info_available); + if (getHttpUploadMaxFileSize().equals("0")) { + this.binding.serverInfoHttpUpload.setText(R.string.server_info_available); + } else { + this.binding.serverInfoHttpUpload.setText(getString(R.string.server_info_available_with, getHttpUploadMaxFileSize())); + } } else if (features.p1S3FileTransfer()) { this.binding.serverInfoHttpUploadDescription.setText(R.string.p1_s3_filetransfer); this.binding.serverInfoHttpUpload.setText(R.string.server_info_available); @@ -1163,6 +1170,28 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } } + private String getHttpUploadMaxFileSize() { + XmppConnection connection = mAccount.getXmppConnection(); + for (String namespace : new String[]{Namespace.HTTP_UPLOAD, Namespace.HTTP_UPLOAD_LEGACY}) { + List<Map.Entry<Jid, ServiceDiscoveryResult>> items = connection.findDiscoItemsByFeature(namespace); + if (items.size() > 0) { + try { + long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(namespace, "max-file-size")); + if (maxsize > (1 * 1024 * 1024)) { + return Math.round(maxsize * 1f / (1024 * 1024)) + " MiB"; + } else if (maxsize >= (1 * 1024)) { + return Math.round(maxsize * 1f / 1024) + " KiB"; + } else if (maxsize > 0){ + return maxsize + " B"; + } + } catch (Exception e) { + return "0"; + } + } + } + return "0"; + } + private void removeErrorsOnAllBut(TextInputLayout exception) { if (this.binding.accountJidLayout != exception) { this.binding.accountJidLayout.setErrorEnabled(false); diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index eed687222..a40670c55 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -1516,7 +1516,7 @@ public class XmppConnection implements Runnable { this.streamId = null; } - private List<Entry<Jid, ServiceDiscoveryResult>> findDiscoItemsByFeature(final String feature) { + public List<Entry<Jid, ServiceDiscoveryResult>> findDiscoItemsByFeature(final String feature) { synchronized (this.disco) { final List<Entry<Jid, ServiceDiscoveryResult>> items = new ArrayList<>(); for (final Entry<Jid, ServiceDiscoveryResult> cursor : this.disco.entrySet()) { |