rename in muc fixed

Daniel Gultsch created

Change summary

src/eu/siacs/conversations/crypto/OtrEngine.java               |  1 
src/eu/siacs/conversations/entities/MucOptions.java            | 15 ++
src/eu/siacs/conversations/services/XmppConnectionService.java | 24 ---
src/eu/siacs/conversations/ui/XmppActivity.java                | 12 +
src/eu/siacs/conversations/utils/MessageParser.java            |  7 -
5 files changed, 26 insertions(+), 33 deletions(-)

Detailed changes

src/eu/siacs/conversations/crypto/OtrEngine.java 🔗

@@ -162,6 +162,7 @@ public class OtrEngine implements OtrEngineHost {
 		privateTag.setAttribute("xmlns","urn:xmpp:carbons:2");
 		packet.addChild(privateTag);
 		packet.setType(MessagePacket.TYPE_CHAT);
+		Log.d(LOGTAG,packet.toString());
 		account.getXmppConnection().sendMessagePacket(packet);
 	}
 

src/eu/siacs/conversations/entities/MucOptions.java 🔗

@@ -76,6 +76,7 @@ public class MucOptions {
 	private boolean isOnline = false;
 	private int error = 0;
 	private OnRenameListener renameListener = null;
+	private boolean aboutToRename = false;
 	private User self = new User();
 	private String subject = null;
 
@@ -121,6 +122,7 @@ public class MucOptions {
 					Element item = packet.findChild("x").findChild("item");
 					String nick = item.getAttribute("nick");
 					if (nick!=null) {
+						aboutToRename = false;
 						if (renameListener!=null) {
 							renameListener.onRename(true);
 						}
@@ -131,7 +133,14 @@ public class MucOptions {
 			} else if (type.equals("error")) {
 				Element error = packet.findChild("error");
 				if (error.hasChild("conflict")) {
-					this.error  = ERROR_NICK_IN_USE;
+					if (aboutToRename) {
+						if (renameListener!=null) {
+							renameListener.onRename(false);
+						}
+						aboutToRename = false;
+					} else {
+						this.error  = ERROR_NICK_IN_USE;
+					}
 				}
 			}
 	}
@@ -195,4 +204,8 @@ public class MucOptions {
 	public String getSubject() {
 		return this.subject;
 	}
+
+	public void flagAboutToRename() {
+		this.aboutToRename = true;
+	}
 }

src/eu/siacs/conversations/services/XmppConnectionService.java 🔗

@@ -1035,34 +1035,14 @@ public class XmppConnectionService extends Service {
 					}
 				}
 			});
+			options.flagAboutToRename();
 			PresencePacket packet = new PresencePacket();
 			packet.setAttribute("to",
 					conversation.getContactJid().split("/")[0] + "/" + nick);
 			packet.setAttribute("from", conversation.getAccount().getFullJid());
 
 			conversation.getAccount().getXmppConnection()
-					.sendPresencePacket(packet, new OnPresencePacketReceived() {
-
-						@Override
-						public void onPresencePacketReceived(Account account,
-								PresencePacket packet) {
-							final boolean changed;
-							String type = packet.getAttribute("type");
-							changed = (!"error".equals(type));
-							if (!changed) {
-								options.getOnRenameListener().onRename(false);
-							} else {
-								if (type == null) {
-									options.getOnRenameListener()
-											.onRename(true);
-									options.setNick(packet.getAttribute("from")
-											.split("/")[1]);
-								} else {
-									options.processPacket(packet);
-								}
-							}
-						}
-					});
+					.sendPresencePacket(packet, null);
 		} else {
 			String jid = conversation.getContactJid().split("/")[0] + "/"
 					+ nick;

src/eu/siacs/conversations/ui/XmppActivity.java 🔗

@@ -43,13 +43,17 @@ public abstract class XmppActivity extends Activity {
 	protected void onStart() {
 		super.onStart();
 		if (!xmppConnectionServiceBound) {
-			Intent intent = new Intent(this, XmppConnectionService.class);
-			intent.setAction("ui");
-			startService(intent);
-			bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
+			connectToBackend();
 		}
 	}
 	
+	public void connectToBackend() {
+		Intent intent = new Intent(this, XmppConnectionService.class);
+		intent.setAction("ui");
+		startService(intent);
+		bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
+	}
+	
 	@Override
 	protected void onStop() {
 		super.onStop();

src/eu/siacs/conversations/utils/MessageParser.java 🔗

@@ -40,11 +40,7 @@ public class MessageParser {
 			String foreignPresence = conversation.getOtrSession().getSessionID().getUserID();
 			if (!foreignPresence.equals(fromParts[1])) {
 				Log.d(LOGTAG,"new otr during existing otr session requested. ending old one");
-				try {
-					conversation.getOtrSession().endSession();
-				} catch (OtrException e) {
-					Log.d("xmppService","couldnt end old session");
-				}
+				conversation.resetOtrSession();
 				Log.d("xmppService","starting new one with "+fromParts[1]);
 				conversation.startOtrSession(service.getApplicationContext(), fromParts[1]);
 			}
@@ -80,7 +76,6 @@ public class MessageParser {
 				Log.d(LOGTAG,"otr session stoped");
 			}
 		} catch (Exception e) {
-			Log.d(LOGTAG, "error receiving otr. resetting");
 			conversation.resetOtrSession();
 			return null;
 		}