1 import org.jivesoftware.smack.PacketListener; 2 import org.jivesoftware.smack.packet.*; 3 import org.jivesoftware.smack.util.StringUtils; 4 5 7 public final class SubscriptionRequestPacketListener implements PacketListener{ 8 9 public void processPacket(Packet packet) { 10 Presence p; 11 try{ 12 p=(Presence) packet; 13 } 14 catch (ClassCastException cce){ 15 return; 16 } 17 if(p.getType()==Presence.Type.SUBSCRIBE){ 18 final String from=p.getFrom(); 19 javax.swing.SwingUtilities.invokeLater(new Runnable (){ 20 public void run(){ 21 (new SubscriptionRequestDialog(from) ).show(); 22 } 23 }); 24 return; 25 } 26 if(p.getType()==Presence.Type.SUBSCRIBED){ 27 String f=StringUtils.parseBareAddress(p.getFrom().toLowerCase()); 29 ContactListItem cli=(ContactListItem) WhisperIM.MainWindow.Contacts.get("jabber"+f); 30 if(cli!=null){ 31 f=cli.toString()+" ("+f+")"; 32 } 33 final String ff=f; 34 javax.swing.SwingUtilities.invokeLater(new Runnable (){ 35 public void run(){ 36 GUI.showInfo(WhisperIM.MainWindow,"subscribed","been subscribed",ff); 37 } 38 }); 39 return; 40 } 41 if(p.getType()==Presence.Type.UNSUBSCRIBE){ 42 Presence np=new Presence(Presence.Type.UNSUBSCRIBED); 43 np.setTo(p.getFrom()); 44 np.setFrom(WhisperIM.MainWindow.Conn.getUser()); 45 WhisperIM.MainWindow.Conn.sendPacket(np); 46 } 47 } 48 } 49 | Popular Tags |