anotherim/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java

51 lines
1.2 KiB
Java
Raw Normal View History

2014-10-22 16:38:44 +00:00
package eu.siacs.conversations.xmpp.stanzas;
import eu.siacs.conversations.entities.Account;
2014-10-22 16:38:44 +00:00
import eu.siacs.conversations.xml.Element;
2018-03-05 17:30:40 +00:00
import rocks.xmpp.addr.Jid;
2014-10-22 16:38:44 +00:00
public class AbstractStanza extends Element {
protected AbstractStanza(final String name) {
2014-10-22 16:38:44 +00:00
super(name);
}
2014-11-06 19:10:03 +00:00
public Jid getTo() {
return getAttributeAsJid("to");
}
2014-11-06 19:10:03 +00:00
public Jid getFrom() {
return getAttributeAsJid("from");
}
2014-10-22 16:38:44 +00:00
public void setTo(final Jid to) {
2014-11-17 19:45:00 +00:00
if (to != null) {
setAttribute("to", to.toEscapedString());
2014-11-17 19:45:00 +00:00
}
2014-10-22 16:38:44 +00:00
}
public void setFrom(final Jid from) {
2014-11-17 19:45:00 +00:00
if (from != null) {
setAttribute("from", from.toEscapedString());
2014-11-17 19:45:00 +00:00
}
2014-10-22 16:38:44 +00:00
}
public boolean fromServer(final Account account) {
return getFrom() == null
|| getFrom().equals(Jid.of(account.getServer()))
2018-03-05 17:30:40 +00:00
|| getFrom().equals(account.getJid().asBareJid())
|| getFrom().equals(account.getJid());
}
public boolean toServer(final Account account) {
return getTo() == null
|| getTo().equals(Jid.of(account.getServer()))
2018-03-05 17:30:40 +00:00
|| getTo().equals(account.getJid().asBareJid())
|| getTo().equals(account.getJid());
}
public boolean fromAccount(final Account account) {
2018-03-05 17:30:40 +00:00
return getFrom() != null && getFrom().asBareJid().equals(account.getJid().asBareJid());
}
2014-10-22 16:38:44 +00:00
}