diff options
Diffstat (limited to 'src/eu')
5 files changed, 51 insertions, 27 deletions
diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java index add56fb6..d04fea16 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 17537729..e341da1c 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 ff372460..b64fe5b2 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 f5996345..4381eac4 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 6e65e1ed..c426a838 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( |