Package org.jivesoftware.smack.packet

Examples of org.jivesoftware.smack.packet.Presence


//            treeEntry.dispose();
          } else {
            if(treeEntry.item != null && !treeEntry.item.isDisposed()) {
              RosterEntry entry = treeEntry.entry;
              Roster roster = account.xmpp.getRoster();
              Presence presence = (roster == null ? null : roster.getPresence(entry.getUser()));
              if(item.getData("presence") == presence) return;
//              updatePresenceOfItem(item, entry, (roster == null ? null : presence));
//              return;
            }
          }
View Full Code Here


      if (!hideOffline || entry.getUser().indexOf('@') < 0)
        return true;
      Roster roster = account.xmpp.getRoster();
      if (roster == null)
        return false;
      Presence p = roster.getPresence(entry.getUser());
      if (p == null || p.getType() != Presence.Type.AVAILABLE)
        return false;
      return true;
    }
View Full Code Here

      item = new TreeItem(parent.item, SWT.NULL, index);
      item.setText(getRosterLabel(entry));
      item.setData("entry", entry);
      item.setData("account", account);
      Roster roster = account.xmpp.getRoster();
      Presence presence = roster == null ? null : roster.getPresence(entry.getUser());
      item.setData("presence",presence);
      updatePresenceOfItem(item, entry, presence);
    }
