/** * Sends the given file through this chat transport file transfer operation set. * * @param file the file to send * @return the <tt>FileTransfer</tt> object charged to transfer the file * @throws Exception if anything goes wrong */ public FileTransfer sendFile(File file) throws Exception { // If this chat transport does not support instant messaging we do // nothing here. if (!allowsFileTransfer()) return null; OperationSetFileTransfer ftOpSet = contact.getProtocolProvider().getOperationSet(OperationSetFileTransfer.class); if (FileUtils.isImage(file.getName())) { // Create a thumbnailed file if possible. OperationSetThumbnailedFileFactory tfOpSet = contact.getProtocolProvider().getOperationSet(OperationSetThumbnailedFileFactory.class); if (tfOpSet != null) { byte[] thumbnail = getFileThumbnail(file); if (thumbnail != null && thumbnail.length > 0) { file = tfOpSet.createFileWithThumbnail( file, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, "image/png", thumbnail); } } } return ftOpSet.sendFile(contact, file); }
/** * Determines whether this chat transport supports the supplied content type * * @param contentType the type we want to check * @return <tt>true</tt> if the chat transport supports it and <tt>false</tt> otherwise. */ public boolean isContentTypeSupported(String contentType) { OperationSetBasicInstantMessaging imOpSet = contact.getProtocolProvider().getOperationSet(OperationSetBasicInstantMessaging.class); if (imOpSet != null) return imOpSet.isContentTypeSupported(contentType); else return false; }
/** * Sends a typing notification state. * * @param typingState the typing notification state to send * @return the result of this operation. One of the TYPING_NOTIFICATION_XXX constants defined in * this class */ public int sendTypingNotification(int typingState) { // If this chat transport does not support sms messaging we do // nothing here. if (!allowsTypingNotifications()) return -1; ProtocolProviderService protocolProvider = contact.getProtocolProvider(); OperationSetTypingNotifications tnOperationSet = protocolProvider.getOperationSet(OperationSetTypingNotifications.class); // if protocol is not registered or contact is offline don't // try to send typing notifications if (protocolProvider.isRegistered() && contact.getPresenceStatus().getStatus() >= PresenceStatus.ONLINE_THRESHOLD) { try { tnOperationSet.sendTypingNotification(contact, typingState); return ChatPanel.TYPING_NOTIFICATION_SUCCESSFULLY_SENT; } catch (Exception ex) { logger.error("Failed to send typing notifications.", ex); return ChatPanel.TYPING_NOTIFICATION_SEND_FAILED; } } return ChatPanel.TYPING_NOTIFICATION_SEND_FAILED; }
/** * Permanently removes locally stored message history for the metacontact, remove any recent * contacts if any. */ public void eraseLocallyStoredHistory(MetaContact contact) throws IOException { List<ComparableEvtObj> toRemove = null; synchronized (recentMessages) { toRemove = new ArrayList<ComparableEvtObj>(); Iterator<Contact> iter = contact.getContacts(); while (iter.hasNext()) { Contact item = iter.next(); String id = item.getAddress(); ProtocolProviderService provider = item.getProtocolProvider(); for (ComparableEvtObj msc : recentMessages) { if (msc.getProtocolProviderService().equals(provider) && msc.getContactAddress().equals(id)) { toRemove.add(msc); } } } recentMessages.removeAll(toRemove); } if (recentQuery != null) { for (ComparableEvtObj msc : toRemove) { recentQuery.fireContactRemoved(msc); } } }
/** * Returns <code>true</code> if this chat transport supports typing notifications, otherwise * returns <code>false</code>. * * @return <code>true</code> if this chat transport supports typing notifications, otherwise * returns <code>false</code>. */ public boolean allowsTypingNotifications() { Object tnOpSet = contact.getProtocolProvider().getOperationSet(OperationSetTypingNotifications.class); if (tnOpSet != null) return true; else return false; }
/** * Sends the given sms message trough this chat transport. * * @param phoneNumber phone number of the destination * @param messageText The message to send. * @throws Exception if the send operation is interrupted */ public void sendSmsMessage(String phoneNumber, String messageText) throws Exception { // If this chat transport does not support sms messaging we do // nothing here. if (!allowsSmsMessage()) return; SMSManager.sendSMS(contact.getProtocolProvider(), phoneNumber, messageText); }
/** * Removes the given sms message listener from this chat transport. * * @param l The message listener to remove. */ public void removeSmsMessageListener(MessageListener l) { // If this chat transport does not support sms messaging we do // nothing here. if (!allowsSmsMessage()) return; OperationSetSmsMessaging smsOpSet = contact.getProtocolProvider().getOperationSet(OperationSetSmsMessaging.class); smsOpSet.removeMessageListener(l); }
/** * Removes the instant message listener from this chat transport. * * @param l The message listener to remove. */ public void removeInstantMessageListener(MessageListener l) { // If this chat transport does not support instant messaging we do // nothing here. if (!allowsInstantMessage()) return; OperationSetBasicInstantMessaging imOpSet = contact.getProtocolProvider().getOperationSet(OperationSetBasicInstantMessaging.class); imOpSet.removeMessageListener(l); }
/** * If sending im is supported check it for supporting html messages if a font is set. As it can be * slow make sure its not on our way */ private void checkImCaps() { if (ConfigurationUtils.getChatDefaultFontFamily() != null && ConfigurationUtils.getChatDefaultFontSize() > 0) { OperationSetBasicInstantMessaging imOpSet = contact.getProtocolProvider().getOperationSet(OperationSetBasicInstantMessaging.class); if (imOpSet != null) imOpSet.isContentTypeSupported(OperationSetBasicInstantMessaging.HTML_MIME_TYPE, contact); } }
/** * Whether a dialog need to be opened so the user can enter the destination number. * * @return <tt>true</tt> if dialog needs to be open. */ public boolean askForSMSNumber() { // If this chat transport does not support sms messaging we do // nothing here. if (!allowsSmsMessage()) return false; OperationSetSmsMessaging smsOpSet = contact.getProtocolProvider().getOperationSet(OperationSetSmsMessaging.class); return smsOpSet.askForNumber(contact); }
/** * Returns <code>true</code> if this chat transport supports message corrections and false * otherwise. * * @return <code>true</code> if this chat transport supports message corrections and false * otherwise. */ public boolean allowsMessageCorrections() { OperationSetContactCapabilities capOpSet = getProtocolProvider().getOperationSet(OperationSetContactCapabilities.class); if (capOpSet != null) { return capOpSet.getOperationSet(contact, OperationSetMessageCorrection.class) != null; } else { return contact.getProtocolProvider().getOperationSet(OperationSetMessageCorrection.class) != null; } }
/** * Implements ListSelectionListener.valueChanged. Enables or disables call and hangup buttons * depending on the selection in the contactlist. */ public void valueChanged(ListSelectionEvent e) { Object o = mainFrame.getContactListPanel().getContactList().getSelectedValue(); if ((e.getFirstIndex() != -1 || e.getLastIndex() != -1) && (o instanceof MetaContact)) { setCallMetaContact(true); // Switch automatically to the appropriate pps in account selector // box and enable callButton if telephony is supported. Contact contact = ((MetaContact) o).getDefaultContact(OperationSetBasicTelephony.class); if (contact != null) { callButton.setEnabled(true); if (contact.getProtocolProvider().isRegistered()) getAccountSelectorBox().setSelected(contact.getProtocolProvider()); } else { callButton.setEnabled(false); } } else if (phoneNumberCombo.isComboFieldEmpty()) { callButton.setEnabled(false); } }
/** * Extract values from <tt>EventObject</tt>. * * @param source */ public void update(EventObject source) { this.eventObject = source; if (source instanceof MessageDeliveredEvent) { MessageDeliveredEvent e = (MessageDeliveredEvent) source; this.contact = e.getDestinationContact(); this.address = contact.getAddress(); this.ppService = contact.getProtocolProvider(); this.timestamp = e.getTimestamp(); } else if (source instanceof MessageReceivedEvent) { MessageReceivedEvent e = (MessageReceivedEvent) source; this.contact = e.getSourceContact(); this.address = contact.getAddress(); this.ppService = contact.getProtocolProvider(); this.timestamp = e.getTimestamp(); } else if (source instanceof ChatRoomMessageDeliveredEvent) { ChatRoomMessageDeliveredEvent e = (ChatRoomMessageDeliveredEvent) source; this.room = e.getSourceChatRoom(); this.address = room.getIdentifier(); this.ppService = room.getParentProvider(); this.timestamp = e.getTimestamp(); } else if (source instanceof ChatRoomMessageReceivedEvent) { ChatRoomMessageReceivedEvent e = (ChatRoomMessageReceivedEvent) source; this.room = e.getSourceChatRoom(); this.address = room.getIdentifier(); this.ppService = room.getParentProvider(); this.timestamp = e.getTimestamp(); } }
/** * Returns <code>true</code> if this chat transport supports sms messaging, otherwise returns * <code>false</code>. * * @return <code>true</code> if this chat transport supports sms messaging, otherwise returns * <code>false</code>. */ public boolean allowsSmsMessage() { // First try to ask the capabilities operation set if such is // available. OperationSetContactCapabilities capOpSet = getProtocolProvider().getOperationSet(OperationSetContactCapabilities.class); if (capOpSet != null) { if (capOpSet.getOperationSet(contact, OperationSetSmsMessaging.class) != null) { return true; } } else if (contact.getProtocolProvider().getOperationSet(OperationSetSmsMessaging.class) != null) return true; return false; }
/** * Sends <tt>message</tt> as a message correction through this transport, specifying the mime type * (html or plain text) and the id of the message to replace. * * @param message The message to send. * @param mimeType The mime type of the message to send: text/html or text/plain. * @param correctedMessageUID The ID of the message being corrected by this message. */ public void correctInstantMessage(String message, String mimeType, String correctedMessageUID) { if (!allowsMessageCorrections()) { return; } OperationSetMessageCorrection mcOpSet = contact.getProtocolProvider().getOperationSet(OperationSetMessageCorrection.class); Message msg; if (mimeType.equals(OperationSetBasicInstantMessaging.HTML_MIME_TYPE) && mcOpSet.isContentTypeSupported(OperationSetBasicInstantMessaging.HTML_MIME_TYPE)) { msg = mcOpSet.createMessage( message, OperationSetBasicInstantMessaging.HTML_MIME_TYPE, "utf-8", ""); } else { msg = mcOpSet.createMessage(message); } mcOpSet.correctMessage(contact, contactResource, msg, correctedMessageUID); }
/** * When a sent message is delivered shows it in the chat conversation panel. * * @param evt the event containing details on the message delivery */ public void messageDelivered(MessageDeliveredEvent evt) { Contact contact = evt.getDestinationContact(); MetaContact metaContact = GuiActivator.getContactListService().findMetaContactByContact(contact); if (logger.isTraceEnabled()) logger.trace("MESSAGE DELIVERED to contact: " + contact.getAddress()); ChatPanel chatPanel = chatWindowManager.getContactChat(metaContact, false); if (chatPanel != null) { Message msg = evt.getSourceMessage(); ProtocolProviderService protocolProvider = contact.getProtocolProvider(); if (logger.isTraceEnabled()) logger.trace( "MESSAGE DELIVERED: process message to chat for contact: " + contact.getAddress() + " MESSAGE: " + msg.getContent()); chatPanel.addMessage( this.mainFrame.getAccountAddress(protocolProvider), this.mainFrame.getAccountDisplayName(protocolProvider), evt.getTimestamp(), Chat.OUTGOING_MESSAGE, msg.getContent(), msg.getContentType(), msg.getMessageUID(), evt.getCorrectedMessageUID()); if (evt.isSmsMessage() && !ConfigurationUtils.isSmsNotifyTextDisabled()) { chatPanel.addMessage( contact.getDisplayName(), new Date(), Chat.ACTION_MESSAGE, GuiActivator.getResources().getI18NString("service.gui.SMS_SUCCESSFULLY_SENT"), "text"); } } }
/** * Sends the given instant message through this chat transport, by specifying the mime type (html * or plain text). * * @param message The message to send. * @param mimeType The mime type of the message to send: text/html or text/plain. * @throws Exception if the send operation is interrupted */ public void sendInstantMessage(String message, String mimeType) throws Exception { // If this chat transport does not support instant messaging we do // nothing here. if (!allowsInstantMessage()) return; OperationSetBasicInstantMessaging imOpSet = contact.getProtocolProvider().getOperationSet(OperationSetBasicInstantMessaging.class); Message msg; if (mimeType.equals(OperationSetBasicInstantMessaging.HTML_MIME_TYPE) && imOpSet.isContentTypeSupported(OperationSetBasicInstantMessaging.HTML_MIME_TYPE)) { msg = imOpSet.createMessage( message, OperationSetBasicInstantMessaging.HTML_MIME_TYPE, "utf-8", ""); } else { msg = imOpSet.createMessage(message); } if (contactResource != null) imOpSet.sendInstantMessage(contact, contactResource, msg); else imOpSet.sendInstantMessage(contact, ContactResource.BASE_RESOURCE, msg); }
/** * Initialize (a new) Whiteboard with contact * * @param contact Contact used to init whiteboard */ public void initWhiteboard(final Contact contact) { opSetWb = (OperationSetWhiteboarding) contact.getProtocolProvider().getOperationSet(OperationSetWhiteboarding.class); if (opSetWb == null) { logger.info("Contact does not support whiteboarding"); return; } WhiteboardFrame wbf = getWhiteboardFrame(contact); if (wbf != null) { wbf.setVisible(true); return; } new Thread() { public void run() { try { WhiteboardSession wbSession = opSetWb.createWhiteboardSession(contact.getDisplayName(), null); WhiteboardFrame wbFrame = new WhiteboardFrame(WhiteboardSessionManager.this, wbSession); wbFrames.add(wbFrame); wbFrame.setContact(contact); wbFrame.setVisible(true); wbSession.join(); wbSession.invite(contact.getAddress()); } catch (OperationFailedException e) { logger.error("Creating a whiteboard session failed.", e); } catch (OperationNotSupportedException e) { logger.error("Do not support create of whiteboard session", e); } } }.start(); }
/** * Creates an instance of <tt>MetaContactChatTransport</tt> by specifying the parent * <tt>chatSession</tt> and the <tt>contact</tt> associated with the transport. * * @param chatSession the parent <tt>ChatSession</tt> * @param contact the <tt>Contact</tt> associated with this transport * @param contactResource the <tt>ContactResource</tt> associated with the contact * @param isDisplayResourceOnly indicates if only the resource name should be displayed */ public MetaContactChatTransport( MetaContactChatSession chatSession, Contact contact, ContactResource contactResource, boolean isDisplayResourceOnly) { this.parentChatSession = chatSession; this.contact = contact; this.contactResource = contactResource; this.isDisplayResourceOnly = isDisplayResourceOnly; presenceOpSet = contact.getProtocolProvider().getOperationSet(OperationSetPresence.class); if (presenceOpSet != null) presenceOpSet.addContactPresenceStatusListener(this); // checking this can be slow so make // sure its out of our way new Thread( new Runnable() { public void run() { checkImCaps(); } }) .start(); }
/** * Implements the ContactListListener.contactSelected method. * * @param evt the <tt>ContactListEvent</tt> that notified us */ public void contactClicked(ContactListEvent evt) { // We're interested only in two click events. if (evt.getClickCount() < 2) return; UIContact descriptor = evt.getSourceContact(); // We're currently only interested in MetaContacts. if (descriptor.getDescriptor() instanceof MetaContact) { MetaContact metaContact = (MetaContact) descriptor.getDescriptor(); // Searching for the right proto contact to use as default for the // chat conversation. Contact defaultContact = metaContact.getDefaultContact(OperationSetBasicInstantMessaging.class); // do nothing if (defaultContact == null) { defaultContact = metaContact.getDefaultContact(OperationSetSmsMessaging.class); if (defaultContact == null) return; } ProtocolProviderService defaultProvider = defaultContact.getProtocolProvider(); OperationSetBasicInstantMessaging defaultIM = defaultProvider.getOperationSet(OperationSetBasicInstantMessaging.class); ProtocolProviderService protoContactProvider; OperationSetBasicInstantMessaging protoContactIM; boolean isOfflineMessagingSupported = defaultIM != null && !defaultIM.isOfflineMessagingSupported(); if (defaultContact.getPresenceStatus().getStatus() < 1 && (!isOfflineMessagingSupported || !defaultProvider.isRegistered())) { Iterator<Contact> protoContacts = metaContact.getContacts(); while (protoContacts.hasNext()) { Contact contact = protoContacts.next(); protoContactProvider = contact.getProtocolProvider(); protoContactIM = protoContactProvider.getOperationSet(OperationSetBasicInstantMessaging.class); if (protoContactIM != null && protoContactIM.isOfflineMessagingSupported() && protoContactProvider.isRegistered()) { defaultContact = contact; } } } ContactEventHandler contactHandler = mainFrame.getContactHandler(defaultContact.getProtocolProvider()); contactHandler.contactClicked(defaultContact, evt.getClickCount()); } else if (descriptor.getDescriptor() instanceof SourceContact) { SourceContact contact = (SourceContact) descriptor.getDescriptor(); List<ContactDetail> imDetails = contact.getContactDetails(OperationSetBasicInstantMessaging.class); List<ContactDetail> mucDetails = contact.getContactDetails(OperationSetMultiUserChat.class); if (imDetails != null && imDetails.size() > 0) { ProtocolProviderService pps = imDetails.get(0).getPreferredProtocolProvider(OperationSetBasicInstantMessaging.class); GuiActivator.getUIService() .getChatWindowManager() .startChat(contact.getContactAddress(), pps); } else if (mucDetails != null && mucDetails.size() > 0) { ChatRoomWrapper room = GuiActivator.getMUCService().findChatRoomWrapperFromSourceContact(contact); if (room == null) { // lets check by id ProtocolProviderService pps = mucDetails.get(0).getPreferredProtocolProvider(OperationSetMultiUserChat.class); room = GuiActivator.getMUCService() .findChatRoomWrapperFromChatRoomID(contact.getContactAddress(), pps); if (room == null) { GuiActivator.getMUCService() .createChatRoom( contact.getContactAddress(), pps, new ArrayList<String>(), "", false, false, false); } } if (room != null) GuiActivator.getMUCService().openChatRoom(room); } else { List<ContactDetail> smsDetails = contact.getContactDetails(OperationSetSmsMessaging.class); if (smsDetails != null && smsDetails.size() > 0) { GuiActivator.getUIService() .getChatWindowManager() .startChat(contact.getContactAddress(), true); } } } }
/** * Returns the <tt>ProtocolProviderService</tt>, corresponding to this chat transport. * * @return the <tt>ProtocolProviderService</tt>, corresponding to this chat transport. */ public ProtocolProviderService getProtocolProvider() { return contact.getProtocolProvider(); }
/** * Returns <code>true</code> if this chat transport supports file transfer, otherwise returns * <code>false</code>. * * @return <code>true</code> if this chat transport supports file transfer, otherwise returns * <code>false</code>. */ public boolean allowsFileTransfer() { Object ftOpSet = contact.getProtocolProvider().getOperationSet(OperationSetFileTransfer.class); if (ftOpSet != null) return true; else return false; }
/** * Returns the maximum file length supported by the protocol in bytes. * * @return the file length that is supported. */ public long getMaximumFileLength() { OperationSetFileTransfer ftOpSet = contact.getProtocolProvider().getOperationSet(OperationSetFileTransfer.class); return ftOpSet.getMaximumFileLength(); }