/** * Constructs a new AgentRoster. * * @param connection an XMPP connection. * @throws NotConnectedException */ AgentRoster(XMPPConnection connection, String workgroupJID) throws NotConnectedException { this.connection = connection; this.workgroupJID = workgroupJID; entries = new ArrayList<String>(); listeners = new ArrayList<AgentRosterListener>(); presenceMap = new HashMap<String, Map<String, Presence>>(); // Listen for any roster packets. StanzaFilter rosterFilter = new StanzaTypeFilter(AgentStatusRequest.class); connection.addAsyncStanzaListener(new AgentStatusListener(), rosterFilter); // Listen for any presence packets. connection.addAsyncStanzaListener(new PresencePacketListener(), new StanzaTypeFilter(Presence.class)); // Send request for roster. AgentStatusRequest request = new AgentStatusRequest(); request.setTo(workgroupJID); connection.sendStanza(request); }
@Override public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { Presence.Type typeVal = Presence.Type.valueOf(sampler.getPropertyAsString(TYPE, Presence.Type.available.toString())); Presence.Mode modeVal = Presence.Mode.valueOf(sampler.getPropertyAsString(MODE, Presence.Mode.available.toString())); Presence presence = new Presence(typeVal); presence.setMode(modeVal); String to = sampler.getPropertyAsString(RECIPIENT); if (!to.isEmpty()) { presence.setTo(to); } String text = sampler.getPropertyAsString(STATUS_TEXT); if (!text.isEmpty()) { presence.setStatus(text); } sampler.getXMPPConnection().sendPacket(presence); res.setSamplerData(presence.toXML().toString()); return res; }
@Override public void addUI(JComponent mainPanel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) { addToPanel(mainPanel, labelConstraints, 0, 0, new JLabel("Type: ", JLabel.RIGHT)); addToPanel(mainPanel, editConstraints, 1, 0, type = new JComboBox<>()); type.addItem(Presence.Type.available); type.addItem(Presence.Type.unavailable); type.addItem(Presence.Type.subscribe); type.addItem(Presence.Type.unsubscribe); addToPanel(mainPanel, labelConstraints, 0, 1, new JLabel("Status: ", JLabel.RIGHT)); addToPanel(mainPanel, editConstraints, 1, 1, mode = new JComboBox<>()); mode.addItem(Presence.Mode.available); mode.addItem(Presence.Mode.away); mode.addItem(Presence.Mode.chat); mode.addItem(Presence.Mode.dnd); mode.addItem(Presence.Mode.xa); addToPanel(mainPanel, labelConstraints, 0, 2, new JLabel("Text: ", JLabel.RIGHT)); addToPanel(mainPanel, editConstraints, 1, 2, text = new JTextField(20)); addToPanel(mainPanel, labelConstraints, 0, 3, new JLabel("Recipient: ", JLabel.RIGHT)); addToPanel(mainPanel, editConstraints, 1, 3, recipient = new JTextField(20)); }
protected void sendStatus(JabberPlayer player, String recipient, JabberRoom room) { final SimpleStatus s = (SimpleStatus) player.getStatus(); final Presence p = new Presence(Presence.Type.available); p.setStatus(""); //$NON-NLS-1$ p.setMode(Presence.Mode.chat); p.setProperty(SimpleStatus.LOOKING, s.isLooking()); p.setProperty(SimpleStatus.AWAY, s.isAway()); p.setProperty(SimpleStatus.IP, s.getIp()); p.setProperty(SimpleStatus.CLIENT, s.getClient()); p.setProperty(SimpleStatus.MODULE_VERSION, s.getModuleVersion()); p.setProperty(SimpleStatus.CRC, s.getCrc()); p.setProperty(REAL_NAME, player.getName()); //$NON-NLS-1$ if (room != null) { p.setProperty(ROOM_CONFIG, room.encodeConfig()); p.setProperty(ROOM_JID, room.getJID()); p.setProperty(ROOM_NAME, room.getName()); } p.setTo(recipient == null ? monitorRoom.getRoom() : recipient); conn.sendPacket(p); }
EntityFullJid getFullThingJidOrNotify() { EntityBareJid thingJid = settings.getThingJid(); IoTProvisioningManager ioTProvisioningManager = IoTProvisioningManager.getInstanceFor(xmppConnection); if (!ioTProvisioningManager.iAmFriendOf(thingJid)) { withMainActivity((ma) -> Toast.makeText(ma, "Can not perform action. Not befriended with thing", Toast.LENGTH_LONG).show()); return null; } Presence presence = roster.getPresence(settings.getThingJid()); if (presence == null || !presence.isAvailable()) { withMainActivity((ma) -> Toast.makeText(ma, "Can not perform action. Befriended with thing, but thing is not online/unavailable", Toast.LENGTH_LONG).show()); return null; } EntityFullJid fullOtherJid = presence.getFrom().asEntityFullJidIfPossible(); if (fullOtherJid == null) throw new IllegalStateException("Exepected full JID"); return fullOtherJid; }
public void logoff() { new Thread(new Runnable() { @Override public void run() { try { Presence presence = new Presence(Presence.Type.unavailable); presence.setMode(Presence.Mode.away); presence.setTo(JidCreate.from(SERVICE_NAME)); sendStanza(presence); mReconnectionManager.disableAutomaticReconnection(); mXMPPConnection.disconnect(); stopService(MangostaApplication.getInstance()); } catch (Exception e) { e.printStackTrace(); } finally { clearInstance(); } } }).start(); }
public void sendPresenceAvailable() { if (mXMPPConnection.isAuthenticated()) { new Thread(new Runnable() { @Override public void run() { try { Presence presence = new Presence(JidCreate.from(SERVICE_NAME), Presence.Type.available); presence.setMode(Presence.Mode.available); sendStanza(presence); } catch (Exception e) { e.printStackTrace(); } } }).start(); } }
public void removeContact(String jidString) throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException, XmppStringprepException { Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection()); if (!roster.isLoaded()) { roster.reloadAndWait(); } BareJid jid = JidCreate.bareFrom(jidString); roster.removeEntry(roster.getEntry(jid)); Presence presence = new Presence(Presence.Type.unsubscribe); presence.setTo(JidCreate.from(jidString)); XMPPSession.getInstance().sendStanza(presence); }
public Presence.Type getStatusFromContact(String name) { try { HashMap<Jid, Presence.Type> buddies = getContacts(); for (Map.Entry<Jid, Presence.Type> pair : buddies.entrySet()) { if (XMPPUtils.fromJIDToUserName(pair.getKey().toString()).equals(name)) { return pair.getValue(); } } } catch (Exception e) { e.printStackTrace(); } return Presence.Type.unavailable; }
/** * 发送当前状态 * * @param status 状态。内部类PRESENCE里有两种状态 ONLINE 和 OFFLINE */ public void setPresence(final int status) { //如果没有连接,则返回 if (getConnection() == null) { return; } //新线程里发送状态封包 new Thread() { @Override public void run() { switch (status) { case PRESENCE.ONLINE: getConnection().sendPacket( new Presence(Presence.Type.available)); break; case PRESENCE.OFFLINE: getConnection().sendPacket( new Presence(Presence.Type.unavailable)); break; default: break; } } }.start(); }
/** * sets the status * * @param available if true the status type will be set to available otherwise to unavailable * @param status the status message * @return true if setting the status was successful */ public boolean setStatus(boolean available, String status){ if (connection != null && connection.isConnected()){ // set the presence type Presence presence = new Presence(available ? Presence.Type.available : Presence.Type.unavailable); presence.setStatus(status); try{ connection.sendStanza(presence); Log.d("DEBUG", "Success: Set status."); return true; }catch (Exception e){ System.err.println(e.toString()); Log.e("ERROR", "Error while setting status."); return false; } } Log.e("ERROR", "Setting status failed: No connection."); return false; }
private void presenceReceived(Presence presence){ if (Presence.Type.available.equals(presence.getType()) && presence.getStatus() != null){ String from = presence.getFrom(); int index = from.indexOf('@'); if (index >= 0){ from = from.substring(0, index); } String status = presence.getStatus(); Intent intent = new Intent(Constants.PRESENCE_CHANGED); intent.putExtra(Constants.BUDDY_ID, from); intent.putExtra(Constants.PRESENCE_STATUS, status); LocalBroadcastManager.getInstance(getApplicationContext()) .sendBroadcast(intent); messageHistory.setOnline(from, status); } }
/** * This method sends a friend request to the user if he isn't already in the bots {@link Roster} * . {@inheritDoc} */ @Override public void enableUser(String username) { if (!connection.isConnected()) { return; } Roster roster = connection.getRoster(); if (roster != null && roster.getEntry(username) != null) { return; } try { String clientId = ClientAndChannelContextHolder.getClient().getClientId(); Presence subscribe = new Presence(Presence.Type.subscribe); subscribe.setFrom(sender); subscribe.setTo(username + "." + clientId + XMPPPatternUtils.getUserSuffix()); connection.sendPacket(subscribe); Presence subscribed = new Presence(Presence.Type.subscribed); subscribed.setFrom(sender); subscribed.setTo(username + "." + clientId + XMPPPatternUtils.getUserSuffix()); connection.sendPacket(subscribed); } catch (NotConnectedException e) { LOG.debug("Could not send friendship request because XMPP connector is disconnected"); } }
/** * {@inheritDoc} * * @param username * Has to be in the messagers format. */ @Override public boolean isAvailable(String username) { if (connection.isConnected()) { Roster roster = connection.getRoster(); if (roster != null) { Presence presence = roster.getPresence(username + XMPPPatternUtils.getUserSuffix()); return presence.isAvailable(); } else { LOG.debug("XMPP connection did not return a roster for communote bot"); } } else { LOG.debug("Cannot check availability of user because XMPP connector is disconnected"); } return false; }
/** * This method sends a {@link Presence} packet with the configured priority. */ private void sendPriorityPresence() { if (!connection.isConnected()) { return; } int priority = CommunoteRuntime.getInstance().getConfigurationManager() .getApplicationConfigurationProperties() .getProperty(ApplicationPropertyXmpp.PRIORITY, 100); Presence presence = new Presence(Presence.Type.available); presence.setPriority(priority); try { connection.sendPacket(presence); } catch (NotConnectedException e) { LOG.info("Could not send presence packet because XMPP connector is disconnected"); } }
@Override public void processPacket(Packet packet) { if(packet.getFrom().equals(packet.getTo())){ return; } if (packet instanceof Presence) { Presence presence = (Presence) packet; String from = presence.getFrom();//发送方 String to = presence.getTo();//接收方 if (presence.getType().equals(Presence.Type.subscribe)) {//好友申请 Log.e("jj", "好友申请"); } else if (presence.getType().equals(Presence.Type.subscribed)) {//同意添加好友 Log.e("jj", "同意添加好友"); } else if (presence.getType().equals(Presence.Type.unsubscribe)) {//拒绝添加好友 和 删除好友 Log.e("jj", "拒绝添加好友"); } else if (presence.getType().equals(Presence.Type.unsubscribed)){ } else if (presence.getType().equals(Presence.Type.unavailable)) {//好友下线 要更新好友列表,可以在这收到包后,发广播到指定页面 更新列表 Log.e("jj", "好友下线"); } else if(presence.getType().equals(Presence.Type.available)){//好友上线 Log.e("jj", "好友上线"); } else{ Log.e("jj", "error"); } } }
private XmppRosterEntry getRosterEntryFor(Roster roster, RosterEntry entry) { XmppRosterEntry newEntry = new XmppRosterEntry(); newEntry.setXmppJID(entry.getUser()) .setAlias(entry.getName()) .setAvatar(getCachedAvatar(entry.getUser())); if (newEntry.getAvatar() == null) { newEntry.setAvatar(getAvatarFor(entry.getUser())); } Presence presence = roster.getPresence(entry.getUser()); newEntry.setAvailable(presence.isAvailable()) .setPresenceMode(presence.getMode().ordinal()) .setPersonalMessage(presence.getStatus()); newEntry.setUnreadMessages(mMessagesProvider.countUnreadMessages(mAccount.getXmppJid(), entry.getUser())); return newEntry; }
protected void afterSuccessfulLogin(final boolean resumed) throws NotConnectedException { // Indicate that we're now authenticated. this.authenticated = true; // If debugging is enabled, change the the debug window title to include the // name we are now logged-in as. // If DEBUG was set to true AFTER the connection was created the debugger // will be null if (config.isDebuggerEnabled() && debugger != null) { debugger.userHasLogged(user); } callConnectionAuthenticatedListener(resumed); // Set presence to online. It is important that this is done after // callConnectionAuthenticatedListener(), as this call will also // eventually load the roster. And we should load the roster before we // send the initial presence. if (config.isSendPresence() && !resumed) { sendStanza(new Presence(Presence.Type.available)); } }
/** * Will a user recieve a message from another after only sending the user a directed presence, * or will Wildfire intercept for offline storage? * * User1 becomes lines. User0 never sent an available presence to the server but * instead sent one to User1. User1 sends a message to User0. Should User0 get the * message? */ public void testDirectPresence() { getConnection(1).sendStanza(new Presence(Presence.Type.available)); Presence presence = new Presence(Presence.Type.available); presence.setTo(getBareJID(1)); getConnection(0).sendStanza(presence); PacketCollector collector = getConnection(0) .createPacketCollector(new MessageTypeFilter(Message.Type.chat)); try { getConnection(1).getChatManager().createChat(getBareJID(0), null).sendMessage("Test 1"); } catch (XMPPException e) { e.printStackTrace(); fail(e.getMessage()); } Message message = (Message) collector.nextResult(2500); assertNotNull("Message not recieved from remote user", message); }
/** * User1 logs from 2 resources but only one is available. User0 sends a message * to the full JID of the unavailable resource. User1 in the not available resource * should receive the message. * TODO Fix this in Wildfire but before check if XMPP spec requests this feature */ public void testNotAvailablePresence() throws XMPPException { // Change the presence to unavailable of User_1 getConnection(1).sendStanza(new Presence(Presence.Type.unavailable)); // User_1 will log in again using another resource (that is going to be available) XMPPTCPConnection conn = createConnection(); conn.connect(); conn.login(getUsername(1), getPassword(1), "OtherPlace"); // Create chats between participants Chat chat0 = getConnection(0).getChatManager().createChat(getFullJID(1), null); Chat chat1 = getConnection(1).getChatManager().createChat(getBareJID(0), chat0.getThreadID(), null); // Test delivery of message to the presence with highest priority chat0.sendMessage("Hello"); /*assertNotNull("Not available connection didn't receive message sent to full JID", chat1.nextMessage(2000)); assertNull("Not available connection received an unknown message", chat1.nextMessage(1000));*/ conn.disconnect(); }
@Test public void validatePresenceOptionalElements() throws Exception { String stanza = "<presence xml:lang='en' type='unsubscribed'>" + "<show>dnd</show>" + "<status>Wooing Juliet</status>" + "<priority>1</priority>" + "</presence>"; Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza)); assertXMLEqual(stanza, presence.toXML().toString()); assertEquals(Presence.Type.unsubscribed, presence.getType()); assertEquals("dnd", presence.getMode().name()); assertEquals("en", presence.getLanguage()); assertEquals("Wooing Juliet", presence.getStatus()); assertEquals(1, presence.getPriority()); }
/** * Fires event to listeners. */ private void fireEvent(int eventType, Object eventObject) { AgentRosterListener[] listeners = null; synchronized (this.listeners) { listeners = new AgentRosterListener[this.listeners.size()]; this.listeners.toArray(listeners); } for (int i = 0; i < listeners.length; i++) { switch (eventType) { case EVENT_AGENT_ADDED: listeners[i].agentAdded((String)eventObject); break; case EVENT_AGENT_REMOVED: listeners[i].agentRemoved((String)eventObject); break; case EVENT_PRESENCE_CHANGED: listeners[i].presenceChanged((Presence)eventObject); break; } } }
/** * Sets the agent's current status with the workgroup. The presence mode affects how offers * are routed to the agent. The possible presence modes with their meanings are as follows:<ul> * <p/> * <li>Presence.Mode.AVAILABLE -- (Default) the agent is available for more chats * (equivalent to Presence.Mode.CHAT). * <li>Presence.Mode.DO_NOT_DISTURB -- the agent is busy and should not be disturbed. * However, special case, or extreme urgency chats may still be offered to the agent. * <li>Presence.Mode.AWAY -- the agent is not available and should not * have a chat routed to them (equivalent to Presence.Mode.EXTENDED_AWAY).</ul> * * @param presenceMode the presence mode of the agent. * @param status sets the status message of the presence update. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws IllegalStateException if the agent is not online with the workgroup. */ public void setStatus(Presence.Mode presenceMode, String status) throws NoResponseException, XMPPErrorException, NotConnectedException { if (!online) { throw new IllegalStateException("Cannot set status when the agent is not online."); } if (presenceMode == null) { presenceMode = Presence.Mode.available; } this.presenceMode = presenceMode; Presence presence = new Presence(Presence.Type.available); presence.setMode(presenceMode); presence.setTo(this.getWorkgroupJID()); if (status != null) { presence.setStatus(status); } presence.addExtension(new MetaData(this.metaData)); PacketCollector collector = this.connection.createPacketCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence); collector.nextResultOrThrow(); }
/** * Like {@link #create(String)}, but will return true if the room creation was acknowledged by * the service (with an 201 status code). It's up to the caller to decide, based on the return * value, if he needs to continue sending the room configuration. If false is returned, the room * already existed and the user is able to join right away, without sending a form. * * @param nickname the nickname to use. * @param password the password to use. * @param history the amount of discussion history to receive while joining a room. * @param timeout the amount of time to wait for a reply from the MUC service(in milliseconds). * @return true if the room creation was acknowledged by the service, false otherwise. * @throws XMPPErrorException if the room couldn't be created for some reason (e.g. 405 error if * the user is not allowed to create the room) * @throws NoResponseException if there was no response from the server. */ public synchronized boolean createOrJoin(String nickname, String password, DiscussionHistory history, long timeout) throws NoResponseException, XMPPErrorException, SmackException { if (joined) { throw new IllegalStateException("Creation failed - User already joined the room."); } Presence presence = enter(nickname, password, history, timeout); // Look for confirmation of room creation from the server MUCUser mucUser = MUCUser.from(presence); if (mucUser != null && mucUser.getStatus().contains(Status.ROOM_CREATED_201)) { // Room was created and the user has joined the room return true; } return false; }
/** * Changes the occupant's availability status within the room. The presence type * will remain available but with a new status that describes the presence update and * a new presence mode (e.g. Extended away). * * @param status a text message describing the presence update. * @param mode the mode type for the presence update. * @throws NotConnectedException */ public void changeAvailabilityStatus(String status, Presence.Mode mode) throws NotConnectedException { StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank."); // Check that we already have joined the room before attempting to change the // availability status. if (!joined) { throw new IllegalStateException( "Must be logged into the room to change the " + "availability status."); } // We change the availability status by sending a presence packet to the room with the // new presence status and mode Presence joinPresence = new Presence(Presence.Type.available); joinPresence.setStatus(status); joinPresence.setMode(mode); joinPresence.setTo(room + "/" + nickname); // Send join packet. connection.sendStanza(joinPresence); }
@Override public void presenceChanged(Presence presence) { log.fine("Presence change from " + presence.getFrom()); String name = StringUtils.parseName(presence.getFrom()); if (!isMultiplicityDevice(name)) { return; } if (presence.isAvailable()) { notifyDeviceAvailable(name); } else { notifyDeviceUnavailable(name); } }
/** * Notify current presence. * * @param connection * the connection */ private void notifyCurrentPresence(XMPPConnection connection) { if (multiplicityGroup == null) { log.log(Level.WARNING, "Could not find the multiplicity roster group."); return; } log.log(Level.FINE, "Loading roster entries."); for (RosterEntry re : multiplicityGroup.getEntries()) { log.finer("Roster entry check availability on " + re.getUser()); Presence presence = roster.getPresence(re.getUser()); if (presence.isAvailable()) { log.finer(" is available!"); notifyDeviceAvailable(re.getName()); } } }
public void disconnect(Presence unavailablePresence) { // If not connected, ignore this request. if (packetReader == null || packetWriter == null) { return; } shutdown(unavailablePresence); if (roster != null) { roster.cleanup(); roster = null; } wasAuthenticated = false; packetWriter.cleanup(); packetWriter = null; packetReader.cleanup(); packetReader = null; }
/** * Changes the occupant's availability status within the room. The presence type * will remain available but with a new status that describes the presence update and * a new presence mode (e.g. Extended away). * * @param status a text message describing the presence update. * @param mode the mode type for the presence update. */ public void changeAvailabilityStatus(String status, Presence.Mode mode) { if (nickname == null || nickname.equals("")) { throw new IllegalArgumentException("Nickname must not be null or blank."); } // Check that we already have joined the room before attempting to change the // availability status. if (!joined) { throw new IllegalStateException( "Must be logged into the room to change the " + "availability status."); } // We change the availability status by sending a presence packet to the room with the // new presence status and mode Presence joinPresence = new Presence(Presence.Type.available); joinPresence.setStatus(status); joinPresence.setMode(mode); joinPresence.setTo(room + "/" + nickname); // Invoke presence interceptors so that extra information can be dynamically added for (PacketInterceptor packetInterceptor : presenceInterceptors) { packetInterceptor.interceptPacket(joinPresence); } // Send join packet. connection.sendPacket(joinPresence); }
/** * Constructs a new AgentRoster. * * @param connection an XMPP connection. */ AgentRoster(Connection connection, String workgroupJID) { this.connection = connection; this.workgroupJID = workgroupJID; entries = new ArrayList<String>(); listeners = new ArrayList<AgentRosterListener>(); presenceMap = new HashMap<String, Map<String, Presence>>(); // Listen for any roster packets. PacketFilter rosterFilter = new PacketTypeFilter(AgentStatusRequest.class); connection.addPacketListener(new AgentStatusListener(), rosterFilter); // Listen for any presence packets. connection.addPacketListener(new PresencePacketListener(), new PacketTypeFilter(Presence.class)); // Send request for roster. AgentStatusRequest request = new AgentStatusRequest(); request.setTo(workgroupJID); connection.sendPacket(request); }
/** * ����RosterEntry����һ��User * * @param entry * @return */ public static User transEntryToUser(RosterEntry entry, Roster roster) { User user = new User(); if (entry.getName() == null) { user.setName(StringUtil.getUserNameByJid(entry.getUser())); } else { user.setName(entry.getName()); } user.setJID(entry.getUser()); System.out.println(entry.getUser()); Presence presence = roster.getPresence(entry.getUser()); user.setFrom(presence.getFrom()); user.setStatus(presence.getStatus()); user.setSize(entry.getGroups().size()); user.setAvailable(presence.isAvailable()); user.setType(entry.getType()); return user; }
/** * �����û�jid�õ��û� * * @param userJid * @param nickname */ public static User getByUserJid(String userJId, XMPPConnection connection) { Roster roster = connection.getRoster(); RosterEntry entry = connection.getRoster().getEntry(userJId); if (null == entry) { return null; } User user = new User(); if (entry.getName() == null) { user.setName(StringUtil.getUserNameByJid(entry.getUser())); } else { user.setName(entry.getName()); } user.setJID(entry.getUser()); System.out.println(entry.getUser()); Presence presence = roster.getPresence(entry.getUser()); user.setFrom(presence.getFrom()); user.setStatus(presence.getStatus()); user.setSize(entry.getGroups().size()); user.setAvailable(presence.isAvailable()); user.setType(entry.getType()); return user; }
/** * ���һ����������������������� */ private void addSubscriptionListener() { PacketFilter filter = new PacketFilter() { @Override public boolean accept(Packet packet) { if (packet instanceof Presence) { Presence presence = (Presence) packet; if (presence.getType().equals(Presence.Type.subscribe)) { return true; } } return false; } }; XmppConnectionManager.getInstance().getConnection() .addPacketListener(subscriptionPacketListener, filter); }
@Override public void presenceChanged(Presence presence) { Intent intent = new Intent(); intent.setAction(Constant.ROSTER_PRESENCE_CHANGED); String subscriber = presence.getFrom().substring(0, presence.getFrom().indexOf("/")); RosterEntry entry = roster.getEntry(subscriber); if (ContacterManager.contacters.containsKey(subscriber)) { // ��״̬�ı�֮ǰ��user�㲥��ȥ intent.putExtra(User.userKey, ContacterManager.contacters.get(subscriber)); ContacterManager.contacters.remove(subscriber); ContacterManager.contacters.put(subscriber, ContacterManager.transEntryToUser(entry, roster)); } sendBroadcast(intent); }
public void displayfrndslist() { Roster rster = conn.getRoster(); Collection<RosterEntry> records = rster.getEntries(); System.out.println("\nTotal friends: "+records.size()); int i = 1; String status = null; for(RosterEntry r:records) { Presence presence = rster.getPresence(r.getUser()); if ((presence != null)){ if(rster.getPresence(r.getUser()).toString().contains("away")) status = "idle"; else if (rster.getPresence(r.getUser()).toString().contains("unavailable")) status = "offline"; else if (rster.getPresence(r.getUser()).toString().contains("dnd")) status = "busy"; else status = "available"; System.out.println("(#" + i + ")"+r.getUser()+"---"+status); i++; } } }