Esempio n. 1
0
  /**
   * Joins the given chat room with the given password and manages all the exceptions that could
   * occur during the join process.
   *
   * @param chatRoomWrapper the chat room to join.
   * @param nickName the nickname we choose for the given chat room.
   * @param password the password.
   * @param rememberPassword if true the password should be saved.
   * @param isFirstAttempt is this the first attempt to join room, used to check whether to show
   *     some error messages
   * @param subject the subject which will be set to the room after the user join successful.
   */
  private void joinChatRoom(
      ChatRoomWrapper chatRoomWrapper,
      String nickName,
      byte[] password,
      boolean rememberPassword,
      boolean isFirstAttempt,
      String subject) {
    ChatRoom chatRoom = chatRoomWrapper.getChatRoom();

    if (chatRoom == null) {
      MUCActivator.getAlertUIService()
          .showAlertDialog(
              MUCActivator.getResources().getI18NString("service.gui.WARNING"),
              MUCActivator.getResources()
                  .getI18NString(
                      "service.gui.CHAT_ROOM_NOT_CONNECTED",
                      new String[] {chatRoomWrapper.getChatRoomName()}));
      return;
    }

    new JoinChatRoomTask(
            (ChatRoomWrapperImpl) chatRoomWrapper,
            nickName,
            password,
            rememberPassword,
            isFirstAttempt,
            subject)
        .start();
  }
Esempio n. 2
0
  /**
   * Leaves the given chat room.
   *
   * @param chatRoomWrapper the chat room to leave.
   * @return <tt>ChatRoomWrapper</tt> instance associated with the chat room.
   */
  public ChatRoomWrapper leaveChatRoom(ChatRoomWrapper chatRoomWrapper) {
    ChatRoom chatRoom = chatRoomWrapper.getChatRoom();

    if (chatRoom == null) {
      ResourceManagementService resources = MUCActivator.getResources();

      MUCActivator.getAlertUIService()
          .showAlertDialog(
              resources.getI18NString("service.gui.WARNING"),
              resources.getI18NString("service.gui.CHAT_ROOM_LEAVE_NOT_CONNECTED"));

      return null;
    }

    if (chatRoom.isJoined()) chatRoom.leave();

    ChatRoomWrapper existChatRoomWrapper = chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom);

    if (existChatRoomWrapper == null) return null;

    // We save the choice of the user, before the chat room is really
    // joined, because even the join fails we want the next time when
    // we login to join this chat room automatically.
    ConfigurationUtils.updateChatRoomStatus(
        chatRoomWrapper.getParentProvider().getProtocolProvider(),
        chatRoomWrapper.getChatRoomID(),
        GlobalStatusEnum.OFFLINE_STATUS);

    return existChatRoomWrapper;
  }
    /**
     * Checks if the menu item should be enabled or disabled.
     *
     * @param contact the contact associated with the menu item.
     * @return <tt>true</tt> if the item should be enabled and <tt>false</tt> if not.
     */
    public boolean check(SourceContact contact) {
      ChatRoomWrapper chatRoomWrapper =
          MUCActivator.getMUCService().findChatRoomWrapperFromSourceContact(contact);
      ChatRoom chatRoom = null;
      if (chatRoomWrapper != null) {
        chatRoom = chatRoomWrapper.getChatRoom();
      }

      if ((chatRoom != null) && chatRoom.isJoined()) return false;
      return true;
    }
Esempio n. 4
0
  /**
   * Handles adding a chat room provider.
   *
   * @param provider the provider.
   * @param addQueryResult indicates whether we should add the chat room to the query results or
   *     fire an event without adding it to the results.
   */
  private void providerAdded(ChatRoomProviderWrapper provider, boolean addQueryResult) {

    for (int i = 0; i < provider.countChatRooms(); i++) {
      ChatRoomWrapper chatRoom = provider.getChatRoom(i);
      addChatRoom(
          provider.getProtocolProvider(),
          chatRoom.getChatRoomName(),
          chatRoom.getChatRoomID(),
          addQueryResult,
          chatRoom.isAutojoin());
    }
  }
    @Override
    public boolean isVisible(SourceContact actionSource) {
      if (!(actionSource instanceof ChatRoomSourceContact)) return false;

      if (name.equals("autojoin") || name.equals("autojoin_pressed")) {
        ChatRoomSourceContact contact = (ChatRoomSourceContact) actionSource;
        ChatRoomWrapper room =
            MUCActivator.getMUCService().findChatRoomWrapperFromSourceContact(contact);
        if (name.equals("autojoin")) return !room.isAutojoin();

        if (name.equals("autojoin_pressed")) return room.isAutojoin();
      }
      return true;
    }
Esempio n. 6
0
 /**
  * Destroys the given <tt>ChatRoom</tt> from the list of all chat rooms.
  *
  * @param chatRoomWrapper the <tt>ChatRoomWrapper</tt> to be destroyed.
  * @param reason the reason for destroying.
  * @param alternateAddress the alternate address.
  */
 public void destroyChatRoom(
     ChatRoomWrapper chatRoomWrapper, String reason, String alternateAddress) {
   if (chatRoomWrapper.getChatRoom().destroy(reason, alternateAddress)) {
     MUCActivator.getUIService().closeChatRoomWindow(chatRoomWrapper);
     chatRoomList.removeChatRoom(chatRoomWrapper);
   } else {
     // if we leave a chat room which is not persistent
     // the room can be destroyed on the server, and error is returned
     // when we try to destroy it not-authorized(401)
     if (!chatRoomWrapper.getChatRoom().isPersistent()
         && !chatRoomWrapper.getChatRoom().isJoined()) {
       chatRoomList.removeChatRoom(chatRoomWrapper);
     }
   }
 }
Esempio n. 7
0
  /**
   * Joins the given chat room with the given password and manages all the exceptions that could
   * occur during the join process.
   *
   * @param chatRoomWrapper the chat room to join.
   * @param nickName the nickname we choose for the given chat room.
   * @param password the password.
   */
  public void joinChatRoom(ChatRoomWrapper chatRoomWrapper, String nickName, byte[] password) {
    ChatRoom chatRoom = chatRoomWrapper.getChatRoom();

    if (chatRoom == null) {
      MUCActivator.getAlertUIService()
          .showAlertDialog(
              MUCActivator.getResources().getI18NString("service.gui.WARNING"),
              MUCActivator.getResources()
                  .getI18NString(
                      "service.gui.CHAT_ROOM_NOT_CONNECTED",
                      new String[] {chatRoomWrapper.getChatRoomName()}));
      return;
    }

    new JoinChatRoomTask((ChatRoomWrapperImpl) chatRoomWrapper, nickName, password).start();
  }
Esempio n. 8
0
  /**
   * Handles chat room presence status updates.
   *
   * @param evt the <tt>LocalUserChatRoomPresenceChangeEvent</tt> instance containing the chat room
   *     and the type, and reason of the change
   */
  @Override
  public void localUserPresenceChanged(LocalUserChatRoomPresenceChangeEvent evt) {
    ChatRoom sourceChatRoom = evt.getChatRoom();

    String eventType = evt.getEventType();

    boolean existingContact = false;
    ChatRoomSourceContact foundContact = null;
    synchronized (contactResults) {
      for (ChatRoomSourceContact contact : contactResults) {
        if (contactEqualsChatRoom(contact, sourceChatRoom)) {
          existingContact = true;
          foundContact = contact;
          contactResults.remove(contact);
          break;
        }
      }
    }

    if (LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED.equals(eventType)) {
      if (existingContact) {
        foundContact.setPresenceStatus(ChatRoomPresenceStatus.CHAT_ROOM_ONLINE);
        synchronized (contactResults) {
          contactResults.add(foundContact);
        }
        fireContactChanged(foundContact);
      } else {
        ChatRoomWrapper chatRoom =
            MUCActivator.getMUCService().findChatRoomWrapperFromChatRoom(sourceChatRoom);
        if (chatRoom != null) addChatRoom(sourceChatRoom, false, chatRoom.isAutojoin());
      }
    } else if ((LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_LEFT.equals(eventType)
        || LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_KICKED.equals(eventType)
        || LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_DROPPED.equals(eventType))) {
      if (existingContact) {
        foundContact.setPresenceStatus(ChatRoomPresenceStatus.CHAT_ROOM_OFFLINE);
        synchronized (contactResults) {
          contactResults.add(foundContact);
        }
        fireContactChanged(foundContact);
      }
    }
  }
    @Override
    public boolean isVisible(SourceContact actionSource) {
      if (actionSource instanceof ChatRoomSourceContact) {
        if (name.equals("leave")) {
          return actionsEnabledCheckers[3].check(actionSource);
        } else if (name.equals("join")) {
          return actionsEnabledCheckers[1].check(actionSource);
        } else {
          ChatRoomSourceContact contact = (ChatRoomSourceContact) actionSource;
          ChatRoomWrapper room =
              MUCActivator.getMUCService().findChatRoomWrapperFromSourceContact(contact);
          if (room == null) return false;

          if (name.equals("autojoin")) return room.isAutojoin();
          else if (name.equals("autojoin_pressed")) return !room.isAutojoin();
        }
      }
      return false;
    }
