use of org.awesomeapp.messenger.service.IChatSessionManager in project Zom-Android by zom.
the class MainActivity method startGroupChat.
public void startGroupChat(String room, String server, String nickname, final ArrayList<String> invitees, IImConnection conn) {
mLastConnGroup = conn;
new AsyncTask<String, Long, String>() {
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
dialog = new ProgressDialog(MainActivity.this);
dialog.setMessage(getString(R.string.connecting_to_group_chat_));
dialog.setCancelable(true);
dialog.show();
}
@Override
protected String doInBackground(String... params) {
String subject = params[0];
String chatRoom = "group" + UUID.randomUUID().toString().substring(0, 8);
String server = params[1];
try {
IChatSessionManager manager = mLastConnGroup.getChatSessionManager();
String roomAddress = (chatRoom + '@' + server).toLowerCase(Locale.US);
String nickname = params[2];
IChatSession session = manager.getChatSession(roomAddress);
if (session == null) {
session = manager.createMultiUserChatSession(roomAddress, subject, nickname, true);
if (session != null) {
mRequestedChatId = session.getId();
publishProgress(mRequestedChatId);
} else {
return getString(R.string.unable_to_create_or_join_group_chat);
}
} else {
mRequestedChatId = session.getId();
publishProgress(mRequestedChatId);
}
if (invitees != null && invitees.size() > 0) {
// wait a second for the server to sort itself out
try {
Thread.sleep(100);
} catch (Exception e) {
}
for (String invitee : invitees) session.inviteContact(invitee);
}
return null;
} catch (RemoteException e) {
return e.toString();
}
}
@Override
protected void onProgressUpdate(Long... showChatId) {
showChat(showChatId[0]);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (dialog.isShowing()) {
dialog.dismiss();
}
if (result != null) {
// mHandler.showServiceErrorAlert(result);
}
}
}.executeOnExecutor(ImApp.sThreadPoolExecutor, room, server, nickname);
}
Aggregations