2014-02-28 17:46:01 +00:00
|
|
|
package eu.siacs.conversations.xmpp;
|
2014-01-30 23:33:01 +00:00
|
|
|
|
2014-02-28 17:46:01 +00:00
|
|
|
import eu.siacs.conversations.xml.Element;
|
2014-01-30 23:33:01 +00:00
|
|
|
|
|
|
|
public class MessagePacket extends Element {
|
2014-02-02 15:05:15 +00:00
|
|
|
public static final int TYPE_CHAT = 0;
|
2014-02-02 16:53:34 +00:00
|
|
|
public static final int TYPE_UNKNOWN = 1;
|
|
|
|
public static final int TYPE_NO = 2;
|
2014-02-05 21:33:39 +00:00
|
|
|
public static final int TYPE_GROUPCHAT = 3;
|
2014-02-20 16:00:50 +00:00
|
|
|
public static final int TYPE_ERROR = 4;
|
2014-02-02 15:05:15 +00:00
|
|
|
|
2014-01-30 23:33:01 +00:00
|
|
|
private MessagePacket(String name) {
|
|
|
|
super(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public MessagePacket() {
|
|
|
|
super("message");
|
|
|
|
}
|
2014-02-02 15:05:15 +00:00
|
|
|
|
|
|
|
public String getTo() {
|
|
|
|
return getAttribute("to");
|
|
|
|
}
|
2014-02-01 14:07:20 +00:00
|
|
|
|
|
|
|
public String getFrom() {
|
|
|
|
return getAttribute("from");
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getBody() {
|
2014-02-02 16:53:34 +00:00
|
|
|
Element body = this.findChild("body");
|
|
|
|
if (body!=null) {
|
|
|
|
return body.getContent();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2014-02-01 14:07:20 +00:00
|
|
|
}
|
2014-02-02 15:05:15 +00:00
|
|
|
|
|
|
|
public void setTo(String to) {
|
|
|
|
setAttribute("to", to);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFrom(String from) {
|
|
|
|
setAttribute("from",from);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBody(String text) {
|
2014-02-13 22:40:08 +00:00
|
|
|
this.children.remove(findChild("body"));
|
2014-02-02 15:05:15 +00:00
|
|
|
Element body = new Element("body");
|
|
|
|
body.setContent(text);
|
|
|
|
this.children.add(body);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setType(int type) {
|
|
|
|
switch (type) {
|
|
|
|
case TYPE_CHAT:
|
|
|
|
this.setAttribute("type","chat");
|
|
|
|
break;
|
2014-02-05 21:33:39 +00:00
|
|
|
case TYPE_GROUPCHAT:
|
|
|
|
this.setAttribute("type", "groupchat");
|
|
|
|
break;
|
2014-02-02 15:05:15 +00:00
|
|
|
default:
|
|
|
|
this.setAttribute("type","chat");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-02 16:53:34 +00:00
|
|
|
|
|
|
|
public int getType() {
|
|
|
|
String type = getAttribute("type");
|
|
|
|
if (type==null) {
|
|
|
|
return TYPE_NO;
|
|
|
|
}
|
|
|
|
if (type.equals("chat")) {
|
|
|
|
return TYPE_CHAT;
|
2014-02-05 21:33:39 +00:00
|
|
|
} else if (type.equals("groupchat")) {
|
|
|
|
return TYPE_GROUPCHAT;
|
2014-02-20 16:00:50 +00:00
|
|
|
} else if (type.equals("error")) {
|
|
|
|
return TYPE_ERROR;
|
2014-02-02 16:53:34 +00:00
|
|
|
} else {
|
|
|
|
return TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
2014-01-30 23:33:01 +00:00
|
|
|
}
|