Beispiel #1
0
 private Presence enter$324fb5b(String nickname, long timeout)
     throws NotConnectedException, NoResponseException, XMPPErrorException {
   if (StringUtils.isNullOrEmpty(nickname)) {
     throw new IllegalArgumentException("Nickname must not be null or blank.");
   }
   Presence joinPresence = new Presence(Type.available);
   joinPresence.to = this.room + MqttTopic.TOPIC_LEVEL_SEPARATOR + nickname;
   joinPresence.addExtension(new MUCInitialPresence());
   for (PacketInterceptor interceptPacket : this.presenceInterceptors) {
     interceptPacket.interceptPacket(joinPresence);
   }
   PacketCollector response =
       this.connection.createPacketCollector(
           new AndFilter(
               FromMatchesFilter.createFull(
                   this.room + MqttTopic.TOPIC_LEVEL_SEPARATOR + nickname),
               new PacketTypeFilter(Presence.class)));
   this.connection.sendPacket(joinPresence);
   Presence presence = (Presence) response.nextResultOrThrow(timeout);
   this.nickname = nickname;
   this.joined = true;
   List<String> rooms = (List) joinedRooms.get(this.connection);
   if (rooms == null) {
     rooms = new ArrayList();
     joinedRooms.put(this.connection, rooms);
   }
   rooms.add(this.room);
   return presence;
 }
Beispiel #2
0
  /**
   * @see net.sf.kraken.session.TransportSession#sendChatState(org.xmpp.packet.JID,
   *     net.sf.kraken.type.ChatStateType)
   */
  @Override
  public void sendChatState(JID jid, ChatStateType chatState) {
    final Presence presence = conn.getRoster().getPresence(jid.toString());
    if (presence == null || presence.getType().equals(Presence.Type.unavailable)) {
      // don't send chat state to contacts that are offline.
      return;
    }
    Chat chat = conn.getChatManager().createChat(getTransport().convertJIDToID(jid), listener);
    try {
      ChatState state = ChatState.active;
      switch (chatState) {
        case active:
          state = ChatState.active;
          break;
        case composing:
          state = ChatState.composing;
          break;
        case paused:
          state = ChatState.paused;
          break;
        case inactive:
          state = ChatState.inactive;
          break;
        case gone:
          state = ChatState.gone;
          break;
      }

      Message message = new Message();
      message.addExtension(new ChatStateExtension(state));
      chat.sendMessage(message);
    } catch (XMPPException e) {
      // Ignore
    }
  }
Beispiel #3
0
  /**
   * 根据RosterEntry创建一个User
   *
   * @param entry
   * @return
   */
  public User transEntryToUser(RosterEntry entry, Roster roster) {
    User user = new User();
    user.setJID(entry.getUser());
    Presence presence = roster.getPresence(entry.getUser());
    user.setFrom(presence.getFrom());
    user.setStatus(presence.getStatus());
    user.setAvailable(presence.isAvailable());
    user.setType(entry.getType());

    // user.setvCard(userManager.getUserVCard(entry.getUser()));
    if (entry.getName() == null) {
      //			if(user.getvCard()==null)
      //			user.setName(StringUtil.getUserNameByJid(entry.getUser()));
      //			else {
      //				user.setName(user.getvCard().getNickName());
      //			}
      user.setName(StringUtil.getUserNameByJid(entry.getUser()));
    } else {
      user.setName(entry.getName());
    }
    String avatar = UserManager.saveAvatar(entry.getUser(), context);
    user.setAvatar_path(avatar);

    return user;
  }
