Ejemplo n.º 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);
  }
Ejemplo n.º 2
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);
  }
Ejemplo n.º 3
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);
  }