Esempio n. 10
0
  /**
   * Indicates that a change has occurred in the chat room data list.
   *
   * @param evt the event that describes the change.
   */
  @Override
  public void contentChanged(final ChatRoomListChangeEvent evt) {
    ChatRoomWrapper chatRoom = evt.getSourceChatRoom();
    switch (evt.getEventID()) {
      case ChatRoomListChangeEvent.CHAT_ROOM_ADDED:
        addChatRoom(chatRoom.getChatRoom(), false, chatRoom.isAutojoin());
        break;
      case ChatRoomListChangeEvent.CHAT_ROOM_REMOVED:
        LinkedList<ChatRoomSourceContact> tmpContactResults;
        synchronized (contactResults) {
          tmpContactResults = new LinkedList<ChatRoomSourceContact>(contactResults);

          for (ChatRoomSourceContact contact : tmpContactResults) {
            if (contactEqualsChatRoom(contact, chatRoom)) {
              contactResults.remove(contact);
              fireContactRemoved(contact);
              break;
            }
          }
        }
        break;
      case ChatRoomListChangeEvent.CHAT_ROOM_CHANGED:
        synchronized (contactResults) {
          for (ChatRoomSourceContact contact : contactResults) {
            if (contactEqualsChatRoom(contact, chatRoom.getChatRoom())) {
              if (chatRoom.isAutojoin() != contact.isAutoJoin()) {
                contact.setAutoJoin(chatRoom.isAutojoin());
                fireContactChanged(contact);
              }
              break;
            }
          }
        }
        break;
      default:
        break;
    }
  }
Esempio n. 11
0
  /**
   * Opens a chat window for the chat room.
   *
   * @param room the chat room.
   */
  public void openChatRoom(ChatRoomWrapper room) {
    if (room.getChatRoom() == null) {
      room =
          createChatRoom(
              room.getChatRoomName(),
              room.getParentProvider().getProtocolProvider(),
              new ArrayList<String>(),
              "",
              false,
              false,
              true);

      // leave the chatroom because getChatRoom().isJoined() returns true
      // otherwise
      if (room.getChatRoom().isJoined()) room.getChatRoom().leave();
    }

    if (!room.getChatRoom().isJoined()) {
      String savedNick =
          ConfigurationUtils.getChatRoomProperty(
              room.getParentProvider().getProtocolProvider(), room.getChatRoomID(), "userNickName");
      String subject = null;

      if (savedNick == null) {
        String[] joinOptions =
            ChatRoomJoinOptionsDialog.getJoinOptions(
                room.getParentProvider().getProtocolProvider(),
                room.getChatRoomID(),
                getDefaultNickname(room.getParentProvider().getProtocolProvider()));
        savedNick = joinOptions[0];
        subject = joinOptions[1];
      }

      if (savedNick != null) {
        joinChatRoom(room, savedNick, null, subject);
      } else return;
    }

    MUCActivator.getUIService().openChatRoomWindow(room);
  }
