Search in sources :

Example 1 with ChatRoomListener

use of org.jivesoftware.spark.ui.ChatRoomListener in project Spark by igniterealtime.

the class BuzzPlugin method initialize.

public void initialize() {
    ProviderManager.addExtensionProvider(ELEMENTNAME, NAMESPACE, new BuzzPacket.Provider());
    ProviderManager.addExtensionProvider(ELEMENTNAME_OLD, NAMESPACE_OLD, new BuzzPacket.Provider());
    SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
        if (stanza instanceof Message) {
            final Message message = (Message) stanza;
            boolean buzz = message.getExtension(ELEMENTNAME_OLD, NAMESPACE_OLD) != null || message.getExtension(ELEMENTNAME, NAMESPACE) != null;
            if (buzz) {
                SwingUtilities.invokeLater(() -> shakeWindow(message));
            }
        }
    }, new StanzaTypeFilter(Message.class));
    SparkManager.getChatManager().addChatRoomListener(new ChatRoomListener() {

        public void chatRoomOpened(final ChatRoom room) {
            TimerTask task = new SwingTimerTask() {

                public void doRun() {
                    addBuzzFeatureToChatRoom(room);
                }
            };
            TaskEngine.getInstance().schedule(task, 100);
        }

        public void chatRoomLeft(ChatRoom room) {
        }

        public void chatRoomClosed(ChatRoom room) {
        }

        public void chatRoomActivated(ChatRoom room) {
        }

        public void userHasJoined(ChatRoom room, String userid) {
        }

        public void userHasLeft(ChatRoom room, String userid) {
        }
    });
}
Also used : StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Message(org.jivesoftware.smack.packet.Message) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) TimerTask(java.util.TimerTask) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomListener(org.jivesoftware.spark.ui.ChatRoomListener)

Aggregations

TimerTask (java.util.TimerTask)1 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)1 Message (org.jivesoftware.smack.packet.Message)1 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)1 ChatRoomListener (org.jivesoftware.spark.ui.ChatRoomListener)1 SwingTimerTask (org.jivesoftware.spark.util.SwingTimerTask)1