muc message available
authorVincent V.<marseille@beem-project.com>
Wed, 22 Feb 2012 00:29:10 +0100
changeset 935 5801f1f5f0bd
parent 934 53e19596d22c
child 936 5cfaa17be49e
muc message available
AndroidManifest.xml
src/com/beem/project/beem/BeemIntent.java
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/MucChat.java
--- a/AndroidManifest.xml	Tue Feb 21 20:10:27 2012 +0100
+++ b/AndroidManifest.xml	Wed Feb 22 00:29:10 2012 +0100
@@ -205,6 +205,7 @@
                 <action android:name="com.beem.project.beem.intent.action.ADD_CONTACT" />
                 <action android:name="com.beem.project.beem.intent.action.CHANGE_STATUS" />
                 <action android:name="com.beem.project.beem.intent.action.MUC_JOIN" />
+                <action android:name="com.beem.project.beem.intent.action.MUC_SEND_MESSAGE" />
             </intent-filter>
         </service>
     </application>
--- a/src/com/beem/project/beem/BeemIntent.java	Tue Feb 21 20:10:27 2012 +0100
+++ b/src/com/beem/project/beem/BeemIntent.java	Wed Feb 22 00:29:10 2012 +0100
@@ -58,9 +58,11 @@
     public static final String ACTION_ADD_CONTACT = "com.beem.project.beem.intent.action.ADD_CONTACT";
 
     public static final String ACTION_CHANGE_STATUS = "com.beem.project.beem.intent.action.CHANGE_STATUS";
-    
+
     public static final String ACTION_MUC_JOIN = "com.beem.project.beem.intent.action.MUC_JOIN";
 
+    public static final String ACTION_MUC_SEND_MESSAGE = "com.beem.project.beem.intent.action.MUC_SEND_MESSAGE";
+
     /* Broadcast Receiver's action */
     public static final String ACTION_CONNECTED = "com.beem.project.beem.intent.action.CONNECTED";
 
--- a/src/com/beem/project/beem/BeemService.java	Tue Feb 21 20:10:27 2012 +0100
+++ b/src/com/beem/project/beem/BeemService.java	Wed Feb 22 00:29:10 2012 +0100
@@ -117,8 +117,7 @@
     private static final int MESSAGE_ADD_CONTACT = 0x5;
     private static final int MESSAGE_CHANGE_STATUS = 0x7;
     private static final int MESSAGE_MUC_JOIN = 0x8;
-
-    //Next = 0x9;
+    private static final int MESSAGE_MUC_SEND_MSG = 0x9;
 
     private Map<String, XmppConnectionAdapter> mConnection = new HashMap<String, XmppConnectionAdapter>();
     private Map<String, BeemConnection> mBeemConnection = new HashMap<String, BeemConnection>();
@@ -441,6 +440,8 @@
 	    msg = mHandler.obtainMessage(MESSAGE_CHANGE_STATUS, intent.getExtras());
 	} else if (BeemIntent.ACTION_MUC_JOIN.equals(action)) {
 	    msg = mHandler.obtainMessage(MESSAGE_MUC_JOIN, intent.getExtras());
+	} else if (BeemIntent.ACTION_MUC_SEND_MESSAGE.equals(action)) {
+	    msg = mHandler.obtainMessage(MESSAGE_MUC_SEND_MSG, intent.getExtras());
 	} else {
 	    Log.w(TAG, "Unknown intent " + intent);
 	}
@@ -541,6 +542,15 @@
 			Log.e(TAG, "MUC Join Problem", e);
 		    }
 		    break;
+		case MESSAGE_MUC_SEND_MSG:
+		    MultiUserChat mucmsg = new MultiUserChat(connection.getAdaptee(), b.getString(BeemIntent.EXTRA_JID));
+		    try {
+			Log.e(TAG, "-" + b.getString(BeemIntent.EXTRA_MESSAGE));
+			mucmsg.sendMessage(b.getString(BeemIntent.EXTRA_MESSAGE));
+		    } catch (XMPPException e) {
+			Log.e(TAG, "Error send message to muc", e);
+		    }
+		    break;
 		default:
 		    Log.w(TAG, "Unknown message " + msg);
 	    }
--- a/src/com/beem/project/beem/ui/ContactList.java	Tue Feb 21 20:10:27 2012 +0100
+++ b/src/com/beem/project/beem/ui/ContactList.java	Wed Feb 22 00:29:10 2012 +0100
@@ -577,6 +577,7 @@
 
 	    Intent i = new Intent(ContactList.this, MucChat.class);
 	    i.setData(Uri.parse("imto://jabber/" + jid));
+	    i.putExtra(BeemIntent.EXTRA_ACCOUNT, mAccountName);
 	    startActivity(i);
 	}
     }
--- a/src/com/beem/project/beem/ui/MucChat.java	Tue Feb 21 20:10:27 2012 +0100
+++ b/src/com/beem/project/beem/ui/MucChat.java	Wed Feb 22 00:29:10 2012 +0100
@@ -54,7 +54,6 @@
 import android.net.Uri;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
-import android.provider.ContactsContract.RawContacts;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
@@ -100,17 +99,7 @@
 
 	Uri contactURI = getIntent().getData();
 	mjid = contactURI.getPathSegments().get(0);
-
-	Cursor cursorAccount = getContentResolver().query(RawContacts.CONTENT_URI,
-	    new String[] { RawContacts._ID, RawContacts.ACCOUNT_NAME }, RawContacts.SOURCE_ID + "=?",
-	    new String[] { mjid }, null);
-
-	if (cursorAccount.getCount() == 1) {
-	    cursorAccount.moveToFirst();
-	    mAccount = cursorAccount.getString(cursorAccount.getColumnIndex(RawContacts.ACCOUNT_NAME));
-	} else if (cursorAccount.getCount() > 1) {
-	    // TODO : get account from jid. if multi account propose select
-	}
+	mAccount = getIntent().getExtras().getString(BeemIntent.EXTRA_ACCOUNT);
 
 	SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
 	boolean isCompact = settings.getBoolean("settings_chat_compact_key", false);
@@ -174,8 +163,8 @@
     private void sendMessage() {
 	EditText inputField = (EditText) findViewById(R.id.chat_input);
 	final String inputContent = inputField.getText().toString();
-
-	Intent intent = new Intent(BeemIntent.ACTION_SEND_MESSAGE);
+	Log.e(TAG, "+" + inputContent);
+	Intent intent = new Intent(BeemIntent.ACTION_MUC_SEND_MESSAGE);
 	intent.putExtra(BeemIntent.EXTRA_ACCOUNT, mAccount);
 	intent.putExtra(BeemIntent.EXTRA_JID, mjid);
 	intent.putExtra(BeemIntent.EXTRA_MESSAGE, inputContent);