Esempio n. 1
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;
  }
Esempio n. 2
0
 public void addFriend(String userID) {
   if (sRoster != null) {
     if (!sRoster.contains(userID)) {
       try {
         sRoster.createEntry(userID, StringUtils.parseBareAddress(userID), null);
         retrieveFriendList();
       } catch (XMPPException e) {
         System.err.println("Error in adding friend " + e.getMessage());
       }
     } else {
       RosterEntry rosterEntry = sRoster.getEntry(userID);
       RosterPacket.ItemType type = rosterEntry.getType();
       switch (type) {
         case from:
           requestSubscription(userID, sConnection);
           break;
         case to:
           grantSubscription(userID, sConnection);
           break;
         case none:
           grantSubscription(userID, sConnection);
           requestSubscription(userID, sConnection);
           break;
         case both:
         default:
           break;
       }
     }
   }
 }
Esempio n. 3
0
 static RosterPacket.Item toRosterItem(RosterEntry entry) {
   RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName());
   item.setItemType(entry.getType());
   item.setItemStatus(entry.getStatus());
   // Set the correct group names for the item.
   for (RosterGroup group : entry.getGroups()) {
     item.addGroupName(group.getName());
   }
   return item;
 }
Esempio n. 4
0
  public SubscribeInfo processSubscribe(String from) throws SmackInvocationException {
    SubscribeInfo result = new SubscribeInfo();

    RosterEntry rosterEntry = contactHelper.getRosterEntry(from);
    ItemType rosterType = rosterEntry != null ? rosterEntry.getType() : null;

    if (rosterEntry == null || rosterType == ItemType.none) {
      result.setType(SubscribeInfo.TYPE_WAIT_FOR_APPROVAL);
      result.setNickname(getNickname(from));
    } else if (rosterType == ItemType.to) {
      result.setType(SubscribeInfo.TYPE_APPROVED);
      result.setNickname(rosterEntry.getName());

      approveSubscription(from, null, false);
    }

    result.setFrom(from);
    return result;
  }
Esempio n. 5
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);
  }