rename in muc fixed
This commit is contained in:
parent
3a98a695d4
commit
389d4db311
|
@ -162,6 +162,7 @@ public class OtrEngine implements OtrEngineHost {
|
||||||
privateTag.setAttribute("xmlns","urn:xmpp:carbons:2");
|
privateTag.setAttribute("xmlns","urn:xmpp:carbons:2");
|
||||||
packet.addChild(privateTag);
|
packet.addChild(privateTag);
|
||||||
packet.setType(MessagePacket.TYPE_CHAT);
|
packet.setType(MessagePacket.TYPE_CHAT);
|
||||||
|
Log.d(LOGTAG,packet.toString());
|
||||||
account.getXmppConnection().sendMessagePacket(packet);
|
account.getXmppConnection().sendMessagePacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@ public class MucOptions {
|
||||||
private boolean isOnline = false;
|
private boolean isOnline = false;
|
||||||
private int error = 0;
|
private int error = 0;
|
||||||
private OnRenameListener renameListener = null;
|
private OnRenameListener renameListener = null;
|
||||||
|
private boolean aboutToRename = false;
|
||||||
private User self = new User();
|
private User self = new User();
|
||||||
private String subject = null;
|
private String subject = null;
|
||||||
|
|
||||||
|
@ -121,6 +122,7 @@ public class MucOptions {
|
||||||
Element item = packet.findChild("x").findChild("item");
|
Element item = packet.findChild("x").findChild("item");
|
||||||
String nick = item.getAttribute("nick");
|
String nick = item.getAttribute("nick");
|
||||||
if (nick!=null) {
|
if (nick!=null) {
|
||||||
|
aboutToRename = false;
|
||||||
if (renameListener!=null) {
|
if (renameListener!=null) {
|
||||||
renameListener.onRename(true);
|
renameListener.onRename(true);
|
||||||
}
|
}
|
||||||
|
@ -131,10 +133,17 @@ public class MucOptions {
|
||||||
} else if (type.equals("error")) {
|
} else if (type.equals("error")) {
|
||||||
Element error = packet.findChild("error");
|
Element error = packet.findChild("error");
|
||||||
if (error.hasChild("conflict")) {
|
if (error.hasChild("conflict")) {
|
||||||
|
if (aboutToRename) {
|
||||||
|
if (renameListener!=null) {
|
||||||
|
renameListener.onRename(false);
|
||||||
|
}
|
||||||
|
aboutToRename = false;
|
||||||
|
} else {
|
||||||
this.error = ERROR_NICK_IN_USE;
|
this.error = ERROR_NICK_IN_USE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<User> getUsers() {
|
public List<User> getUsers() {
|
||||||
return this.users;
|
return this.users;
|
||||||
|
@ -195,4 +204,8 @@ public class MucOptions {
|
||||||
public String getSubject() {
|
public String getSubject() {
|
||||||
return this.subject;
|
return this.subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void flagAboutToRename() {
|
||||||
|
this.aboutToRename = true;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1035,34 +1035,14 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
options.flagAboutToRename();
|
||||||
PresencePacket packet = new PresencePacket();
|
PresencePacket packet = new PresencePacket();
|
||||||
packet.setAttribute("to",
|
packet.setAttribute("to",
|
||||||
conversation.getContactJid().split("/")[0] + "/" + nick);
|
conversation.getContactJid().split("/")[0] + "/" + nick);
|
||||||
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
||||||
|
|
||||||
conversation.getAccount().getXmppConnection()
|
conversation.getAccount().getXmppConnection()
|
||||||
.sendPresencePacket(packet, new OnPresencePacketReceived() {
|
.sendPresencePacket(packet, null);
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
String jid = conversation.getContactJid().split("/")[0] + "/"
|
String jid = conversation.getContactJid().split("/")[0] + "/"
|
||||||
+ nick;
|
+ nick;
|
||||||
|
|
|
@ -43,12 +43,16 @@ public abstract class XmppActivity extends Activity {
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
if (!xmppConnectionServiceBound) {
|
if (!xmppConnectionServiceBound) {
|
||||||
|
connectToBackend();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void connectToBackend() {
|
||||||
Intent intent = new Intent(this, XmppConnectionService.class);
|
Intent intent = new Intent(this, XmppConnectionService.class);
|
||||||
intent.setAction("ui");
|
intent.setAction("ui");
|
||||||
startService(intent);
|
startService(intent);
|
||||||
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
|
|
|
@ -40,11 +40,7 @@ public class MessageParser {
|
||||||
String foreignPresence = conversation.getOtrSession().getSessionID().getUserID();
|
String foreignPresence = conversation.getOtrSession().getSessionID().getUserID();
|
||||||
if (!foreignPresence.equals(fromParts[1])) {
|
if (!foreignPresence.equals(fromParts[1])) {
|
||||||
Log.d(LOGTAG,"new otr during existing otr session requested. ending old one");
|
Log.d(LOGTAG,"new otr during existing otr session requested. ending old one");
|
||||||
try {
|
conversation.resetOtrSession();
|
||||||
conversation.getOtrSession().endSession();
|
|
||||||
} catch (OtrException e) {
|
|
||||||
Log.d("xmppService","couldnt end old session");
|
|
||||||
}
|
|
||||||
Log.d("xmppService","starting new one with "+fromParts[1]);
|
Log.d("xmppService","starting new one with "+fromParts[1]);
|
||||||
conversation.startOtrSession(service.getApplicationContext(), fromParts[1]);
|
conversation.startOtrSession(service.getApplicationContext(), fromParts[1]);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +76,6 @@ public class MessageParser {
|
||||||
Log.d(LOGTAG,"otr session stoped");
|
Log.d(LOGTAG,"otr session stoped");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(LOGTAG, "error receiving otr. resetting");
|
|
||||||
conversation.resetOtrSession();
|
conversation.resetOtrSession();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue