Java 类org.jivesoftware.smackx.muc.Occupant 实例源码

项目:Zom-Android    文件:XmppConnection.java   
@Override
public void joined(EntityFullJid entityFullJid) {
     XmppAddress xa = new XmppAddress(entityFullJid.toString());
     ChatGroup chatGroup = mChatGroupManager.getChatGroup(xa);
     MultiUserChat muc = mChatGroupManager.getMultiUserChat(entityFullJid.asBareJid().toString());

     Occupant occupant = muc.getOccupant(entityFullJid);
     Jid jidSource = (occupant != null) ? occupant.getJid() : null;
     if (jidSource != null)
     xa = new XmppAddress(jidSource.toString());
     else
     xa = new XmppAddress(entityFullJid.toString());

     Contact mucContact = new Contact(xa, xa.getUser(), Imps.Contacts.TYPE_NORMAL);
     chatGroup.notifyMemberJoined(entityFullJid.toString(),mucContact);
    if (occupant != null) {
        chatGroup.notifyMemberRoleUpdate(mucContact, occupant.getRole().name(), occupant.getAffiliation().toString());
    }
}
项目:jabbot    文件:PrivilegeMapper.java   
public Privilege getResourcePrivileges(Resource resource, Resource target){
    MultiUserChat chatroom = MultiUserChatManager.getInstanceFor(connection).getMultiUserChat(resource.getAddress());
    String occupantAddress = resource.getAddress()+"/"+resource.getName();
    Occupant o = chatroom.getOccupant(occupantAddress);
    switch(o.getRole()){
        case moderator: return Privilege.MODERATOR;
        default: return Privilege.USER;
    }
}
项目:aceim    文件:XMPPEntityAdapter.java   
private void fillMUCGroup(Collection<Occupant> occupants, BuddyGroup group, Map<String, Buddy> map) {
    for (Occupant occu : occupants){
        String occupantJid = normalizeJID(occu.getJid());
        Buddy occupant = map.remove(occupantJid);
        if (occupant != null) {
            group.getBuddyList().add(occupant);
        }
    }       
}
项目:spark-svn-mirror    文件:UserManager.java   
/**
 * Checks to see if the user is an owner of the specified room.
 *
 * @param groupChatRoom the group chat room.
 * @param nickname      the user's nickname.
 * @return true if the user is an owner.
 */
public boolean isOwner(GroupChatRoom groupChatRoom, String nickname) {
    Occupant occupant = getOccupant(groupChatRoom, nickname);
    if (occupant != null) {
        String affiliation = occupant.getAffiliation();
        if ("owner".equals(affiliation)) {
            return true;
        }
    }
    return false;
}
项目:spark-svn-mirror    文件:UserManager.java   
/**
 * Checks to see if the Occupant is the owner of the room.
 *
 * @param occupant the occupant of a room.
 * @return true if the user is an owner.
 */
public boolean isOwner(Occupant occupant) {
    if (occupant != null) {
        String affiliation = occupant.getAffiliation();
        if ("owner".equals(affiliation)) {
            return true;
        }
    }
    return false;
}
项目:spark-svn-mirror    文件:UserManager.java   
/**
    * Checks if the Occupant is a Member in this Room<br>
    * <b>admins and owners are also members!!!</b>
    * @param occupant
    * @return true if member, else false
    */
   public boolean isMember(Occupant occupant) {
if (occupant != null) {
    String affiliation = occupant.getAffiliation();
    if ("member".equals(affiliation) || affiliation.equals("owner")
        || affiliation.equals("admin")) {
    return true;
    }
}
return false;
   }
项目:spark-svn-mirror    文件:UserManager.java   
/**
 * Checks to see if the Occupant is a moderator.
 *
 * @param groupChatRoom the group chat room.
 * @param nickname      the nickname of the user.
 * @return true if the user is a moderator.
 */
public boolean isModerator(GroupChatRoom groupChatRoom, String nickname) {
    Occupant occupant = getOccupant(groupChatRoom, nickname);
    if (occupant != null) {
        String role = occupant.getRole();
        if ("moderator".equals(role)) {
            return true;
        }
    }
    return false;
}
项目:spark-svn-mirror    文件:UserManager.java   
/**
 * Checks to see if the Occupant is a moderator.
 *
 * @param occupant the Occupant of a room.
 * @return true if the user is a moderator.
 */
public boolean isModerator(Occupant occupant) {
    if (occupant != null) {
        String role = occupant.getRole();
        if ("moderator".equals(role)) {
            return true;
        }
    }
    return false;
}
项目:spark-svn-mirror    文件:UserManager.java   
/**
 * Checks to see if the user is either an owner or admin of a room.
 *
 * @param groupChatRoom the group chat room.
 * @param nickname      the user's nickname.
 * @return true if the user is either an owner or admin of the room.
 */
