Пример #1
0
        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();
        }
 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);
   }
 }
Пример #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;
  }
Пример #4
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);
  }
Пример #5
0
  // carefull, this method does also get called by the SmackListener Thread
  @Override
  public void presenceChanged(Presence presence) {
    String bareUserId = StringUtils.parseBareAddress(presence.getFrom());

    Intent intent = new Intent(MainService.ACTION_XMPP_PRESENCE_CHANGED);
    intent.putExtra("userid", bareUserId);
    intent.putExtra("fullid", presence.getFrom());
    intent.putExtra("state", retrieveState(presence.getMode(), presence.isAvailable()));
    intent.putExtra("status", presence.getStatus());
    sContext.sendBroadcast(intent);

    // TODO Make this a general intent action.NOTIFICATION_ADDRESS_AVAILABLE
    // and handle it for example within XmppPresenceStatus
    // if the notification address is/has become available, update the resource status string
    if (sSettings.containsNotifiedAddress(bareUserId) && presence.isAvailable()) {
      intent = new Intent(MainService.ACTION_COMMAND);
      intent.setClass(sContext, MainService.class);
      intent.putExtra("cmd", "batt");
      intent.putExtra("args", "silent");
      MainService.sendToServiceHandler(intent);
    }
  }
Пример #6
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;
  }
Пример #7
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;
 }
Пример #8
0
  /**
   * Returns the RQ-JIDs of all presences of the given (plain) JID which are available.
   *
   * <p>An empty list is returned if no presence for the given JID is online.
   */
  public List<JID> getAvailablePresences(JID from) {

    List<JID> result = new ArrayList<JID>();

    for (Presence presence : getPresences(from)) {
      if (!presence.isAvailable()) continue;

      String rjid = presence.getFrom();
      if (rjid == null) {
        LOG.error("presence.getFrom() is null");
        continue;
      }
      result.add(new JID(rjid));
    }

    return result;
  }
Пример #9
0
  /**
   * Returns the RQ-JID of given plain JID supporting the feature of the given name-space if
   * available, otherwise null.
   *
   * <p>If not in the cache then a blocking cache update is performed.
   *
   * @param jid The JID of the user to find a supporting presence for. The JID can be resource
   *     qualified in which case the resource is stripped, before performing the look-up.
   * @blocking This method blocks until the ServiceDiscovery returns.
   * @reentrant This method can be called concurrently.
   * @caching If results are available in the cache, they are used instead of querying the server.
   */
  public JID getSupportingPresence(final JID jid, final String namespace) {
    checkJID(jid);

    for (Presence presence : rosterTracker.getPresences(jid.getBareJID())) {
      if (!presence.isAvailable()) continue;

      String rjid = presence.getFrom();
      if (rjid == null) {
        LOG.error("presence.getFrom() is null");
        continue;
      }

      JID jidToCheck = new JID(rjid);
      Boolean supported = queryFeatureSupport(jidToCheck, namespace);

      if (supported != null && supported) return jidToCheck;
    }

    return null;
  }
Пример #10
0
  /**
   * Handles presence stanzas
   *
   * @param presence
   */
  private void handlePresence(Presence presence) {
    // unavailable is sent when user leaves the room
    if (!presence.isAvailable()) {
      return;
    }

    String from = presence.getFrom();
    JitsiMeetConference conference = getConferenceForMucJid(from);

    if (conference == null) {
      if (logger.isDebugEnabled()) {
        logger.debug("Room not found for JID: " + from);
      }
      return;
    }

    ChatRoomMemberRole role = conference.getRoleForMucJid(from);

    if (role != null && role.compareTo(ChatRoomMemberRole.MODERATOR) < 0) {
      StartMutedPacketExtension ext =
          (StartMutedPacketExtension)
              presence.getExtension(
                  StartMutedPacketExtension.ELEMENT_NAME, StartMutedPacketExtension.NAMESPACE);

      if (ext != null) {
        boolean[] startMuted = {ext.getAudioMuted(), ext.getVideoMuted()};

        conference.setStartMuted(startMuted);
      }
    }

    Participant participant = conference.findParticipantForRoomJid(from);
    ColibriConference colibriConference = conference.getColibriConference();

    if (participant != null && colibriConference != null) {
      // Check if this conference is valid
      String conferenceId = colibriConference.getConferenceId();
      if (StringUtils.isNullOrEmpty(conferenceId)) {
        logger.error("Unable to send DisplayNameChanged event" + " - no conference id");
        return;
      }

      // Check for changes to the display name
      String oldDisplayName = participant.getDisplayName();
      String newDisplayName = null;
      for (PacketExtension pe : presence.getExtensions()) {
        if (pe instanceof Nick) {
          newDisplayName = ((Nick) pe).getName();
          break;
        }
      }

      if (!Objects.equals(oldDisplayName, newDisplayName)) {
        participant.setDisplayName(newDisplayName);

        EventAdmin eventAdmin = FocusBundleActivator.getEventAdmin();
        if (eventAdmin != null) {
          // Prevent NPE when adding to event hashtable
          if (newDisplayName == null) {
            newDisplayName = "";
          }
          eventAdmin.sendEvent(
              EventFactory.endpointDisplayNameChanged(
                  conferenceId, participant.getEndpointId(), newDisplayName));
        }
      }
    }
  }
