rename in muc fixed

This commit is contained in:
Daniel Gultsch 2014-03-19 15:05:01 +01:00
parent 3a98a695d4
commit 389d4db311
5 changed files with 26 additions and 33 deletions

View file

@ -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);
}

View file

@ -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,10 +133,17 @@ public class MucOptions {
} else if (type.equals("error")) {
Element error = packet.findChild("error");
if (error.hasChild("conflict")) {
if (aboutToRename) {
if (renameListener!=null) {
renameListener.onRename(false);
}
aboutToRename = false;
} else {
this.error = ERROR_NICK_IN_USE;
}
}
}
}
public List<User> getUsers() {
return this.users;
@ -195,4 +204,8 @@ public class MucOptions {
public String getSubject() {
return this.subject;
}
public void flagAboutToRename() {
this.aboutToRename = true;
}
}

View file

@ -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;

View file

@ -43,12 +43,16 @@ public abstract class XmppActivity extends Activity {
protected void onStart() {
super.onStart();
if (!xmppConnectionServiceBound) {
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() {

View file

@ -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;
}