示例#1
0
  @Override
  public void joinAs(String nickname, byte[] password) throws OperationFailedException {
    if (isJoined) throw new OperationFailedException("Alread joined the room", 0);

    isJoined = true;

    MockRoomMember member = new MockRoomMember(createAddressForName(nickname), this);

    // FIXME: for mock purposes we are always the owner on join()
    boolean isOwner = true; // = members.size() == 0;

    synchronized (members) {
      members.add(member);

      me = member;

      fireMemberPresenceEvent(me, me, ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED, null);
    }

    ChatRoomMemberRole oldRole = me.getRole();
    if (isOwner) {
      me.setRole(ChatRoomMemberRole.OWNER);
    }

    fireLocalUserRoleEvent(me, oldRole, true);
  }
示例#2
0
 public void mockLeave(String memberName) {
   for (ChatRoomMember member : members) {
     if (member.getName().equals(memberName)) {
       mockLeave((MockRoomMember) member);
     }
   }
 }
示例#3
0
  /**
   * Determines whether a specific <code>ChatRoom</code> is private i.e. represents a one-to-one
   * conversation which is not a channel. Since the interface {@link ChatRoom} does not expose the
   * private property, an heuristic is used as a workaround: (1) a system <code>ChatRoom</code> is
   * obviously not private and (2) a <code>ChatRoom</code> is private if it has only one <code>
   * ChatRoomMember</code> who is not the local user.
   *
   * @param chatRoom the <code>ChatRoom</code> to be determined as private or not
   * @return <tt>true</tt> if the specified <code>ChatRoom</code> is private; otherwise,
   *     <tt>false</tt>
   */
  public static boolean isPrivate(ChatRoom chatRoom) {
    if (!chatRoom.isSystem() && chatRoom.isJoined() && (chatRoom.getMembersCount() == 1)) {
      String nickname = chatRoom.getUserNickname();

      if (nickname != null) {
        for (ChatRoomMember member : chatRoom.getMembers())
          if (nickname.equals(member.getName())) return false;
        return true;
      }
    }
    return false;
  }
示例#4
0
  private void fireMemberRoleEvent(ChatRoomMember member, ChatRoomMemberRole oldRole) {
    ChatRoomMemberRoleChangeEvent evt =
        new ChatRoomMemberRoleChangeEvent(this, member, oldRole, member.getRole());

    Iterable<ChatRoomMemberRoleListener> listeners;
    synchronized (memberRoleListeners) {
      listeners = new ArrayList<ChatRoomMemberRoleListener>(memberRoleListeners);
    }

    for (ChatRoomMemberRoleListener listener : listeners) listener.memberRoleChanged(evt);
  }
示例#5
0
  private void fireLocalUserRoleEvent(
      ChatRoomMember member, ChatRoomMemberRole oldRole, boolean isInitial) {
    ChatRoomLocalUserRoleChangeEvent evt =
        new ChatRoomLocalUserRoleChangeEvent(this, oldRole, member.getRole(), isInitial);

    Iterable<ChatRoomLocalUserRoleListener> listeners;
    synchronized (localUserRoleListeners) {
      listeners = new ArrayList<ChatRoomLocalUserRoleListener>(localUserRoleListeners);
    }

    for (ChatRoomLocalUserRoleListener listener : listeners) listener.localUserRoleChanged(evt);
  }
示例#6
0
 private MockRoomMember findMember(String nickname) {
   for (ChatRoomMember member : members) {
     if (nickname.equals(member.getName())) return (MockRoomMember) member;
   }
   return null;
 }