Beispiel #4
0
 public void sendPresenceRequest(String user, String type) {
   // HACK: remove the fake roster entry added by handleIncomingSubscribe()
   if ("unsubscribed".equals(type)) deleteRosterEntryFromDB(user);
   Presence response = new Presence(Presence.Type.valueOf(type));
   response.setTo(user);
   mXMPPConnection.sendPacket(response);
 }
 public void updateUser(Presence presence) {
   boolean newUser = true;
   Contact removeC = null;
   for (Contact c : contactList) {
     if (c.getRosterEntry().getUser().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
       newUser = false;
       if (!(presence.isAvailable() || presence.isAway())) {
         removeC = c;
       }
       break;
     }
   }
   if (removeC != null) {
     contactList.remove(removeC);
   }
   if (newUser) {
     RosterEntry re = roster.getEntry(StringUtils.parseBareAddress(presence.getFrom()));
     Contact c = new Contact();
     if (re.getName() == null || re.getName().trim().equals("")) c.setName(re.getUser());
     else c.setName(re.getName());
     c.setStatus(presence.getStatus());
     c.setRosterEntry(re);
     contactList.add(c);
   }
 }
  @Override
  public void presenceChanged(Presence presence) {

    log.info("Presence Updated: " + presence.getFrom());

    updated = true;
    presenceChanged.add(presence.getFrom());
  }
        private boolean hasOnlineStateChanged(Presence presence) {
          Presence last = lastPresenceMap.get(presence.getFrom());
          lastPresenceMap.put(presence.getFrom(), presence);

          if (last == null) return false;

          return last.isAvailable() ^ presence.isAvailable();
        }
Beispiel #8
0
  /** @see net.sf.kraken.session.TransportSession#acceptAddContact(JID) */
  @Override
  public void acceptAddContact(JID jid) {
    final String userID = getTransport().convertJIDToID(jid);
    Log.debug("XMPP: accept-add contact: " + userID);

    final Presence accept = new Presence(Type.subscribed);
    accept.setTo(userID);
    conn.sendPacket(accept);
  }
Beispiel #9
0
 public void interceptPacket(Packet packet) {
   Presence presence = (Presence) packet;
   // Check if user is joining a room
   if (Presence.Type.available == presence.getType()
       && presence.getExtension("x", "http://jabber.org/protocol/muc") != null) {
     // Add extension that indicates that user wants to be a deaf occupant
     packet.addExtension(new DeafExtension());
   }
 }
Beispiel #10
0
  /**
   * Updates user's changed presence
   *
   * @param presence
   */
  public void presenceChanged(Presence presence) {

    String from = presence.getFrom();

    // Log.i(tag, presence.getMode().toString());
    new BuddiesController(context)
        .notifyPresenceChanged(from, presence.getMode(), presence.getStatus());
    return;
  }
 private Packet getPresenceForMode(FriendPresence.Mode mode) {
   org.jivesoftware.smack.packet.Presence presence =
       new org.jivesoftware.smack.packet.Presence(
           org.jivesoftware.smack.packet.Presence.Type.available);
   presence.setMode(org.jivesoftware.smack.packet.Presence.Mode.valueOf(mode.name()));
   if (jabberSettings.advertiseLimeWireStatus()) {
     presence.setStatus("on LimeWire");
   }
   return presence;
 }
Beispiel #12
0
  /*
   * (non-Javadoc)
   *
   * @see
   * fr.univartois.ili.fsnet.commons.talk.ITalk#sendPresence(java.lang.String)
   */
  @Override
  public void sendPresence(String status) {

    Presence presence = new Presence(Type.available, status, 10, Mode.available);
    if (status.equals("offline")) {
      presence.setType(Type.unavailable);
      presence.setMode(Mode.away);
    }
    connection.sendPacket(presence);
  }
Beispiel #13
0
  public void reconnectionSuccessful() {
    Presence usersPresence = PresenceManager.getPresence(getParticipantJID());
    if (usersPresence.isAvailable()) {
      presence = usersPresence;
    }

    SparkManager.getChatManager().getChatContainer().fireChatRoomStateUpdated(this);
    getChatInputEditor().setEnabled(true);
    getSendButton().setEnabled(true);
  }
 private StatusMode getStatus(Presence presence) {
   if (presence.getType() == Presence.Type.subscribe) return StatusMode.subscribe;
   if (presence.getType() == Presence.Type.available) {
     if (presence.getMode() != null) {
       return StatusMode.valueOf(presence.getMode().name());
     }
     return StatusMode.available;
   }
   return StatusMode.offline;
 }
 private String getCurrentJabberID(User user, RosterEntry rosterEntry) {
   Presence presence = _getPresence(user);
   String jabberId = null;
   if (presence != null) {
     jabberId = presence.getFrom();
   }
   if (jabberId == null) jabberId = rosterEntry.getUser();
   if (jabberId == null) jabberId = rosterEntry.getName();
   return jabberId;
 }
