aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/generator
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-07-12 03:44:23 +0200
committeriNPUTmice <daniel@gultsch.de>2014-07-12 03:44:23 +0200
commit99935dd630b59d6cff05714c888b01e4c88c6351 (patch)
treee84968da60ea8bc8f117bed39cf430259f9958aa /src/eu/siacs/conversations/generator
parent789383e5cb900baf55595e91f47f6d3ab4cec75e (diff)
moved most of the message/presence generation into seperate classes
Diffstat (limited to 'src/eu/siacs/conversations/generator')
-rw-r--r--src/eu/siacs/conversations/generator/MessageGenerator.java24
-rw-r--r--src/eu/siacs/conversations/generator/PresenceGenerator.java51
2 files changed, 74 insertions, 1 deletions
diff --git a/src/eu/siacs/conversations/generator/MessageGenerator.java b/src/eu/siacs/conversations/generator/MessageGenerator.java
index 28504b21..756a8738 100644
--- a/src/eu/siacs/conversations/generator/MessageGenerator.java
+++ b/src/eu/siacs/conversations/generator/MessageGenerator.java
@@ -42,7 +42,7 @@ public class MessageGenerator {
delay.setAttribute("stamp", mDateFormat.format(date));
}
- public MessagePacket generateOtrChat(Message message) throws OtrException {
+ public MessagePacket generateOtrChat(Message message) {
return generateOtrChat(message, false);
}
@@ -106,4 +106,26 @@ public class MessageGenerator {
packet.setType(MessagePacket.TYPE_ERROR);
return packet;
}
+
+ public MessagePacket confirm(Account account, String to, String id) {
+ MessagePacket packet = new MessagePacket();
+ packet.setType(MessagePacket.TYPE_NORMAL);
+ packet.setTo(to);
+ packet.setFrom(account.getFullJid());
+ Element received = packet.addChild("displayed",
+ "urn:xmpp:chat-markers:0");
+ received.setAttribute("id", id);
+ return packet;
+ }
+
+ public MessagePacket conversationSubject(Conversation conversation,String subject) {
+ MessagePacket packet = new MessagePacket();
+ packet.setType(MessagePacket.TYPE_GROUPCHAT);
+ packet.setTo(conversation.getContactJid().split("/")[0]);
+ Element subjectChild = new Element("subject");
+ subjectChild.setContent(subject);
+ packet.addChild(subjectChild);
+ packet.setFrom(conversation.getAccount().getJid());
+ return packet;
+ }
}
diff --git a/src/eu/siacs/conversations/generator/PresenceGenerator.java b/src/eu/siacs/conversations/generator/PresenceGenerator.java
new file mode 100644
index 00000000..1ca8cd05
--- /dev/null
+++ b/src/eu/siacs/conversations/generator/PresenceGenerator.java
@@ -0,0 +1,51 @@
+package eu.siacs.conversations.generator;
+
+import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.entities.Contact;
+import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
+
+public class PresenceGenerator {
+
+ public PresencePacket requestPresenceUpdatesFrom(Contact contact) {
+ PresencePacket packet = new PresencePacket();
+ packet.setAttribute("type", "subscribe");
+ packet.setAttribute("to", contact.getJid());
+ packet.setAttribute("from", contact.getAccount().getJid());
+ return packet;
+ }
+
+ public PresencePacket stopPresenceUpdatesFrom(Contact contact) {
+ PresencePacket packet = new PresencePacket();
+ packet.setAttribute("type", "unsubscribe");
+ packet.setAttribute("to", contact.getJid());
+ packet.setAttribute("from", contact.getAccount().getJid());
+ return packet;
+ }
+
+ public PresencePacket stopPresenceUpdatesTo(Contact contact) {
+ PresencePacket packet = new PresencePacket();
+ packet.setAttribute("type", "unsubscribed");
+ packet.setAttribute("to", contact.getJid());
+ packet.setAttribute("from", contact.getAccount().getJid());
+ return packet;
+ }
+
+ public PresencePacket sendPresenceUpdatesTo(Contact contact) {
+ PresencePacket packet = new PresencePacket();
+ packet.setAttribute("type", "subscribed");
+ packet.setAttribute("to", contact.getJid());
+ packet.setAttribute("from", contact.getAccount().getJid());
+ return packet;
+ }
+
+ public PresencePacket sendPresence(Account account) {
+ PresencePacket packet = new PresencePacket();
+ packet.setAttribute("from", account.getFullJid());
+ String sig = account.getPgpSignature();
+ if (sig != null) {
+ packet.addChild("status").setContent("online");
+ packet.addChild("x", "jabber:x:signed").setContent(sig);
+ }
+ return packet;
+ }
+} \ No newline at end of file