aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator
diff options
context:
space:
mode:
authorMarin <m.dzhigarov@gmail.com>2014-01-02 12:26:12 +0200
committerMarin <m.dzhigarov@gmail.com>2014-01-02 13:40:21 +0200
commit5a7657667304a23ce9e7a65ea67261d56128358e (patch)
tree6427fe21eb77bc6208a319ef775634f0e3edef27 /src/net/java/sip/communicator
parente64da30937358c3a08c9a9f57aa3bc280ab69fca (diff)
downloadjitsi-5a7657667304a23ce9e7a65ea67261d56128358e.zip
jitsi-5a7657667304a23ce9e7a65ea67261d56128358e.tar.gz
jitsi-5a7657667304a23ce9e7a65ea67261d56128358e.tar.bz2
Fixes last message correction when OTR is enabled
Diffstat (limited to 'src/net/java/sip/communicator')
-rw-r--r--src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java17
-rw-r--r--src/net/java/sip/communicator/plugin/otr/OtrContactManager.java86
-rw-r--r--src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java6
-rw-r--r--src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java16
-rw-r--r--src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java13
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.
*