Beispiel #16
0
 Occupant(Presence presence) {
   super();
   MUCUser mucUser = (MUCUser) presence.getExtension("x", "http://jabber.org/protocol/muc#user");
   MUCUser.Item item = mucUser.getItem();
   this.jid = item.getJid();
   this.affiliation = item.getAffiliation();
   this.role = item.getRole();
   // Get the nickname from the FROM attribute of the presence
   this.nick = StringUtils.parseResource(presence.getFrom());
 }
 @Override
 public void presenceChanged(Presence presence) {
   final User user = getUser(presence.getFrom(), true, false);
   if (user == null) {
     return;
   }
   user.setUserState(new UserState(presence));
   user.setAvatar(service.getAvatarService().getAvatar(user));
   user.setRessource(StringUtils.parseResource(presence.getFrom()));
   service.sendRosterUpdated(user);
 }
Beispiel #18
0
 /**
  * There are two ways we initially learn about new peers. The first is a Lantern peer directly on
  * our roster, which will produce this event. The second is a kaleidoscope advertisement. Those
  * Kaleidoscope advertisements can be from peers on our roster, but they can also be from peers
  * we're not directly connected to. This method captures the first case where peers on our roster
  * are running Lantern.
  *
  * @param event The update presence event.
  */
 @Subscribe
 public void onUpdatePresenceEvent(final UpdatePresenceEvent event) {
   log.debug("Processing presence event");
   final Presence presence = event.getPresence();
   final String from = presence.getFrom();
   if (StringUtils.isBlank(from)) {
     log.warn("Presence with blank from?");
   } else {
     addPeer(LanternUtils.newURI(from), Type.pc);
   }
 }
Beispiel #19
0
  /*
   * (non-Javadoc)
   *
   * @see
   * fr.univartois.ili.fsnet.commons.talk.ITalk#subscribe(java.lang.String)
   */
  @Override
  public void subscribe(String user) {

    Presence presence = new Presence(Presence.Type.subscribe, "subscribe", 10, Mode.available);
    presence.setTo(user);
    connection.sendPacket(presence);

    presence = new Presence(Presence.Type.subscribed);
    presence.setTo(user);
    connection.sendPacket(presence);
  }
  public void setStatusFromConfig() {
    CarbonManager.getInstanceFor(extXMPPConnection)
        .sendCarbonsEnabled(configuration.messageCarbons);

    Presence presence = new Presence(Presence.Type.available);
    Mode mode = Mode.valueOf(configuration.statusMode);
    presence.setMode(mode);
    presence.setStatus(configuration.statusMessage);
    presence.setPriority(configuration.priority);
    extXMPPConnection.sendPacket(presence);
    configuration.presence_required = false;
  }
Beispiel #21
0
  public void setStatusFromConfig() {
    // TODO: only call this when carbons changed, not on every presence change
    CarbonManager.getInstanceFor(mXMPPConnection).sendCarbonsEnabled(mConfig.messageCarbons);

    Presence presence = new Presence(Presence.Type.available);
    Mode mode = Mode.valueOf(mConfig.statusMode);
    presence.setMode(mode);
    presence.setStatus(mConfig.statusMessage);
    presence.setPriority(mConfig.priority);
    mXMPPConnection.sendPacket(presence);
    mConfig.presence_required = false;
  }
  private void handleIncomingSubscribe(Presence request) {
    final ContentValues values = new ContentValues();

    values.put(RosterConstants.JID, request.getFrom());
    values.put(RosterConstants.ALIAS, request.getFrom());
    values.put(RosterConstants.GROUP, "");

    values.put(RosterConstants.STATUS_MODE, getStatusInt(request));
    values.put(RosterConstants.STATUS_MESSAGE, request.getStatus());

    Uri uri = contentResolver.insert(RosterProvider.CONTENT_URI, values);
    Log.d(TAG, "handleIncomingSubscribe: faked " + uri);
  }
Beispiel #23
0
  public int retrieveState(String userID) {
    int userState = XmppFriend.OFFLINE; // default return value
    Presence userFromServer = null;

    try {
      userFromServer = sConnection.getRoster().getPresence(userID);
      userState = retrieveState(userFromServer.getMode(), userFromServer.isAvailable());
    } catch (NullPointerException e) {
      Log.e("retrieveState(): Invalid connection or user - NPE", e);
    }

    return userState;
  }
