From 6f86638341ffdeb51552627a04a1372b03256042 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 4 Mar 2014 04:09:15 +0100 Subject: [PATCH] more workaroud for ejabberd bugs --- gen/eu/siacs/conversations/R.java | 45 +++++++++--------- res/layout/muc_options.xml | 2 +- .../conversations/entities/MucOptions.java | 5 -- .../services/XmppConnectionService.java | 46 +++++++++++-------- .../ui/ConversationFragment.java | 21 +++++++++ .../conversations/ui/MucOptionsActivity.java | 3 +- .../conversations/xmpp/XmppConnection.java | 3 +- 7 files changed, 74 insertions(+), 51 deletions(-) diff --git a/gen/eu/siacs/conversations/R.java b/gen/eu/siacs/conversations/R.java index 2c0562b2c..f432a8b11 100644 --- a/gen/eu/siacs/conversations/R.java +++ b/gen/eu/siacs/conversations/R.java @@ -54,25 +54,25 @@ public final class R { } public static final class id { public static final int account_confirm_password_desc=0x7f0a001c; - public static final int account_delete=0x7f0a0042; - public static final int account_disable=0x7f0a0043; - public static final int account_enable=0x7f0a0044; + public static final int account_delete=0x7f0a0041; + public static final int account_disable=0x7f0a0042; + public static final int account_enable=0x7f0a0043; public static final int account_jid=0x7f0a0000; public static final int account_list=0x7f0a002b; public static final int account_password=0x7f0a0019; public static final int account_password_confirm2=0x7f0a001d; public static final int account_status=0x7f0a0002; public static final int account_usetls=0x7f0a001a; - public static final int action_accounts=0x7f0a003c; - public static final int action_add=0x7f0a0037; - public static final int action_add_account=0x7f0a0041; - public static final int action_archive=0x7f0a003b; - public static final int action_contact_details=0x7f0a0039; - public static final int action_muc_details=0x7f0a003a; - public static final int action_refresh_contacts=0x7f0a0046; - public static final int action_security=0x7f0a0038; - public static final int action_settings=0x7f0a003d; - public static final int announce_pgp=0x7f0a0045; + public static final int action_accounts=0x7f0a003b; + public static final int action_add=0x7f0a0036; + public static final int action_add_account=0x7f0a0040; + public static final int action_archive=0x7f0a003a; + public static final int action_contact_details=0x7f0a0038; + public static final int action_muc_details=0x7f0a0039; + public static final int action_refresh_contacts=0x7f0a0045; + public static final int action_security=0x7f0a0037; + public static final int action_settings=0x7f0a003c; + public static final int announce_pgp=0x7f0a0044; public static final int contactList=0x7f0a0006; public static final int contact_display_name=0x7f0a0008; public static final int contact_jid=0x7f0a0009; @@ -90,24 +90,23 @@ public final class R { public static final int details_receive_presence=0x7f0a0014; public static final int details_send_presence=0x7f0a0013; public static final int edit_account_register_new=0x7f0a001b; - public static final int encryption_choice_none=0x7f0a003e; - public static final int encryption_choice_otr=0x7f0a003f; - public static final int encryption_choice_pgp=0x7f0a0040; - public static final int imageView1=0x7f0a0030; + public static final int encryption_choice_none=0x7f0a003d; + public static final int encryption_choice_otr=0x7f0a003e; + public static final int encryption_choice_pgp=0x7f0a003f; public static final int info_box=0x7f0a0022; public static final int list=0x7f0a0029; public static final int message_body=0x7f0a002d; public static final int message_photo=0x7f0a002c; public static final int message_time=0x7f0a002e; public static final int messages_view=0x7f0a0021; - public static final int muc_edit_nick=0x7f0a0031; + public static final int muc_edit_nick=0x7f0a0030; public static final int muc_error=0x7f0a0023; public static final int muc_error_msg=0x7f0a0024; - public static final int muc_jabberid=0x7f0a0032; - public static final int muc_members=0x7f0a0036; - public static final int muc_more_details=0x7f0a0033; - public static final int muc_participants_header=0x7f0a0035; - public static final int muc_role=0x7f0a0034; + public static final int muc_jabberid=0x7f0a0031; + public static final int muc_members=0x7f0a0035; + public static final int muc_more_details=0x7f0a0032; + public static final int muc_participants_header=0x7f0a0034; + public static final int muc_role=0x7f0a0033; public static final int muc_your_nick=0x7f0a002f; public static final int new_conversation_search=0x7f0a0004; public static final int new_fingerprint=0x7f0a0025; diff --git a/res/layout/muc_options.xml b/res/layout/muc_options.xml index a4e142c27..fd5583cfe 100644 --- a/res/layout/muc_options.xml +++ b/res/layout/muc_options.xml @@ -28,7 +28,7 @@ android:layout_width="wrap_content" android:layout_height="48dp" android:layout_alignParentLeft="true" - android:layout_toLeftOf="@+id/imageView1" + android:layout_toLeftOf="@+id/muc_edit_nick" android:background="#eee" android:ems="10" android:hint="Search or enter Jabber ID" diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java index add56fb66..d04fea160 100644 --- a/src/eu/siacs/conversations/entities/MucOptions.java +++ b/src/eu/siacs/conversations/entities/MucOptions.java @@ -99,7 +99,6 @@ public class MucOptions { } public void processPacket(PresencePacket packet) { - Log.d("xmppService","process Packet for muc options: "+packet.toString()); String name = packet.getAttribute("from").split("/")[1]; String type = packet.getAttribute("type"); if (type==null) { @@ -109,8 +108,6 @@ public class MucOptions { user.setAffiliation(item.getAttribute("affiliation")); user.setRole(item.getAttribute("role")); user.setName(name); - Log.d("xmppService","nick: "+getNick()); - Log.d("xmppService","name: "+name); if (name.equals(getNick())) { this.isOnline = true; this.error = 0; @@ -119,10 +116,8 @@ public class MucOptions { addUser(user); } } else if (type.equals("unavailable")) { - Log.d("xmppService","name: "+name); if (name.equals(getNick())) { Element item = packet.findChild("x").findChild("item"); - Log.d("xmppService","nick equals name"); String nick = item.getAttribute("nick"); if (nick!=null) { if (renameListener!=null) { diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 175377294..e341da1ce 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -192,12 +192,13 @@ public class XmppConnectionService extends Service { @Override public void onPresencePacketReceived(Account account, PresencePacket packet) { - Log.d(LOGTAG, packet.toString()); if (packet.hasChild("x")&&(packet.findChild("x").getAttribute("xmlns").startsWith("http://jabber.org/protocol/muc"))) { Conversation muc = findMuc(packet.getAttribute("from").split("/")[0]); + int error = muc.getMucOptions().getError(); if (muc!=null) { muc.getMucOptions().processPacket(packet); - if (convChangedListener!=null) { + if ((muc.getMucOptions().getError()!=error)&&(convChangedListener!=null)) { + Log.d(LOGTAG,"muc error status changed"); convChangedListener.onConversationListChanged(); } } @@ -846,30 +847,31 @@ public class XmppConnectionService extends Service { .sendPresencePacket(packet); } - public void renameInMuc(final Conversation conversation, final String nick, final XmppActivity activity) { + private OnRenameListener renameListener = null; + public void setOnRenameListener(OnRenameListener listener) { + this.renameListener = listener; + } + + public void renameInMuc(final Conversation conversation, final String nick) { final MucOptions options = conversation.getMucOptions(); if (options.online()) { options.setOnRenameListener(new OnRenameListener() { @Override - public void onRename(final boolean success) { - activity.runOnUiThread(new Runnable() { - - @Override - public void run() { - if (success) { - databaseBackend.updateConversation(conversation); - Toast.makeText(activity, "Your nickname has been changed", Toast.LENGTH_SHORT).show(); - } else { - Toast.makeText(activity, "Nickname already in use",Toast.LENGTH_SHORT).show(); - } - } - }); + public void onRename(boolean success) { + if (renameListener!=null) { + renameListener.onRename(success); + } + if (success) { + databaseBackend.updateConversation(conversation); + } } }); PresencePacket packet = new PresencePacket(); packet.setAttribute("to", conversation.getContactJid().split("/")[0]+"/"+nick); - conversation.getAccount().getXmppConnection().sendPresencePacket(packet, new OnPresencePacketReceived() { + packet.setAttribute("from", conversation.getAccount().getFullJid()); + + packet = conversation.getAccount().getXmppConnection().sendPresencePacket(packet, new OnPresencePacketReceived() { @Override public void onPresencePacketReceived(Account account, PresencePacket packet) { @@ -877,9 +879,15 @@ public class XmppConnectionService extends Service { String type = packet.getAttribute("type"); changed = (!"error".equals(type)); if (!changed) { - options.getOnRenameListener().onRename(changed); + options.getOnRenameListener().onRename(false); + } else { + if (type==null) { + options.getOnRenameListener().onRename(true); + options.setNick(packet.getAttribute("from").split("/")[1]); + } else { + options.processPacket(packet); + } } - options.processPacket(packet); } }); } else { diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index ff3724601..b64fe5b2b 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -18,6 +18,7 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions; +import eu.siacs.conversations.entities.MucOptions.OnRenameListener; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.utils.UIHelper; @@ -49,6 +50,7 @@ import android.widget.ListView; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; public class ConversationFragment extends Fragment { @@ -351,6 +353,25 @@ public class ConversationFragment extends Fragment { Message.ENCRYPTION_PGP); sendPgpMessage(message); } + if (conversation.getMode() == Conversation.MODE_MULTI) { + activity.xmppConnectionService.setOnRenameListener(new OnRenameListener() { + + @Override + public void onRename(final boolean success) { + getActivity().runOnUiThread(new Runnable() { + + @Override + public void run() { + if (success) { + Toast.makeText(getActivity(), "Your nickname has been changed",Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(getActivity(), "Nichname is already in use",Toast.LENGTH_SHORT).show(); + } + } + }); + } + }); + } } public void updateMessages() { diff --git a/src/eu/siacs/conversations/ui/MucOptionsActivity.java b/src/eu/siacs/conversations/ui/MucOptionsActivity.java index f59963453..4381eac4c 100644 --- a/src/eu/siacs/conversations/ui/MucOptionsActivity.java +++ b/src/eu/siacs/conversations/ui/MucOptionsActivity.java @@ -20,7 +20,6 @@ import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.ListView; import android.widget.TextView; public class MucOptionsActivity extends XmppActivity { @@ -44,7 +43,7 @@ public class MucOptionsActivity extends XmppActivity { String nick = mYourNick.getText().toString(); if (!options.getNick().equals(nick)) { Log.d("gultsch","call to change muc"); - xmppConnectionService.renameInMuc(conversation, nick, activity); + xmppConnectionService.renameInMuc(conversation, nick); finish(); } } diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 6e65e1ed0..c426a8381 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -442,13 +442,14 @@ public class XmppConnection implements Runnable { this.sendPresencePacket(packet, null); } - public void sendPresencePacket(PresencePacket packet, OnPresencePacketReceived callback) { + public PresencePacket sendPresencePacket(PresencePacket packet, OnPresencePacketReceived callback) { String id = nextRandomId(); packet.setAttribute("id", id); tagWriter.writeElement(packet); if (callback != null) { packetCallbacks.put(id, callback); } + return packet; } public void setOnMessagePacketReceivedListener(