aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/otr
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/plugin/otr
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/plugin/otr')
-rw-r--r--src/net/java/sip/communicator/plugin/otr/OtrContactManager.java86
-rw-r--r--src/net/java/sip/communicator/plugin/otr/OtrTransformLayer.java6
2 files changed, 90 insertions, 2 deletions
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;
}