001 /* 002 Copyright (C) 2003 Adam Olsen 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU General Public License as published by 006 the Free Software Foundation; either version 1, or (at your option) 007 any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU General Public License for more details. 013 014 You should have received a copy of the GNU General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 017 */ 018 019 package com.valhalla.jbother.jabber.smack; 020 021 import java.util.TreeMap; 022 023 import org.jivesoftware.smack.PacketListener; 024 import org.jivesoftware.smack.packet.Packet; 025 import org.jivesoftware.smack.packet.Presence; 026 027 import com.valhalla.jbother.*; 028 import com.valhalla.jbother.jabber.*; 029 import com.valhalla.jbother.groupchat.*; 030 031 /** 032 * Listens for presence packets when you are in a groupchat, and will update 033 * the nicklist in a groupchat room. Also, if you are in a private conversation with 034 * someone and they sign off, it will let you know. 035 * 036 * @author Adam Olsen 037 * @version 1.0 038 **/ 039 public class GroupParticipantListener implements PacketListener 040 { 041 private ChatRoomPanel window; 042 private VersionCollectorThread vThread = null; 043 044 /** 045 * sets up the packet listener 046 */ 047 public GroupParticipantListener( ChatRoomPanel window ) 048 { 049 this.window = window; 050 } 051 052 /** 053 * Processes incoming presence packets (from group chats) 054 */ 055 public void processPacket( Packet packet ) 056 { 057 Presence presence = (Presence)packet; 058 059 String from = packet.getFrom(); 060 061 boolean addBuddy = false; 062 if( !window.getBuddyStatuses().containsKey( from ) ) addBuddy = true; 063 064 //right now we find out if we have already recieved a packet from them, 065 //and if not, we set up an information "account" in the system 066 BuddyStatus buddyStatus = window.getBuddyStatus( from ); 067 068 //update the relavent presence information 069 if( presence.getType() == Presence.Type.UNAVAILABLE ) 070 { 071 ConversationPanel conv = buddyStatus.getConversation(); 072 if( (conv != null) && (conv instanceof ChatPanel) ) ((ChatPanel)conv).signedOff(); 073 } 074 else { 075 buddyStatus.addResource( "_no resource_", 5, presence.getMode(), presence.getStatus() ); 076 /*if( vThread == null ) 077 { 078 vThread = new VersionCollectorThread(); 079 Thread thread = new Thread( vThread ); 080 thread.start(); 081 } 082 083 vThread.add( buddyStatus );*/ 084 } 085 086 //if we need to, reload the nicklist. 087 if( presence.getType() == Presence.Type.AVAILABLE && addBuddy ) window.addBuddy( buddyStatus.getUser() ); 088 if( presence.getType() == Presence.Type.UNAVAILABLE ) window.removeBuddy( buddyStatus.getUser() ); 089 window.getNickList().repaint(); 090 } 091 }