Esempio n. 12
0
  /**
   * Creates a chat room, by specifying the chat room name, the parent protocol provider and
   * eventually, the contacts invited to participate in this chat room.
   *
   * @param roomName the name of the room
   * @param protocolProvider the parent protocol provider.
   * @param contacts the contacts invited when creating the chat room.
   * @param reason
   * @param join whether we should join the room after creating it.
   * @param persistent whether the newly created room will be persistent.
   * @param isPrivate whether the room will be private or public.
   * @return the <tt>ChatRoomWrapper</tt> corresponding to the created room
   */
  public ChatRoomWrapper createChatRoom(
      String roomName,
      ProtocolProviderService protocolProvider,
      Collection<String> contacts,
      String reason,
      boolean join,
      boolean persistent,
      boolean isPrivate) {
    ChatRoomWrapper chatRoomWrapper = null;
    OperationSetMultiUserChat groupChatOpSet =
        protocolProvider.getOperationSet(OperationSetMultiUserChat.class);

    // If there's no group chat operation set we have nothing to do here.
    if (groupChatOpSet == null) return null;

    ChatRoom chatRoom = null;
    try {

      HashMap<String, Object> roomProperties = new HashMap<String, Object>();
      roomProperties.put("isPrivate", isPrivate);
      chatRoom = groupChatOpSet.createChatRoom(roomName, roomProperties);

      if (join) {
        chatRoom.join();

        for (String contact : contacts) chatRoom.invite(contact, reason);
      }
    } catch (OperationFailedException ex) {
      logger.error("Failed to create chat room.", ex);

      MUCActivator.getAlertUIService()
          .showAlertDialog(
              MUCActivator.getResources().getI18NString("service.gui.ERROR"),
              MUCActivator.getResources()
                  .getI18NString(
                      "service.gui.CREATE_CHAT_ROOM_ERROR",
                      new String[] {protocolProvider.getProtocolDisplayName()}),
              ex);
    } catch (OperationNotSupportedException ex) {
      logger.error("Failed to create chat room.", ex);

      MUCActivator.getAlertUIService()
          .showAlertDialog(
              MUCActivator.getResources().getI18NString("service.gui.ERROR"),
              MUCActivator.getResources()
                  .getI18NString(
                      "service.gui.CREATE_CHAT_ROOM_ERROR",
                      new String[] {protocolProvider.getProtocolDisplayName()}),
              ex);
    }

    if (chatRoom != null) {
      ChatRoomProviderWrapper parentProvider =
          chatRoomList.findServerWrapperFromProvider(protocolProvider);

      // if there is the same room ids don't add new wrapper as old one
      // maybe already created
      chatRoomWrapper = chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom);

      if (chatRoomWrapper == null) {
        chatRoomWrapper = new ChatRoomWrapperImpl(parentProvider, chatRoom);
        chatRoomWrapper.setPersistent(persistent);
        chatRoomList.addChatRoom(chatRoomWrapper);
      }
    }

    return chatRoomWrapper;
  }
Esempio n. 13
0
 /**
  * Test equality of contact to chat room wrapper. This method does not rely on a chat room
  * instance, since that may not be available in case of removal.
  *
  * @param contact the contact
  * @param chatRoomWrapper the chat room wrapper
  * @return returns <tt>true</tt> if they are equal, or <tt>false</tt> if they are different.
  */
 private boolean contactEqualsChatRoom(
     final ChatRoomSourceContact contact, final ChatRoomWrapper chatRoomWrapper) {
   return contact.getProvider() == chatRoomWrapper.getParentProvider().getProtocolProvider()
       && contact.getContactAddress().equals(chatRoomWrapper.getChatRoomID());
 }
 @Override
 public boolean isSelected(SourceContact contact) {
   ChatRoomWrapper chatRoomWrapper =
       MUCActivator.getMUCService().findChatRoomWrapperFromSourceContact(contact);
   return chatRoomWrapper.isAutojoin();
 }