2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.xmpp.stanzas;
|
|
|
|
|
2014-12-30 13:50:51 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2014-10-22 16:38:44 +00:00
|
|
|
import eu.siacs.conversations.xml.Element;
|
2020-05-15 15:06:16 +00:00
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
2014-10-22 16:38:44 +00:00
|
|
|
|
|
|
|
public class AbstractStanza extends Element {
|
|
|
|
|
2014-12-30 13:50:51 +00:00
|
|
|
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() {
|
2014-12-15 16:29:17 +00:00
|
|
|
return getAttributeAsJid("to");
|
2014-11-09 15:18:53 +00:00
|
|
|
}
|
2014-11-06 19:10:03 +00:00
|
|
|
|
|
|
|
public Jid getFrom() {
|
2014-12-15 16:29:17 +00:00
|
|
|
return getAttributeAsJid("from");
|
2014-11-09 15:18:53 +00:00
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
|
2014-11-05 20:55:47 +00:00
|
|
|
public void setTo(final Jid to) {
|
2014-11-17 19:45:00 +00:00
|
|
|
if (to != null) {
|
2020-05-15 15:06:16 +00:00
|
|
|
setAttribute("to", to);
|
2014-11-17 19:45:00 +00:00
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 20:55:47 +00:00
|
|
|
public void setFrom(final Jid from) {
|
2014-11-17 19:45:00 +00:00
|
|
|
if (from != null) {
|
2020-05-15 15:06:16 +00:00
|
|
|
setAttribute("from", from);
|
2014-11-17 19:45:00 +00:00
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
2014-12-30 13:50:51 +00:00
|
|
|
public boolean fromServer(final Account account) {
|
2018-04-28 14:26:40 +00:00
|
|
|
final Jid from = getFrom();
|
|
|
|
return from == null
|
2020-05-17 08:24:46 +00:00
|
|
|
|| from.equals(account.getDomain())
|
2018-04-28 14:26:40 +00:00
|
|
|
|| from.equals(account.getJid().asBareJid())
|
|
|
|
|| from.equals(account.getJid());
|
2014-12-30 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean toServer(final Account account) {
|
2018-04-28 14:26:40 +00:00
|
|
|
final Jid to = getTo();
|
|
|
|
return to == null
|
2020-05-17 08:24:46 +00:00
|
|
|
|| to.equals(account.getDomain())
|
2018-04-28 14:26:40 +00:00
|
|
|
|| to.equals(account.getJid().asBareJid())
|
|
|
|
|| to.equals(account.getJid());
|
2014-12-30 13:50:51 +00:00
|
|
|
}
|
2015-05-15 03:14:15 +00:00
|
|
|
|
|
|
|
public boolean fromAccount(final Account account) {
|
2018-04-28 14:26:40 +00:00
|
|
|
final Jid from = getFrom();
|
|
|
|
return from != null && from.asBareJid().equals(account.getJid().asBareJid());
|
2015-05-15 03:14:15 +00:00
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|