1package im.conversations.android.xmpp.model.stanza;
2
3import eu.siacs.conversations.xml.Element;
4import eu.siacs.conversations.xml.LocalizedContent;
5
6import im.conversations.android.annotation.XmlElement;
7import im.conversations.android.xmpp.model.jabber.Body;
8
9import java.util.Locale;
10
11@XmlElement
12public class Message extends Stanza {
13
14 public Message() {
15 super(Message.class);
16 }
17
18 public Message(Type type) {
19 this();
20 this.setType(type);
21 }
22
23 public LocalizedContent getBody() {
24 return findInternationalizedChildContentInDefaultNamespace("body");
25 }
26
27 public Type getType() {
28 final var value = this.getAttribute("type");
29 if (value == null) {
30 return Type.NORMAL;
31 } else {
32 try {
33 return Type.valueOf(value.toUpperCase(Locale.ROOT));
34 } catch (final IllegalArgumentException e) {
35 return null;
36 }
37 }
38 }
39
40 public void setType(final Type type) {
41 if (type == null || type == Type.NORMAL) {
42 this.removeAttribute("type");
43 } else {
44 this.setAttribute("type", type.toString().toLowerCase(Locale.ROOT));
45 }
46 }
47
48 public void setBody(final String text) {
49 this.addExtension(new Body(text));
50 }
51
52 public void setAxolotlMessage(Element axolotlMessage) {
53 this.children.remove(findChild("body"));
54 this.children.add(0, axolotlMessage);
55 }
56
57 public enum Type {
58 ERROR,
59 NORMAL,
60 GROUPCHAT,
61 HEADLINE,
62 CHAT
63 }
64}