// ex:sw=3 package lava.net.psyc.packages; import java.util.Hashtable; import lava.net.common.UNL; import lava.net.psyc.UNI; import lava.net.psyc.PSYCDeliveryException; import lava.net.psyc.PSYCMessageCenter; import lava.net.psyc.PSYCPackage; /** ** "Friends" is LynX's counterpart to BK's Notification package. ** ** Friends uses the announcement model, not the ** subscribe-and-keep-alive model. ** ** Since announcements are handled by the server, this package has ** the trivial job of receiving status changes and passing them on. ** **/ public class Friends extends Skeleton { /** * **/ public final static String PackageName = "Friends"; /** * **/ public final static String signonTag = "_notice_friend_present"; protected final static String[] signonAliases = { "_notify_signon", "_status_person_present" }; /** * **/ public final static String signoffTag = "_notice_friend_absent"; protected final static String[] signoffAliases = { "_notify_signoff", "_status_person_absent" }; /** * **/ class DummyListener implements FriendsListener { public void friendPresent(UNI source, String body) { } public void friendAbsent(UNI source, String body) { } } /** * **/ private FriendsListener listener = new DummyListener(); /** * **/ public Friends(FriendsListener listener) { super(); setPackageName(PackageName); addPackageMethod(signonTag,signonAliases,true); addPackageMethod(signoffTag,signoffAliases,true); if(listener != null) this.listener = listener; } /** * **/ public boolean understands() { return !(listener instanceof DummyListener); } /** * **/ public void received(UNL source, String method, String body) { UNI id = center.getIdentification(source); if (id == null) id = new UNI(source); String nick = center.getValue(source, "_nick").toString(); if(method.equals(signonTag)) { listener.friendPresent(id,nick); } else if(method.equals(signoffTag)) { listener.friendAbsent(id,nick); } } }