Add a workaround for error messages
authorDa Risk <darisk972@gmail.com>
Wed, 08 Apr 2009 18:35:28 +0200
changeset 92 e48817ca2398
parent 83 2e6e98e9f8ef
child 93 a4501bbd1549
Add a workaround for error messages
src/com/beem/project/beem/service/ChatAdapter.java
src/com/beem/project/beem/service/Message.java
--- a/src/com/beem/project/beem/service/ChatAdapter.java	Tue Apr 07 21:50:45 2009 +0200
+++ b/src/com/beem/project/beem/service/ChatAdapter.java	Wed Apr 08 18:35:28 2009 +0200
@@ -46,6 +46,8 @@
 	send.setThread(message.getThread());
 	send.setSubject(message.getSubject());
 	send.setType(org.jivesoftware.smack.packet.Message.Type.chat);
+	// TODO gerer les messages contenant des XMPPError
+	// send.set
 	try {
 	    mAdaptee.sendMessage(send);
 	} catch (XMPPException e) {
--- a/src/com/beem/project/beem/service/Message.java	Tue Apr 07 21:50:45 2009 +0200
+++ b/src/com/beem/project/beem/service/Message.java	Wed Apr 08 18:35:28 2009 +0200
@@ -3,6 +3,8 @@
  */
 package com.beem.project.beem.service;
 
+import org.jivesoftware.smack.packet.XMPPError;
+
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.util.Log;
@@ -14,26 +16,31 @@
 public class Message implements Parcelable {
 
     /**
-     * Normal message type.
-     * Theese messages are like an email, with subject.
+     * Normal message type. Theese messages are like an email, with subject.
      */
-    public static  final int MSG_TYPE_NORMAL = 100;
+    public static final int MSG_TYPE_NORMAL = 100;
 
     /**
      * Chat message type.
      */
-    public static  final int MSG_TYPE_CHAT = 200;
+    public static final int MSG_TYPE_CHAT = 200;
 
     /**
      * Group chat message type.
      */
-    public static  final int MSG_TYPE_GROUP_CHAT = 300;
+    public static final int MSG_TYPE_GROUP_CHAT = 300;
+
+    /**
+     * Error message type.
+     */
+    public static final int MSG_TYPE_ERROR = 400;
 
     private int mType;
     private String mBody;
     private String mSubject;
     private String mTo;
     private String mThread;
+    // TODO ajouter l'erreur
 
     /**
      * Parcelable.Creator needs by Android.
@@ -53,8 +60,8 @@
 
     /**
      * Constructor.
-     * @param to	the destinataire of the message
-     * @param type	the message type
+     * @param to the destinataire of the message
+     * @param type the message type
      */
     public Message(final String to, final int type) {
 	mTo = to;
@@ -66,7 +73,7 @@
 
     /**
      * Constructor a message of type chat.
-     * @param to	the destinataire of the message
+     * @param to the destinataire of the message
      */
     public Message(final String to) {
 	this(to, MSG_TYPE_CHAT);
@@ -84,15 +91,29 @@
 	    case normal:
 		mType = MSG_TYPE_NORMAL;
 		break;
+	    // TODO gerer les message de type error
+	    // this a little work around waiting for a better handling of error messages
+	    case error:
+		mType = MSG_TYPE_ERROR;
+		break;
 	    default:
 		Log.w("BEEM_MESSAGE", "type de message non gerer" + smackMsg.getType());
 		break;
 	}
-	mBody = smackMsg.getBody();
-	mSubject = smackMsg.getSubject();
-	mThread = smackMsg.getThread();
+	if (mType == MSG_TYPE_ERROR) {
+	    XMPPError er = smackMsg.getError();
+	    String msg = er.getMessage();
+	    if (msg != null)
+		mBody = msg;
+	    else
+		mBody = er.getCondition();
+	} else {
+	    mBody = smackMsg.getBody();
+	    mSubject = smackMsg.getSubject();
+	    mThread = smackMsg.getThread();
+	}
     }
-    
+
     /**
      * Construct a message from a parcel.
      * @param in parcel to use for construction
@@ -123,7 +144,7 @@
      * @return the type of the message.
      */
     public int getType() {
-        return mType;
+	return mType;
     }
 
     /**
@@ -131,79 +152,71 @@
      * @param type the type to set
      */
     public void setType(int type) {
-        mType = type;
+	mType = type;
     }
 
-
     /**
      * Get the body of the message.
      * @return the Body of the message
      */
     public String getBody() {
-        return mBody;
+	return mBody;
     }
 
-
     /**
      * Set the body of the message.
      * @param body the body to set
      */
     public void setBody(String body) {
-        mBody = body;
+	mBody = body;
     }
 
-
     /**
      * Get the subject of the message.
      * @return the subject
      */
     public String getSubject() {
-        return mSubject;
+	return mSubject;
     }
 
-
     /**
      * Set the subject of the message.
      * @param subject the subject to set
      */
     public void setSubject(String subject) {
-        mSubject = subject;
+	mSubject = subject;
     }
 
-
     /**
      * Get the destinataire of the message.
      * @return the destinataire of the message
      */
     public String getTo() {
-        return mTo;
+	return mTo;
     }
 
-
     /**
      * Set the destinataire of the message.
      * @param to the destinataire to set
      */
     public void setTo(String to) {
-        mTo = to;
+	mTo = to;
     }
 
-
     /**
      * Get the thread of the message.
      * @return the thread
      */
     public String getThread() {
-        return mThread;
+	return mThread;
     }
 
-
     /**
      * Set the thread of the message.
      * @param thread the thread to set
      */
     public void setThread(String thread) {
-        mThread = thread;
+	mThread = thread;
     }
 
     /**