public boolean isOwnerOrAdmin(GroupChatRoom groupChatRoom, String nickname) {
    Occupant occupant = getOccupant(groupChatRoom, nickname);
    if (occupant != null) {
        String affiliation = occupant.getAffiliation();
        if ("owner".equals(affiliation) || "admin".equals(affiliation)) {
            return true;
        }
    }
    return false;
}
项目:spark-svn-mirror    文件:UserManager.java   
/**
 * Checks to see if the user is either an owner or admin of the given room.
 *
 * @param occupant the <code>Occupant</code> to check.
 * @return true if the user is either an owner or admin of the room.
 */
public boolean isOwnerOrAdmin(Occupant occupant) {
    if (occupant != null) {
        String affiliation = occupant.getAffiliation();
        if ("owner".equals(affiliation) || "admin".equals(affiliation)) {
            return true;
        }
    }
    return false;
}
项目:spark-svn-mirror    文件:UserManager.java   
/**
 * Returns the occupant of the room identified by their nickname.
 *
 * @param groupChatRoom the GroupChatRoom.
 * @param nickname      the users nickname.
 * @return the Occupant found.
 */
public Occupant getOccupant(GroupChatRoom groupChatRoom, String nickname) {
    String userJID = groupChatRoom.getRoomname() + "/" + nickname;
    Occupant occ = null;
    try {
        occ = groupChatRoom.getMultiUserChat().getOccupant(userJID);
    }
    catch (Exception e) {
        Log.error(e);
    }
    return occ;
}
项目:spark-svn-mirror    文件:UserManager.java   
public boolean hasVoice(GroupChatRoom groupChatRoom, String nickname) {
    Occupant occupant = getOccupant(groupChatRoom, nickname);
    if (occupant != null) {
        String role = occupant.getRole();
        if ("visitor".equals(role)) {
            return false;
        }
    }
    return true;
}
项目:spark-svn-mirror    文件:GroupChatParticipantList.java   
protected void banUser(String displayName) {
    try {
        Occupant occupant = chat.getOccupant(userMap.get(displayName));
        if (occupant != null) {
            String bareJID = StringUtils
                    .parseBareAddress(occupant.getJid());
            chat.banUser(bareJID, Res
                    .getString("message.you.have.been.banned"));
        }
    } catch (XMPPException e) {
        groupChatRoom.getTranscriptWindow().
        insertNotificationMessage("No can do "+e.getMessage(), ChatManager.ERROR_COLOR);
    }
}
项目:spark-svn-mirror    文件:GroupChatParticipantList.java   
protected void grantMember(String nickname) {
try {
    Occupant o = userManager.getOccupant(groupChatRoom,nickname);
    nickname = StringUtils.parseBareAddress(o.getJid());
    chat.grantMembership(nickname);

} catch (XMPPException e) {
    groupChatRoom.getTranscriptWindow().insertNotificationMessage(
        "No can do " + e.getMessage(), ChatManager.ERROR_COLOR);
}
   }
项目:spark-svn-mirror    文件:GroupChatParticipantList.java   
protected void revokeMember(String nickname) {
try {
    Occupant o = userManager.getOccupant(groupChatRoom,nickname);
    nickname = StringUtils.parseBareAddress(o.getJid());
    chat.revokeMembership(nickname);
} catch (XMPPException e) {
    groupChatRoom.getTranscriptWindow().insertNotificationMessage(
        "No can do " + e.getMessage(), ChatManager.ERROR_COLOR);
}
   }
项目:spark-svn-mirror    文件:GroupChatParticipantList.java   
protected void grantAdmin(String nickname) {
try {
    Occupant o = userManager.getOccupant(groupChatRoom,nickname);
    nickname = StringUtils.parseBareAddress(o.getJid());
    chat.grantAdmin(nickname);
} catch (XMPPException e) {
    groupChatRoom.getTranscriptWindow().insertNotificationMessage(
        "No can do " + e.getMessage(), ChatManager.ERROR_COLOR);
}
   }
项目:spark-svn-mirror    文件:GroupChatParticipantList.java   
protected void revokeAdmin(String nickname) {
try {
    Occupant o = userManager.getOccupant(groupChatRoom,nickname);
    nickname = StringUtils.parseBareAddress(o.getJid());
    chat.revokeAdmin(nickname);
} catch (XMPPException e) {
    groupChatRoom.getTranscriptWindow().insertNotificationMessage(
        "No can do " + e.getMessage(), ChatManager.ERROR_COLOR);
}
   }
项目:spark-svn-mirror    文件:GroupChatParticipantList.java   
protected void grantOwner(String nickname) {
try {
    Occupant o = userManager.getOccupant(groupChatRoom,nickname);
    nickname = StringUtils.parseBareAddress(o.getJid());
    chat.grantOwnership(nickname);
} catch (XMPPException e) {
    groupChatRoom.getTranscriptWindow().insertNotificationMessage(
        "No can do " + e.getMessage(), ChatManager.ERROR_COLOR);
}
   }