Пример #11
0
  /**
   * Updates the icon of the user based on their presence.
   *
   * @param presence the users presence.
   */
  public void updatePresenceIcon(Presence presence) {
    ChatManager chatManager = SparkManager.getChatManager();
    boolean handled = chatManager.fireContactItemPresenceChanged(this, presence);
    if (handled) {
      return;
    }

    String status = presence.getStatus();
    Icon statusIcon = SparkRes.getImageIcon(SparkRes.GREEN_BALL);
    boolean isAvailable = false;
    if (status == null && presence.isAvailable()) {
      Presence.Mode mode = presence.getMode();
      if (mode == Presence.Mode.available) {
        status = Res.getString("status.online");
        isAvailable = true;
      } else if (mode == Presence.Mode.away) {
        status = Res.getString("status.away");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      } else if (mode == Presence.Mode.chat) {
        status = Res.getString("status.free.to.chat");
      } else if (mode == Presence.Mode.dnd) {
        status = Res.getString("status.do.not.disturb");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      } else if (mode == Presence.Mode.xa) {
        status = Res.getString("status.extended.away");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      }
    }

    if (presence.isAvailable()
        && (presence.getMode() == Presence.Mode.dnd
            || presence.getMode() == Presence.Mode.away
            || presence.getMode() == Presence.Mode.xa)) {
      statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
    } else if (presence.isAvailable()) {
      isAvailable = true;
    } else if (!presence.isAvailable()) {
      getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
      getNicknameLabel().setForeground((Color) UIManager.get("ContactItemOffline.color"));

      RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getJID());
      if (entry != null
          && (entry.getType() == RosterPacket.ItemType.none
              || entry.getType() == RosterPacket.ItemType.from)
          && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
        // Do not move out of group.
        setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION));
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        setStatusText(Res.getString("status.pending"));
      } else {
        // We should keep the offline bullet (not available) instead of putting icon null.
        setIcon(SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON));
        setFont(new Font("Dialog", Font.PLAIN, fontSize));
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        setAvailable(false);
        if (ModelUtil.hasLength(status)) {
          setStatusText(status);
        } else {
          setStatusText("");
        }
      }

      sideIcon.setIcon(null);
      setAvailable(false);
      return;
    }

    Icon sIcon = PresenceManager.getIconFromPresence(presence);
    if (sIcon != null) {
      setIcon(sIcon);
    } else {
      setIcon(statusIcon);
    }
    if (status != null) {
      setStatus(status);
    }

    if (PresenceManager.isOnPhone(presence)) {
      statusIcon = SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE);
      setIcon(statusIcon);
    }

    // Always change nickname label to black.
    getNicknameLabel().setForeground((Color) UIManager.get("ContactItemNickname.foreground"));

    if (isAvailable) {
      getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
      if (Res.getString("status.online").equals(status)
          || Res.getString("available").equalsIgnoreCase(status)) {
        setStatusText("");
      } else {
        setStatusText(status);
      }
    } else if (presence.isAvailable()) {
      LocalPreferences pref = SettingsManager.getLocalPreferences();
      if (pref.isGrayingOutEnabled()) {
        getNicknameLabel().setFont(new Font("Dialog", Font.ITALIC, fontSize));
        getNicknameLabel().setForeground(Color.gray);
      } else {
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        getNicknameLabel().setForeground(Color.black);
      }
      if (status != null) {
        setStatusText(status);
      }
    }

    setAvailable(true);
  }
Пример #12
0
 private boolean isOnline() {
   Presence presence = roster.getPresence(getParticipantJID());
   return presence.isAvailable();
 }