[sip-comm-cvs] CVS update: /sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java

emcho at dev.java.net emcho at dev.java.net
Mon Apr 23 20:11:54 CEST 2007


User: emcho   
Date: 2007-04-23 18:11:54+0000
Log:
 working on multi chat and a jabber implementation
 
 implemented max message length handling 

File Changes:

Directory: /sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/
=============================================================================

File [changed]: OperationSetBasicInstantMessagingIcqImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java?r1=1.22&r2=1.23
Delta lines:  +52 -18
---------------------
--- OperationSetBasicInstantMessagingIcqImpl.java	2007-04-17 10:17:03+0000	1.22
+++ OperationSetBasicInstantMessagingIcqImpl.java	2007-04-23 18:11:52+0000	1.23
@@ -72,6 +72,12 @@
     private OperationSetPersistentPresenceIcqImpl opSetPersPresence = null;
 
     /**
+     * The maximum message length allowed by the icq protocol as reported by
+     * Pavel Tankov.
+     */
+    private static final int MAX_MSG_LEN = 2047;
+
+    /**
      * I do not why but we sometimes receive messages with a date in the future.sdf
      * I've decided to ignore such messages. I draw the line on
      * currentTimeMillis() + ONE_DAY milliseconds. Anything with a date farther
@@ -167,7 +173,7 @@
                                  String contentEncoding, String subject)
     {
         return new MessageIcqImpl(new String(content), contentType
-                                  , contentEncoding, subject);
+                                  , contentEncoding, subject, null);
     }
 
     /**
@@ -180,7 +186,7 @@
     public Message createMessage(String messageText)
     {
         return new MessageIcqImpl(messageText, DEFAULT_MIME_TYPE
-                                  , DEFAULT_MIME_ENCODING, null);
+                                  , DEFAULT_MIME_ENCODING, null, null);
     }
 
     /**
@@ -210,27 +216,55 @@
                 getImConversation(
                     new Screenname(to.getAddress()));
 
+        //split the message in multiple parts in case it is bigger than the
+        //max message length
+        LinkedList messageParts = new LinkedList();
+        String messageContent = message.getContent();
 
-        if (to.getPresenceStatus().isOnline())
+        while (messageContent.length() > MAX_MSG_LEN)
         {
+            messageParts.add(messageContent.substring(0, MAX_MSG_LEN));
+            messageContent = messageContent.substring(MAX_MSG_LEN);
+        }
 
+        if (messageContent.length() > 0)
+            messageParts.add(messageContent);
 
+        //now send the all the parts
+        for(int i = 0; i < messageParts.size(); i++)
+        {
+            String messageSegment = (String)messageParts.get(i);
+            if (to.getPresenceStatus().isOnline())
+            {
             //do not add the conversation listener in here. we'll add it
             //inside the icbm listener
-
-            imConversation.sendMessage(new SimpleMessage(message.getContent()));
+                imConversation.sendMessage(new SimpleMessage(messageSegment));
         }
         else
-            imConversation.sendMessage(new SimpleMessage(message.getContent()), true);
+            {
+                imConversation.sendMessage(new SimpleMessage(messageSegment)
+                                           , true);
+            }
 
         //temporarily and uglity fire the sent event here.
-        /** @todo move elsewhaere */
+            /** @todo move elsewhere */
+            //in case we have a multi part message, make sure that at least
+            //the first message delivered event is for a message with the same
+            //uid as the one that was passed to us.
         MessageDeliveredEvent msgDeliveredEvt
             = new MessageDeliveredEvent(
-                message, to, new Date());
+                    new MessageIcqImpl(messageSegment
+                                       , message.getContentType()
+                                       , message.getEncoding()
+                                       , message.getSubject()
+                                       , (i == 0)
+                                           ? message.getMessageUID()
+                                           : null)
+                        , to
+                        , new Date());
 
         fireMessageEvent(msgDeliveredEvt);
-
+        }
     }
 
     /**




---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe at sip-communicator.dev.java.net
For additional commands, e-mail: cvs-help at sip-communicator.dev.java.net





More information about the commits mailing list