private QBGroupChat createChatIfNotExist(QBDialog dialog) throws QBResponseException { boolean notNull = Utils.validateNotNull(groupChatManager); if (!notNull) { ErrorUtils.logError(TAG, " groupChatManager is NULL"); throw new QBResponseException(context.getString(R.string.dlg_fail_create_chat)); } groupChat = groupChatManager.getGroupChat(dialog.getRoomJid()); if (groupChat == null) { groupChat = groupChatManager.createGroupChat(dialog.getRoomJid()); groupChat.addMessageListener(roomChatMessageListener); } return groupChat; }
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); } }
private void updateDialog(QBDialog dialog, QBCustomObjectUpdateBuilder requestBuilder) throws QBResponseException { QBDialog updatedDialog = groupChatManager.updateDialog(dialog, requestBuilder); ArrayList<Integer> friendsList = new ArrayList<Integer>(updatedDialog.getOccupants()); friendsList.remove(chatCreator.getId()); notifyFriendsRoomUpdate(updatedDialog, friendsList); DatabaseManager.saveDialog(context, updatedDialog); }
public void leaveRoomChat(String roomJid) throws XMPPException, SmackException.NotConnectedException, QBResponseException { groupChatManager.getGroupChat(roomJid).leave(); List<Integer> userIdsList = new ArrayList<Integer>(); userIdsList.add(chatCreator.getId()); removeUsersFromRoom(roomJid, userIdsList); DatabaseManager.deleteDialogByRoomJid(context, roomJid); }
public void leaveDialogs() throws XMPPException, SmackException.NotConnectedException { if (groupDialogsList != null) { for (QBDialog dialog : groupDialogsList) { QBGroupChat roomChat = groupChatManager.getGroupChat(dialog.getRoomJid()); if (roomChat != null && roomChat.isJoined()) { roomChat.leave(); } } } }
public QBDialog createGroupChat(String name, List<Integer> friendIdsList, QBDialogType type) throws Exception { ArrayList<Integer> occupantIdsList = ChatUtils.getOccupantIdsWithUser(friendIdsList); QBDialog dialogToCreate = new QBDialog(); dialogToCreate.setName(name); dialogToCreate.setType(type); dialogToCreate.setOccupantsIds(occupantIdsList); QBDialog dialog = groupChatManager.createDialog(dialogToCreate); joinRoomChat(dialog); inviteFriendsToRoom(dialog, friendIdsList); saveDialogToCache(context, dialog); return dialog; }
public List<Integer> getRoomOnlineParticipantList(String roomJid) throws XMPPException { return new ArrayList<Integer>(groupChatManager.getGroupChat(roomJid).getOnlineUsers()); }