diff options
Diffstat (limited to 'src/net/java/sip/communicator')
5 files changed, 136 insertions, 2 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java index 1364643..0eb6620 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java @@ -152,6 +152,23 @@ public class OperationSetBasicInstantMessagingJabberImpl } /** + * Create a Message instance with the specified UID and a default + * (text/plain) content type and encoding. + * This method can be useful when message correction is required. One can + * construct the corrected message to have the same UID as the message + * before correction. + * + * @param messageText the string content of the message. + * @param messageUID the unique identifier of this message. + * @return Message the newly created message + */ + public Message createMessageWithUID(String messageText, String messageUID) + { + return new MessageJabberImpl(messageText, DEFAULT_MIME_TYPE, + DEFAULT_MIME_ENCODING, null, messageUID); + } + + /** * Create a Message instance for sending arbitrary MIME-encoding content. * * @param content content value diff --git a/src/net/java/sip/communicator/plugin/otr/OtrContactManager.java b/src/net/java/sip/communicator/plugin/otr/OtrContactManager.java new file mode 100644 index 0000000..e1776ca --- /dev/null +++ b/src/net/java/sip/communicator/plugin/otr/OtrContactManager.java @@ -0,0 +1,86 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.otr; + +import java.util.*; +import java.util.concurrent.*; + +import net.java.sip.communicator.service.protocol.*; + +public class OtrContactManager +{ + + private static final Map<Contact, List<OtrContact>> contactsMap = + new ConcurrentHashMap<Contact, List<OtrContact>>(); + + public static class OtrContact + { + public final Contact contact; + + public final ContactResource resource; + + private OtrContact(Contact contact, ContactResource resource) + { + this.contact = contact; + this.resource = resource; + } + + public boolean equals(Object obj) + { + if (this == obj) + return true; + + if (!(obj instanceof OtrContact)) + return false; + + OtrContact other = (OtrContact) obj; + + if (this.contact != null && this.contact.equals(other.contact)) + { + if (this.resource != null && resource.equals(other.resource)) + return true; + if (this.resource == null && other.resource == null) + return true; + return false; + } + return false; + } + + public int hashCode() + { + int result = 17; + + result = 31 * result + (contact == null ? 0 : contact.hashCode()); + result = 31 * result + (resource == null ? 0 : resource.hashCode()); + + return result; + } + } + + public static OtrContact getOtrContact( + Contact contact, ContactResource resource) + { + if (contact == null) + return null; + + if (!contactsMap.containsKey(contact)) + { + List<OtrContact> otrContactsList = new ArrayList<OtrContact>(); + contactsMap.put(contact, otrContactsList); + } + + List<OtrContact> otrContactList = contactsMap.get(contact); + for (OtrContact otrContact : otrContactList) + { + if (otrContact.resource.equals(resource)) + return otrContact; + } + OtrContact otrContact = new OtrContact(contact, resource); + otrContactList.add(otrContact); + return otrContact; + } +} diff --git a/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java b/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java index 5111d9e..44e0f0e 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java @@ -139,12 +139,14 @@ public class OtrTransformLayer contact.getProtocolProvider().getOperationSet( OperationSetBasicInstantMessaging.class); Message processedMessage = - imOpSet.createMessage(processedMessageContent); + imOpSet.createMessageWithUID( + processedMessageContent, evt.getSourceMessage().getMessageUID()); // Create a new event and return. MessageReceivedEvent processedEvent = new MessageReceivedEvent(processedMessage, contact, evt - .getTimestamp()); + .getContactResource(), evt.getTimestamp(), + evt.getCorrectedMessageUID()); return processedEvent; } diff --git a/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java b/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java index 74077c6..ec94e08 100644 --- a/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java +++ b/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java @@ -107,6 +107,22 @@ public abstract class AbstractOperationSetBasicInstantMessaging DEFAULT_MIME_ENCODING, null); } + /** + * Create a Message instance with the specified UID and a default + * (text/plain) content type and encoding. + * This method can be useful when message correction is required. One can + * construct the corrected message to have the same UID as the message + * before correction. + * + * @param messageText the string content of the message. + * @param messageUID the unique identifier of this message. + * @return Message the newly created message + */ + public Message createMessageWithUID(String messageText, String messageUID) + { + return createMessage(messageText); + } + public abstract Message createMessage( String content, String contentType, String encoding, String subject); diff --git a/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java b/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java index 7636394..7b34e34 100644 --- a/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java +++ b/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java @@ -54,6 +54,19 @@ public interface OperationSetBasicInstantMessaging public Message createMessage(String messageText); /** + * Create a Message instance with the specified UID and a default + * (text/plain) content type and encoding. + * This method can be useful when message correction is required. One can + * construct the corrected message to have the same UID as the message + * before correction. + * + * @param messageText the string content of the message. + * @param messageUID the unique identifier of this message. + * @return Message the newly created message + */ + public Message createMessageWithUID(String messageText, String messageUID); + + /** * Sends the <tt>message</tt> to the destination indicated by the * <tt>to</tt> contact. * |