private void sendRoomMessage(QBChatMessage chatMessage, String roomJId, String dialogId) throws QBResponseException { groupChat = groupChatManager.getGroupChat(roomJId); QBDialog existingDialog = null; if (groupChat == null) { existingDialog = ChatUtils.getExistDialogById(context, dialogId); groupChat = (QBGroupChat) createChatLocally(existingDialog, null); } String error = null; if (!TextUtils.isEmpty(dialogId)) { chatMessage.setProperty(ChatUtils.PROPERTY_DIALOG_ID, dialogId); } try { groupChat.sendMessage(chatMessage); } catch (XMPPException e) { error = context.getString(R.string.dlg_fail_send_msg); } catch (SmackException.NotConnectedException e) { error = context.getString(R.string.dlg_fail_connection); } catch (IllegalStateException e) { ErrorUtils.showError(context, context.getString(R.string.dlg_not_joined_room)); tryJoinRoomChat(existingDialog); } if (error != null) { throw new QBResponseException(error); } }