/** * Returns existing chat rooms for the given <tt>chatRoomProvider</tt>. * * @param chatRoomProvider the <tt>ChatRoomProviderWrapper</tt>, which chat rooms we're looking * for * @return existing chat rooms for the given <tt>chatRoomProvider</tt> */ public List<String> getExistingChatRooms(ChatRoomProviderWrapper chatRoomProvider) { if (chatRoomProvider == null) return null; ProtocolProviderService protocolProvider = chatRoomProvider.getProtocolProvider(); if (protocolProvider == null) return null; OperationSetMultiUserChat groupChatOpSet = protocolProvider.getOperationSet(OperationSetMultiUserChat.class); if (groupChatOpSet == null) return null; List<String> chatRooms = null; try { chatRooms = groupChatOpSet.getExistingChatRooms(); } catch (OperationFailedException e) { if (logger.isTraceEnabled()) logger.trace( "Failed to obtain existing chat rooms for server: " + protocolProvider.getAccountID().getService(), e); } catch (OperationNotSupportedException e) { if (logger.isTraceEnabled()) logger.trace( "Failed to obtain existing chat rooms for server: " + protocolProvider.getAccountID().getService(), e); } return chatRooms; }
/** * Joins the room with the given name though the given chat room provider. * * @param chatRoomName the name of the room to join. * @param chatRoomProvider the chat room provider to join through. */ public void joinChatRoom(String chatRoomName, ChatRoomProviderWrapper chatRoomProvider) { OperationSetMultiUserChat groupChatOpSet = chatRoomProvider.getProtocolProvider().getOperationSet(OperationSetMultiUserChat.class); ChatRoom chatRoom = null; try { chatRoom = groupChatOpSet.findRoom(chatRoomName); } catch (Exception e) { if (logger.isTraceEnabled()) logger.trace("Un exception occurred while searching for room:" + chatRoomName, e); } if (chatRoom != null) { ChatRoomWrapper chatRoomWrapper = chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom); if (chatRoomWrapper == null) { ChatRoomProviderWrapper parentProvider = chatRoomList.findServerWrapperFromProvider(chatRoom.getParentProvider()); chatRoomWrapper = new ChatRoomWrapperImpl(parentProvider, chatRoom); chatRoomList.addChatRoom(chatRoomWrapper); fireChatRoomListChangedEvent(chatRoomWrapper, ChatRoomListChangeEvent.CHAT_ROOM_ADDED); } joinChatRoom(chatRoomWrapper); } else MUCActivator.getAlertUIService() .showAlertDialog( MUCActivator.getResources().getI18NString("service.gui.ERROR"), MUCActivator.getResources() .getI18NString( "service.gui.CHAT_ROOM_NOT_EXIST", new String[] { chatRoomName, chatRoomProvider.getProtocolProvider().getAccountID().getService() })); }
/** * Rejects the given invitation with the specified reason. * * @param multiUserChatOpSet the operation set to use for rejecting the invitation * @param invitation the invitation to reject * @param reason the reason for the rejection */ public void rejectInvitation( OperationSetMultiUserChat multiUserChatOpSet, ChatRoomInvitation invitation, String reason) { multiUserChatOpSet.rejectInvitation(invitation, reason); }
/** * 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; }
/** * Removes the query from protocol provider service presence listeners. * * @param pps the protocol provider service. */ public void removeQueryFromProviderPresenceListeners(ProtocolProviderService pps) { OperationSetMultiUserChat opSetMUC = pps.getOperationSet(OperationSetMultiUserChat.class); if (opSetMUC != null) { opSetMUC.removePresenceListener(this); } }
/** * Sends a file transfer request to the given <tt>toContact</tt>. * * @return the transfer object * @param toContact the contact that should receive the file * @param file file to send * @param gw special gateway to be used for receiver if its jid misses the domain part */ FileTransfer sendFile(Contact toContact, File file, String gw) throws IllegalStateException, IllegalArgumentException, OperationNotSupportedException { OutgoingFileTransferJabberImpl outgoingTransfer = null; try { assertConnected(); if (file.length() > getMaximumFileLength()) throw new IllegalArgumentException("File length exceeds the allowed one for this protocol"); String fullJid = null; // Find the jid of the contact which support file transfer // and is with highest priority if more than one found // if we have equals priorities // choose the one that is more available OperationSetMultiUserChat mucOpSet = jabberProvider.getOperationSet(OperationSetMultiUserChat.class); if (mucOpSet != null && mucOpSet.isPrivateMessagingContact(toContact.getAddress())) { fullJid = toContact.getAddress(); } else { Iterator<Presence> iter = jabberProvider.getConnection().getRoster().getPresences(toContact.getAddress()); int bestPriority = -1; PresenceStatus jabberStatus = null; while (iter.hasNext()) { Presence presence = iter.next(); if (jabberProvider.isFeatureListSupported( presence.getFrom(), new String[] { "http://jabber.org/protocol/si", "http://jabber.org/protocol/si/profile/file-transfer" })) { int priority = (presence.getPriority() == Integer.MIN_VALUE) ? 0 : presence.getPriority(); if (priority > bestPriority) { bestPriority = priority; fullJid = presence.getFrom(); jabberStatus = OperationSetPersistentPresenceJabberImpl.jabberStatusToPresenceStatus( presence, jabberProvider); } else if (priority == bestPriority && jabberStatus != null) { PresenceStatus tempStatus = OperationSetPersistentPresenceJabberImpl.jabberStatusToPresenceStatus( presence, jabberProvider); if (tempStatus.compareTo(jabberStatus) > 0) { fullJid = presence.getFrom(); jabberStatus = tempStatus; } } } } } // First we check if file transfer is at all supported for this // contact. if (fullJid == null) { throw new OperationNotSupportedException( "Contact client or server does not support file transfers."); } if (gw != null && !fullJid.contains("@") && !fullJid.endsWith(gw)) { fullJid = fullJid + "@" + gw; } OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(fullJid); outgoingTransfer = new OutgoingFileTransferJabberImpl(toContact, file, transfer, jabberProvider); // Notify all interested listeners that a file transfer has been // created. FileTransferCreatedEvent event = new FileTransferCreatedEvent(outgoingTransfer, new Date()); fireFileTransferCreated(event); // Send the file through the Jabber file transfer. transfer.sendFile(file, "Sending file"); // Start the status and progress thread. new FileTransferProgressThread(transfer, outgoingTransfer).start(); } catch (XMPPException e) { logger.error("Failed to send file.", e); } return outgoingTransfer; }