2014-07-12 03:44:23 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								package eu.siacs.conversations.generator;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import eu.siacs.conversations.entities.Account;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import eu.siacs.conversations.entities.Contact;
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-23 14:30:27 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import eu.siacs.conversations.xml.Element;
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 03:44:23 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-23 14:30:27 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								public class PresenceGenerator extends AbstractGenerator {
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 03:44:23 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 11:13:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									private PresencePacket subscription(String type, Contact contact) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 03:44:23 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										PresencePacket packet = new PresencePacket();
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 11:13:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										packet.setAttribute("type", type);
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 03:44:23 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										packet.setAttribute("to", contact.getJid());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										packet.setAttribute("from", contact.getAccount().getJid());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return packet;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							
								
									
										
										
										
											2014-08-31 16:28:21 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 11:13:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									public PresencePacket requestPresenceUpdatesFrom(Contact contact) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return subscription("subscribe", contact);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 03:44:23 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									public PresencePacket stopPresenceUpdatesFrom(Contact contact) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 11:13:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return subscription("unsubscribe", contact);
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 03:44:23 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									public PresencePacket stopPresenceUpdatesTo(Contact contact) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 11:13:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return subscription("unsubscribed", contact);
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 03:44:23 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									public PresencePacket sendPresenceUpdatesTo(Contact contact) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 11:13:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return subscription("subscribed", contact);
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 03:44:23 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									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);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-23 14:30:27 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										String capHash = getCapHash();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										if (capHash != null) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-08-31 16:28:21 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											Element cap = packet.addChild("c",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													"http://jabber.org/protocol/caps");
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-23 14:30:27 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											cap.setAttribute("hash", "sha-1");
							 | 
						
					
						
							
								
									
										
										
										
											2014-08-31 16:28:21 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											cap.setAttribute("node", "http://conversions.siacs.eu");
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-23 14:30:27 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											cap.setAttribute("ver", capHash);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-12 03:44:23 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return packet;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |