diff options
Diffstat (limited to 'src/main/java/eu/siacs')
5 files changed, 59 insertions, 32 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index c73a05647..d6e580dff 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -606,15 +606,19 @@ public class DatabaseBackend extends SQLiteOpenHelper { } public Pair<Long, String> getLastMessageReceived(Account account) { - SQLiteDatabase db = this.getReadableDatabase(); - String sql = "select messages.timeSent,messages.serverMsgId from accounts join conversations on accounts.uuid=conversations.accountUuid join messages on conversations.uuid=messages.conversationUuid where accounts.uuid=? and (messages.status=0 or messages.carbon=1 or messages.serverMsgId not null) order by messages.timesent desc limit 1"; - String[] args = {account.getUuid()}; - Cursor cursor = db.rawQuery(sql, args); - if (cursor.getCount() == 0) { + try { + SQLiteDatabase db = this.getReadableDatabase(); + String sql = "select messages.timeSent,messages.serverMsgId from accounts join conversations on accounts.uuid=conversations.accountUuid join messages on conversations.uuid=messages.conversationUuid where accounts.uuid=? and (messages.status=0 or messages.carbon=1 or messages.serverMsgId not null) order by messages.timesent desc limit 1"; + String[] args = {account.getUuid()}; + Cursor cursor = db.rawQuery(sql, args); + if (cursor.getCount() == 0) { + return null; + } else { + cursor.moveToFirst(); + return new Pair<>(cursor.getLong(0), cursor.getString(1)); + } + } catch (Exception e) { return null; - } else { - cursor.moveToFirst(); - return new Pair<>(cursor.getLong(0), cursor.getString(1)); } } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index e707fc985..6e3e626a5 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2478,7 +2478,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa Thread thread = new Thread(account.getXmppConnection()); account.getXmppConnection().setInteractive(interactive); thread.start(); - scheduleWakeUpCall(Config.CONNECT_TIMEOUT, account.getUuid().hashCode()); + scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode()); } else { account.getRoster().clearPresences(); account.setXmppConnection(null); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 1237b1db1..8fb5680d2 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -117,8 +117,6 @@ public class ConversationActivity extends XmppActivity private ArrayAdapter<Conversation> listAdapter; - private Toast prepareFileToast; - private boolean mActivityPaused = false; private AtomicBoolean mRedirected = new AtomicBoolean(false); private Pair<Integer, Intent> mPostponedActivityResult; @@ -1313,6 +1311,9 @@ public class ConversationActivity extends XmppActivity @SuppressLint("NewApi") private static List<Uri> extractUriFromIntent(final Intent intent) { List<Uri> uris = new ArrayList<>(); + if (intent == null) { + return uris; + } Uri uri = intent.getData(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) { ClipData clipData = intent.getClipData(); @@ -1460,17 +1461,18 @@ public class ConversationActivity extends XmppActivity if (conversation == null) { return; } - prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG); + final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG); prepareFileToast.show(); xmppConnectionService.attachFileToConversation(conversation, uri, new UiCallback<Message>() { @Override public void success(Message message) { - hidePrepareFileToast(); + hidePrepareFileToast(prepareFileToast); xmppConnectionService.sendMessage(message); } @Override public void error(int errorCode, Message message) { + hidePrepareFileToast(prepareFileToast); displayErrorDialog(errorCode); } @@ -1485,32 +1487,31 @@ public class ConversationActivity extends XmppActivity if (conversation == null) { return; } - prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_image), Toast.LENGTH_LONG); + final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_image), Toast.LENGTH_LONG); prepareFileToast.show(); xmppConnectionService.attachImageToConversation(conversation, uri, new UiCallback<Message>() { @Override - public void userInputRequried(PendingIntent pi, - Message object) { - hidePrepareFileToast(); + public void userInputRequried(PendingIntent pi, Message object) { + hidePrepareFileToast(prepareFileToast); } @Override public void success(Message message) { - hidePrepareFileToast(); + hidePrepareFileToast(prepareFileToast); xmppConnectionService.sendMessage(message); } @Override public void error(int error, Message message) { - hidePrepareFileToast(); + hidePrepareFileToast(prepareFileToast); displayErrorDialog(error); } }); } - private void hidePrepareFileToast() { + private void hidePrepareFileToast(final Toast prepareFileToast) { if (prepareFileToast != null) { runOnUiThread(new Runnable() { diff --git a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java index d76d9caea..0f66de176 100644 --- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java @@ -187,6 +187,13 @@ public class PublishProfilePictureActivity extends XmppActivity { loadImageIntoPreview(this.avatarUri); break; } + } else { + if (requestCode == Crop.REQUEST_CROP) { + Throwable throwable = Crop.getError(data); + if (throwable != null && throwable instanceof OutOfMemoryError) { + Toast.makeText(this,R.string.selection_too_large, Toast.LENGTH_SHORT).show(); + } + } } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index a56a64aff..cf3962776 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -226,8 +226,16 @@ public class XmppConnection implements Runnable { lastPingSent = SystemClock.elapsedRealtime(); lastDiscoStarted = Long.MAX_VALUE; this.attempt++; - if (account.getJid().getDomainpart().equals("chat.facebook.com")) { - mServerIdentity = Identity.FACEBOOK; + switch (account.getJid().getDomainpart()) { + case "chat.facebook.com": + mServerIdentity = Identity.FACEBOOK; + break; + case "nimbuzz.com": + mServerIdentity = Identity.NIMBUZZ; + break; + default: + mServerIdentity = Identity.UNKNOWN; + break; } try { shouldAuthenticate = needsBinding = !account.isOptionSet(Account.OPTION_REGISTER); @@ -718,10 +726,12 @@ public class XmppConnection implements Runnable { this.streamFeatures = tagReader.readElement(currentTag); if (this.streamFeatures.hasChild("starttls") && !features.encryptionEnabled) { sendStartTLS(); - } else if (this.streamFeatures.hasChild("register") - && account.isOptionSet(Account.OPTION_REGISTER) - && features.encryptionEnabled) { - sendRegistryRequest(); + } else if (this.streamFeatures.hasChild("register") && account.isOptionSet(Account.OPTION_REGISTER)) { + if (features.encryptionEnabled) { + sendRegistryRequest(); + } else { + throw new IncompatibleServerException(); + } } else if (!this.streamFeatures.hasChild("register") && account.isOptionSet(Account.OPTION_REGISTER)) { changeStatus(Account.State.REGISTRATION_NOT_SUPPORTED); @@ -987,7 +997,7 @@ public class XmppConnection implements Runnable { synchronized (this.disco) { this.disco.clear(); } - mPendingServiceDiscoveries = 0; + mPendingServiceDiscoveries = mServerIdentity == Identity.NIMBUZZ ? 1 : 0; lastDiscoStarted = SystemClock.elapsedRealtime(); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": starting service discovery"); mXmppConnectionService.scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode()); @@ -998,7 +1008,9 @@ public class XmppConnection implements Runnable { } private void sendServiceDiscoveryInfo(final Jid jid) { - mPendingServiceDiscoveries++; + if (mServerIdentity != Identity.NIMBUZZ) { + mPendingServiceDiscoveries++; + } final IqPacket iq = new IqPacket(IqPacket.TYPE.GET); iq.setTo(jid); iq.query("http://jabber.org/protocol/disco#info"); @@ -1007,7 +1019,7 @@ public class XmppConnection implements Runnable { @Override public void onIqPacketReceived(final Account account, final IqPacket packet) { if (packet.getType() == IqPacket.TYPE.RESULT) { - boolean advancedStreamFeaturesLoaded = false; + boolean advancedStreamFeaturesLoaded; synchronized (XmppConnection.this.disco) { final List<Element> elements = packet.query().getChildren(); final Info info = new Info(); @@ -1018,7 +1030,9 @@ public class XmppConnection implements Runnable { String name = element.getAttribute("name"); if (type != null && category != null) { info.identities.add(new Pair<>(category, type)); - if (type.equals("im") && category.equals("server")) { + if (mServerIdentity == Identity.UNKNOWN + && type.equals("im") + && category.equals("server")) { if (name != null && jid.equals(account.getServer())) { switch (name) { case "Prosody": @@ -1051,8 +1065,8 @@ public class XmppConnection implements Runnable { } if (packet.getType() != IqPacket.TYPE.TIMEOUT) { mPendingServiceDiscoveries--; - if (mPendingServiceDiscoveries <= 0) { - Log.d(Config.LOGTAG, account.getJid().toBareJid()+": done with service discovery"); + if (mPendingServiceDiscoveries == 0) { + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": done with service discovery"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": online with resource " + account.getResource()); changeStatus(Account.State.ONLINE); if (bindListener != null) { @@ -1409,6 +1423,7 @@ public class XmppConnection implements Runnable { SLACK, EJABBERD, PROSODY, + NIMBUZZ, UNKNOWN } |