Beispiel #24
0
  /*
   * (non-Javadoc)
   *
   * @see
   * fr.univartois.ili.fsnet.commons.talk.ITalk#unSubscribe(java.lang.String)
   */
  @Override
  public void unSubscribe(String user) {
    /*
     * The Mode referring one of the 5 Mode available in XMPP server. The text message is just a description.
     */
    Presence presence = new Presence(Presence.Type.unsubscribe, "unsubscribe", 10, Mode.available);
    presence.setTo(user);
    connection.sendPacket(presence);

    presence = new Presence(Presence.Type.unsubscribed);
    presence.setTo(user);
    connection.sendPacket(presence);
  }
Beispiel #25
0
  /**
   * Returns true if the workgroup is available for receiving new requests. The workgroup will be
   * available only when agents are available for this workgroup.
   *
   * @return true if the workgroup is available for receiving new requests.
   * @throws XMPPException
   */
  public boolean isAvailable() throws XMPPException {
    Presence directedPresence = new Presence(Presence.Type.available);
    directedPresence.setTo(workgroupJID);
    PacketFilter typeFilter = new PacketTypeFilter(Presence.class);
    PacketFilter fromFilter = FromMatchesFilter.create(workgroupJID);
    PacketCollector collector =
        connection.createPacketCollector(new AndFilter(fromFilter, typeFilter));

    connection.sendPacket(directedPresence);

    Presence response = (Presence) collector.nextResultOrThrow();
    return Presence.Type.available == response.getType();
  }
Beispiel #26
0
  private ContentValues getContentValuesForRosterEntry(final RosterEntry entry) {
    final ContentValues values = new ContentValues();

    values.put(RosterConstants.JID, entry.getUser());
    values.put(RosterConstants.ALIAS, getName(entry));

    Presence presence = mRoster.getPresence(entry.getUser());
    values.put(RosterConstants.STATUS_MODE, getStatusInt(presence));
    values.put(RosterConstants.STATUS_MESSAGE, presence.getStatus());
    values.put(RosterConstants.GROUP, getGroup(entry.getGroups()));

    return values;
  }
Beispiel #27
0
 private synchronized void leave() throws NotConnectedException {
   if (this.joined) {
     Presence leavePresence = new Presence(Type.unavailable);
     leavePresence.to = this.room + MqttTopic.TOPIC_LEVEL_SEPARATOR + this.nickname;
     for (PacketInterceptor interceptPacket : this.presenceInterceptors) {
       interceptPacket.interceptPacket(leavePresence);
     }
     this.connection.sendPacket(leavePresence);
     this.occupantsMap.clear();
     this.nickname = null;
     this.joined = false;
     userHasLeft();
   }
 }
  private void tryToRemoveRosterEntry(String user) throws ClientException {
    try {
      RosterEntry rosterEntry = roster.getEntry(user);

      if (rosterEntry != null) {

        Presence unsub = new Presence(Presence.Type.unsubscribed);
        unsub.setTo(rosterEntry.getUser());
        extXMPPConnection.sendPacket(unsub);
        roster.removeEntry(rosterEntry);
      }
    } catch (XMPPException e) {
      throw new ClientException("tryToRemoveRosterEntry", e);
    }
  }
Beispiel #29
0
 /**
  * Checks if the notification address is available return also true if no roster is loaded
  *
  * @return
  */
 public boolean isNotificationAddressAvailable() {
   if (sRoster != null) {
     // getPresence retrieves eventually the status of the notified Address in an internal data
     // structure cache
     // thus avoiding an extra data packet
     for (String notifiedAddress : sSettings.getNotifiedAddresses()) {
       Presence presence = sRoster.getPresence(notifiedAddress);
       if (presence.isAvailable()) {
         return true;
       }
     }
     return false;
   }
   return true;
 }
  private ContentValues getContentValuesForRosterEntry(final RosterEntry entry) {
    final ContentValues values = new ContentValues();

    values.put(RosterConstants.JID, entry.getUser());
    values.put(RosterConstants.ALIAS, getName(entry));

    Presence presence = roster.getPresence(entry.getUser());
    values.put(RosterConstants.STATUS_MODE, getStatusInt(presence));
    if (presence.getType() == Presence.Type.error) {
      values.put(RosterConstants.STATUS_MESSAGE, presence.getError().toString());
    } else values.put(RosterConstants.STATUS_MESSAGE, presence.getStatus());
    values.put(RosterConstants.GROUP, getGroup(entry.getGroups()));

    return values;
  }