added no-copy

This commit is contained in:
Daniel Gultsch 2014-03-20 15:49:53 +01:00
parent 5653880156
commit b6ea028a9d
5 changed files with 36 additions and 53 deletions

View file

@ -158,9 +158,8 @@ public class OtrEngine implements OtrEngineHost {
packet.setFrom(account.getFullJid()); //sender
packet.setTo(session.getAccountID()+"/"+session.getUserID()); //reciepient
packet.setBody(body);
Element privateTag = new Element("private");
privateTag.setAttribute("xmlns","urn:xmpp:carbons:2");
packet.addChild(privateTag);
packet.addChild("private","urn:xmpp:carbons:2");
packet.addChild("no-copy","urn:xmpp:hints");
packet.setType(MessagePacket.TYPE_CHAT);
Log.d(LOGTAG,packet.toString());
account.getXmppConnection().sendMessagePacket(packet);

View file

@ -619,11 +619,8 @@ public class XmppConnectionService extends Service {
.getFullJid());
packet.setTo(message.getCounterpart());
packet.setBody("This is an XEP-0027 encryted message");
Element x = new Element("x");
x.setAttribute("xmlns", "jabber:x:encrypted");
x.setContent(this.getPgpEngine().encrypt(keyId,
packet.addChild("x","jabber:x:encrypted").setContent(this.getPgpEngine().encrypt(keyId,
message.getBody()));
packet.addChild(x);
account.getXmppConnection().sendMessagePacket(packet);
message.setStatus(Message.STATUS_SEND);
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
@ -694,9 +691,8 @@ public class XmppConnectionService extends Service {
+ ": could not encrypt message to "
+ message.getCounterpart());
}
Element privateMarker = new Element("private");
privateMarker.setAttribute("xmlns", "urn:xmpp:carbons:2");
packet.addChild(privateMarker);
packet.addChild("private","urn:xmpp:carbons:2");
packet.addChild("no-copy","urn:xmpp:hints");
packet.setTo(otrSession.getSessionID().getAccountID() + "/"
+ otrSession.getSessionID().getUserID());
packet.setFrom(account.getFullJid());
@ -736,16 +732,13 @@ public class XmppConnectionService extends Service {
public void updateRoster(final Account account,
final OnRosterFetchedListener listener) {
IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);
Element query = new Element("query");
query.setAttribute("xmlns", "jabber:iq:roster");
if (!"".equals(account.getRosterVersion())) {
Log.d(LOGTAG, account.getJid() + ": fetching roster version "
+ account.getRosterVersion());
} else {
Log.d(LOGTAG, account.getJid() + ": fetching roster");
}
query.setAttribute("ver", account.getRosterVersion());
iqPacket.addChild(query);
iqPacket.query("jabber:iq:roster").setAttribute("ver", account.getRosterVersion());
account.getXmppConnection().sendIqPacket(iqPacket,
new OnIqPacketReceived() {
@ -958,13 +951,8 @@ public class XmppConnectionService extends Service {
public void deleteContact(Contact contact) {
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
Element query = new Element("query");
query.setAttribute("xmlns", "jabber:iq:roster");
Element item = new Element("item");
item.setAttribute("jid", contact.getJid());
item.setAttribute("subscription", "remove");
query.addChild(item);
iq.addChild(query);
Element query = iq.query("jabber:iq:roster");
query.addChild("item").setAttribute("jid", contact.getJid()).setAttribute("subscription", "remove");
contact.getAccount().getXmppConnection().sendIqPacket(iq, null);
replaceContactInConversation(contact.getJid(), null);
databaseBackend.deleteContact(contact);
@ -1035,8 +1023,7 @@ public class XmppConnectionService extends Service {
Element history = new Element("history");
long lastMsgTime = conversation.getLatestMessage().getTimeSent();
long diff = (System.currentTimeMillis() - lastMsgTime) / 1000 - 1;
history.setAttribute("seconds", diff + "");
x.addChild(history);
x.addChild("history").setAttribute("seconds", diff + "");
}
packet.addChild(x);
conversation.getAccount().getXmppConnection()

View file

@ -17,7 +17,22 @@ public class Element {
public Element addChild(Element child) {
this.content = null;
children.add(child);
return this;
return child;
}
public Element addChild(String name) {
this.content = null;
Element child = new Element(name);
children.add(child);
return child;
}
public Element addChild(String name, String xmlns) {
this.content = null;
Element child = new Element(name);
child.setAttribute("xmlns", xmlns);
children.add(child);
return child;
}
public Element setContent(String content) {

View file

@ -461,11 +461,7 @@ public class XmppConnection implements Runnable {
if (this.streamFeatures.hasChild("session")) {
Log.d(LOGTAG,"sending session");
IqPacket startSession = new IqPacket(IqPacket.TYPE_SET);
Element session = new Element("session");
session.setAttribute("xmlns",
"urn:ietf:params:xml:ns:xmpp-session");
session.setContent("");
startSession.addChild(session);
startSession.addChild("session","urn:ietf:params:xml:ns:xmpp-session"); //setContent("")
this.sendIqPacket(startSession, null);
}
}
@ -484,7 +480,8 @@ public class XmppConnection implements Runnable {
IqPacket register = new IqPacket(IqPacket.TYPE_SET);
Element username = new Element("username").setContent(account.getUsername());
Element password = new Element("password").setContent(account.getPassword());
register.query("jabber:iq:register").addChild(username).addChild(password);
register.query("jabber:iq:register").addChild(username);
register.query().addChild(password);
sendIqPacket(register, new OnIqPacketReceived() {
@Override
@ -515,14 +512,9 @@ public class XmppConnection implements Runnable {
packet.setAttribute("from", account.getFullJid());
if (account.getKeys().has("pgp_signature")) {
try {
String signature = account.getKeys().getString("pgp_signature");
Element status = new Element("status");
status.setContent("online");
packet.addChild(status);
Element x = new Element("x");
x.setAttribute("xmlns", "jabber:x:signed");
x.setContent(signature);
packet.addChild(x);
String signature = account.getKeys().getString("pgp_signature");
packet.addChild("status").setContent("online");
packet.addChild("x","jabber:x:signed").setContent(signature);
} catch (JSONException e) {
//
}
@ -532,12 +524,7 @@ public class XmppConnection implements Runnable {
private void sendBindRequest() throws IOException {
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
Element bind = new Element("bind");
bind.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-bind");
Element resource = new Element("resource");
resource.setContent("Conversations");
bind.addChild(resource);
iq.addChild(bind);
iq.addChild("bind", "urn:ietf:params:xml:ns:xmpp-bind").addChild("resource").setContent("Conversations");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
@ -601,9 +588,7 @@ public class XmppConnection implements Runnable {
private void sendEnableCarbons() {
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
Element enable = new Element("enable");
enable.setAttribute("xmlns", "urn:xmpp:carbons:2");
iq.addChild(enable);
iq.addChild("enable","urn:xmpp:carbons:2");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override
@ -679,10 +664,8 @@ public class XmppConnection implements Runnable {
tagWriter.writeStanzaAsync(new RequestPacket());
} else {
IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
Element ping = new Element("ping");
iq.setAttribute("from",account.getFullJid());
ping.setAttribute("xmlns", "urn:xmpp:ping");
iq.addChild(ping);
iq.setFrom(account.getFullJid());
iq.addChild("ping","urn:xmpp:ping");
this.sendIqPacket(iq, null);
}
}

View file

@ -39,8 +39,7 @@ public class IqPacket extends AbstractStanza {
public Element query() {
Element query = findChild("query");
if (query==null) {
query = new Element("query");
addChild(query);
query = addChild("query");
}
return query;
}