项目:spark-svn-mirror    文件:GroupChatParticipantList.java   
protected void revokeOwner(String nickname) {
try {
    Occupant o = userManager.getOccupant(groupChatRoom,nickname);
    nickname = StringUtils.parseBareAddress(o.getJid());
    chat.revokeOwnership(nickname);
} catch (XMPPException e) {
    groupChatRoom.getTranscriptWindow().insertNotificationMessage(
        "No can do " + e.getMessage(), ChatManager.ERROR_COLOR);
}
   }
项目:aceim    文件:XMPPEntityAdapter.java   
public List<BuddyGroup> xmppMUCOccupants2mcrOccupants(XMPPServiceInternal service, MultiUserChat muc, boolean loadIcons) {
    List<BuddyGroup> groups = new ArrayList<BuddyGroup>();
    String ownerJid = service.getOnlineInfo().getProtocolUid();

    BuddyGroup moderators = new BuddyGroup(Integer.toString(2), ownerJid, service.getOnlineInfo().getServiceId());
    BuddyGroup participants = new BuddyGroup(Integer.toString(5), ownerJid, service.getOnlineInfo().getServiceId());
    BuddyGroup other = new BuddyGroup(Integer.toString(7), ownerJid, service.getOnlineInfo().getServiceId());
    BuddyGroup all = new BuddyGroup(Integer.toString(8), ownerJid, service.getOnlineInfo().getServiceId());
    //TODO
    moderators.setName("Moderators");
    participants.setName("Participants");
    other.setName("Other");
    all.setName("All");

    Map<String, Buddy> buddies = new HashMap<String, Buddy>();

    Iterator<String> it = muc.getOccupants(); 

    for (;it.hasNext();){
        String occupant = it.next();
        String buddyId;
        Occupant occu = muc.getOccupant(occupant);
        if (occu != null && occu.getJid() != null){
            buddyId = normalizeJID(occu.getJid());
            if (loadIcons){
                try {
                    service.loadCard(buddyId);
                } catch (Exception e) {
                    Logger.log(e);
                }
            }
        } else {
            buddyId = occupant;
        }
        Buddy buddy = new Buddy(buddyId, ownerJid, XMPPApiConstants.PROTOCOL_NAME, service.getOnlineInfo().getServiceId());
        buddy.setName(buddyId.equals(occupant) ? StringUtils.parseResource(occupant) : occu.getNick());
        buddy.getOnlineInfo().getFeatures().putByte(ApiConstants.FEATURE_STATUS, xmppPresence2UserStatus(muc.getOccupantPresence(occupant)));

        buddies.put(buddy.getProtocolUid(), buddy);
        buddy.setId(buddyId.hashCode());
        all.getBuddyList().add(buddy);
    }

    try {
        fillMUCGroup(muc.getParticipants(), participants, buddies);
        fillMUCGroup(muc.getModerators(), moderators, buddies);
        other.getBuddyList().addAll(buddies.values());

        groups.add(moderators);
        groups.add(participants);
        groups.add(other);
    } catch (Exception e1) {
        Logger.log(e1);
    }

    if (groups.size() < 1){
        groups.add(all);            
    }

    return groups;
}
项目:spark-svn-mirror    文件:GroupChatParticipantList.java   
protected void addParticipant(final String participantJID, Presence presence, String userJID) {
// Remove reference to invitees

for (String displayName : invitees.keySet()) {
    String jid = SparkManager.getUserManager().getJIDFromDisplayName(
        displayName);

    Occupant occ = chat.getOccupant(participantJID);
    if (occ != null) {
    String actualJID = occ.getJid();
    if (actualJID.equals(jid)) {
        removeUser(displayName);
    }
    }
}

String nickname = StringUtils.parseResource(participantJID);

String affiliation  = parseRoleFromPacket(presence)[0];
String userRole = parseRoleFromPacket(presence)[1];

usersandRoles.put(participantJID, affiliation+","+userRole);

Icon icon = null;
if (_localPreferences.isShowingRoleIcons()) {
    icon = getIconForRole(userRole, affiliation);
} else {
    Presence jidPresence = PresenceManager.getPresence(userJID);
    icon = PresenceManager.getIconFromPresence(jidPresence);
    if (icon == null) {
    icon = SparkRes.getImageIcon(SparkRes.GREEN_BALL);
    }
}

if (!exists(nickname)) {
    addUser(icon, nickname);
} else {
    int index = getIndex(nickname);
    if (index != -1) {
    final JLabel userLabel = new JLabel(nickname, icon,
        JLabel.HORIZONTAL);
    model.setElementAt(userLabel, index);
    }
}
   }