View Full Code Here

            public void processPacket(Packet packet) {
              //System.out.println("Got Packet from " + packet.getFrom() + " : " + packet.getClass().toString() + " :  " + packet.toString());
              if(packet instanceof Message) {
                account.chatWindowExtensionManager.handleMessage((Message)packet);
              } else if(packet instanceof Presence) {
                Presence presence = (Presence)packet;
                if(presence.getType() == Presence.Type.SUBSCRIBE) {
                  askForSubscribePermission(presence);
                }
              } else if(packet instanceof Version) {
                Version version = (Version)packet;
                if(version.getType() == IQ.Type.GET) {
                  Version reply = new Version();
                  reply.setType(IQ.Type.RESULT);
                  reply.setTo(version.getFrom());
                  reply.setName("GOIM (Gamers Own Instant Messenger)");
                  reply.setVersion((String)Platform.getProduct().getDefiningBundle().getHeaders().get("Bundle-Version"));
                  reply.setOs(System.getProperty("os.name") + " " + System.getProperty("os.version") + " (Java: " + System.getProperty("java.vendor") + " " + System.getProperty("java.version") + ")");
                  conn.sendPacket(reply);
                }
              }
            }},new AndFilter());
          conn.addConnectionListener(new ConnectionListener() {
            public void connectionClosed() {
            }
            public void connectionClosedOnError(final Exception e) {
              conn = null;
              Presence previousPresence = lastPresenceSent;
              lastPresenceSent = null;
              ownPresenceChanged.fireEvent(new StatusChangedEvent(this,previousPresence));
              PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
                public void run() {
                  ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),"Error while logging in","Error during connection with jabber server: " + account.getServer() + e.getLocalizedMessage(),new Status(IStatus.ERROR,GOIMPlugin.ID,IStatus.OK,"Error while connected with account " + account.name,e));
View Full Code Here

    return result;
  }
  public Shell workbenchShell;
  public void askForSubscribePermission(final Presence presence) {
    if(StringUtils.parseBareAddress(presence.getFrom()).equals(GOIMAccount.STATSCONTACTJID)) {
      Presence reply = new Presence(Presence.Type.SUBSCRIBED);
      reply.setTo(presence.getFrom());
      conn.sendPacket(reply);
      Presence requestSubscribe = new Presence(Presence.Type.SUBSCRIBE);
      requestSubscribe.setTo(presence.getFrom());
      conn.sendPacket(requestSubscribe);
      return;
    }
    if(workbenchShell == null) workbenchShell = account.getDefaultShell();
    workbenchShell.getDisplay().asyncExec(new Runnable() {
View Full Code Here

    });
  }
  Presence presenceByUser = null;
  public void changeStatus(Presence.Type type, Presence.Mode mode, boolean byuser) {
    if(type == Presence.Type.UNAVAILABLE) {
      Presence previousPresence = lastPresenceSent;
      conn.close();conn = null;lastPresenceSent = null;roster = null;
      ownPresenceChanged.fireEvent(new StatusChangedEvent(this,previousPresence));
      rosterListener.fireEvent(new GOIMRosterEvent(XMPPManager.this,GOIMRosterEvent.TYPE_MODIFIED, null));
      return;
    }
    Presence presence = new Presence(type);
    presence.setMode(mode);
    StringBuffer status = new StringBuffer();
    boolean changestate = false;
    String changeStateTo = GOIMPlugin.getDefault().getMyPreferenceStore().getString(PreferenceConstants.P_CHANGE_STATUS_TO_ON_GAME_LAUNCH);
    for(GOIMGameItem game : gameList) {
      String str = game.retrieveExtensionProxy().getStatusString(game);
      PacketExtension ex = game.retrieveExtensionProxy().getStatusPacket(game);
      if(str != null) status.append(str).append(" ");
      if(ex != null) presence.addExtension(ex);
      if(game.retrieveExtensionProxy().needsOnlineStatusChange(game))
        changestate = true;
    }
    if(!byuser && (presenceByUser == null || presenceByUser.getMode() == Presence.Mode.AVAILABLE)) {
      if(changestate) {
        if(!changeStateTo.equals(""))
          presence.setMode(Presence.Mode.fromString(changeStateTo));
      } else {
        presence.setMode(presenceByUser.getMode());
      }
    }
    String statusMsg = status.toString();
    if(!statusMsg.equals("")) statusMsg = "Currently Playing: " + statusMsg + " (visit http://goim.sphene.net)";
    if(status.length() > 0) presence.setStatus(statusMsg);
    presence.setPriority(account.resourcePriority);
    conn.sendPacket(presence);
    Presence previousPresence = lastPresenceSent;
    lastPresenceSent = presence;
    if(byuser) presenceByUser = presence;
    ownPresenceChanged.fireEvent(new StatusChangedEvent(this,previousPresence));
  }
View Full Code Here

      } });
   
  }
  public Presence getGlobalPresence() { // TODO improve this method :)
    GOIMAccountList list = getAccountList();
    Presence leastpresence = null;
    for(GOIMAccount account : list) {
      Presence p = account.xmpp.getOwnPresence();
      if(p == null) return null;
      if(leastpresence == null)
        leastpresence = p;
      else if(leastpresence.getType() == Presence.Type.AVAILABLE)
        leastpresence = p;
View Full Code Here

        conn = new XMPPConnection(config);
        try {
            conn.connect();
            conn.login(username, password, "Freedomotic");
            // Create a new presence. Pass in false to indicate we're unavailable.
            Presence presence = new Presence(Presence.Type.available);
            presence.setStatus("Ready");
            // Send the packet (assume we have a Connection instance called "con").
            conn.sendPacket(presence);

            // wait for messages
            ChatManager chatmanager = conn.getChatManager();
View Full Code Here

    }


    public void receiveFile(){
        // der Status muss available sein, sonst ist das Senden nicht möglich
        Presence presence = new Presence(Presence.Type.available);
        xmppconnection.sendPacket(presence);

        FileTransferManager manager = new FileTransferManager(xmppconnection);
        manager.addFileTransferListener(new FileTransferListener() {
            public void fileTransferRequest(FileTransferRequest request) {
View Full Code Here

     * retriving the headers, then the real messages of the headers and finally removing the
     * loaded messages.
     */
    public void testReadAndDelete() {
        // Make user2 unavailable
        getConnection(1).sendPacket(new Presence(Presence.Type.unavailable));

        try {
            Thread.sleep(500);

            // User1 sends some messages to User2 which is not available at the moment
            Chat chat = getConnection(0).getChatManager().createChat(getBareJID(1), null);
            chat.sendMessage("Test 1");
            chat.sendMessage("Test 2");

            Thread.sleep(500);

            // User2 checks the number of offline messages
            OfflineMessageManager offlineManager = new OfflineMessageManager(getConnection(1));
            assertEquals("Wrong number of offline messages", 2, offlineManager.getMessageCount());
            // Check the message headers
            Iterator headers = offlineManager.getHeaders();
            assertTrue("No message header was found", headers.hasNext());
            List<String> stamps = new ArrayList<String>();
            while (headers.hasNext()) {
                OfflineMessageHeader header = (OfflineMessageHeader) headers.next();
                assertEquals("Incorrect sender", getFullJID(0), header.getJid());
                assertNotNull("No stamp was found in the message header", header.getStamp());
                stamps.add(header.getStamp());
            }
            assertEquals("Wrong number of headers", 2, stamps.size());
            // Get the offline messages
            Iterator messages = offlineManager.getMessages(stamps);
            assertTrue("No message was found", messages.hasNext());
            stamps = new ArrayList<String>();
            while (messages.hasNext()) {
                Message message = (Message) messages.next();
                OfflineMessageInfo info = (OfflineMessageInfo) message.getExtension("offline",
                        "http://jabber.org/protocol/offline");
                assertNotNull("No offline information was included in the offline message", info);
                assertNotNull("No stamp was found in the message header", info.getNode());
                stamps.add(info.getNode());
            }
            assertEquals("Wrong number of messages", 2, stamps.size());
            // Check that the offline messages have not been deleted
            assertEquals("Wrong number of offline messages", 2, offlineManager.getMessageCount());

            // User2 becomes available again
            PacketCollector collector = getConnection(1).createPacketCollector(
                    new MessageTypeFilter(Message.Type.chat));
            getConnection(1).sendPacket(new Presence(Presence.Type.available));

            // Check that no offline messages was sent to the user
            Message message = (Message) collector.nextResult(2500);
            assertNull("An offline message was sent from the server", message);

View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.packet.Presence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.