diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java index 71edda951..a3a048674 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java @@ -946,7 +946,8 @@ public class ContactsController extends BaseController implements SearchView.OnQ ((UserItem) adapter.getItem(position)).flipItemSelection(); adapter.toggleSelection(position); - if (currentUser.hasSpreedCapabilityWithName("last-room-activity") && + if (currentUser.hasSpreedCapabilityWithName("last-room-activity") + && !currentUser.hasSpreedCapabilityWithName("invite-groups-and-mails") && "groups".equals(((UserItem) adapter.getItem(position)).getModel().getSource()) && adapter.getSelectedItemCount() > 1) { List selectedPositions = adapter.getSelectedPositions(); diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java index c772fd759..77c0c141e 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/OperationsMenuController.java @@ -119,7 +119,7 @@ public class OperationsMenuController extends BaseController { private Conversation.RoomType conversationType; private ArrayList invitedUsers = new ArrayList<>(); - private ArrayList invitedGroup = new ArrayList<>(); + private ArrayList invitedGroups = new ArrayList<>(); private List spreedCapabilities; private String credentials; @@ -139,7 +139,7 @@ public class OperationsMenuController extends BaseController { } if (args.containsKey(BundleKeys.KEY_INVITED_GROUP)) { - this.invitedGroup = args.getStringArrayList(BundleKeys.KEY_INVITED_GROUP); + this.invitedGroups = args.getStringArrayList(BundleKeys.KEY_INVITED_GROUP); } if (args.containsKey(BundleKeys.KEY_CONVERSATION_TYPE)) { @@ -275,8 +275,8 @@ public class OperationsMenuController extends BaseController { boolean isGroupCallWorkaround = false; String invite = null; - if (invitedGroup.size() > 0) { - invite = invitedGroup.get(0); + if (invitedGroups.size() > 0) { + invite = invitedGroups.get(0); } if (conversationType.equals(Conversation.RoomType.ROOM_PUBLIC_CALL) || @@ -513,43 +513,86 @@ public class OperationsMenuController extends BaseController { private void inviteUsersToAConversation() { RetrofitBucket retrofitBucket; final ArrayList localInvitedUsers = invitedUsers; - if (localInvitedUsers.size() > 0) { - for (int i = 0; i < invitedUsers.size(); i++) { - final String userId = invitedUsers.get(i); - retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(currentUser.getBaseUrl(), conversation.getToken(), - userId); + final ArrayList localInvitedGroups = invitedGroups; + localInvitedGroups.remove(0); + if (localInvitedUsers.size() > 0 || (localInvitedGroups.size() > 0 && currentUser.hasSpreedCapabilityWithName("invite-groups-and-mails"))) { + if ((localInvitedGroups.size() > 0 && currentUser.hasSpreedCapabilityWithName("invite-groups-and-mails"))) { + for (int i = 0; i < localInvitedGroups.size(); i++) { + final String groupId = localInvitedGroups.get(i); + retrofitBucket = ApiUtils.getRetrofitBucketForAddGroupParticipant(currentUser.getBaseUrl(), conversation.getToken(), + groupId); - ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) - .subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.mainThread()) - .retry(1) - .subscribe(new Observer() { - @Override - public void onSubscribe(Disposable d) { + ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .retry(1) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { - } - - @Override - public void onNext(AddParticipantOverall addParticipantOverall) { - } - - @Override - public void onError(Throwable e) { - dispose(); - } - - @Override - public void onComplete() { - synchronized (localInvitedUsers) { - localInvitedUsers.remove(userId); } - if (localInvitedUsers.size() == 0) { - initiateConversation(true, null); + @Override + public void onNext(AddParticipantOverall addParticipantOverall) { } - dispose(); - } - }); + + @Override + public void onError(Throwable e) { + dispose(); + } + + @Override + public void onComplete() { + synchronized (localInvitedGroups) { + localInvitedGroups.remove(localInvitedGroups); + } + + if (localInvitedGroups.size() == 0 && localInvitedUsers.size() == 0) { + initiateConversation(true, null); + } + dispose(); + } + }); + + } + + for (int i = 0; i < localInvitedGroups.size(); i++) { + final String userId = invitedUsers.get(i); + retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(currentUser.getBaseUrl(), conversation.getToken(), + userId); + + ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .retry(1) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(AddParticipantOverall addParticipantOverall) { + } + + @Override + public void onError(Throwable e) { + dispose(); + } + + @Override + public void onComplete() { + synchronized (localInvitedUsers) { + localInvitedUsers.remove(userId); + } + + if (localInvitedUsers.size() == 0) { + initiateConversation(true, null); + } + dispose(); + } + }); + } } } else { if (!currentUser.hasSpreedCapabilityWithName("chat-v2")) { diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index 044bfc4d0..85c0bd701 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -132,6 +132,18 @@ public class ApiUtils { } + public static RetrofitBucket getRetrofitBucketForAddGroupParticipant(String baseUrl, String token, String group) { + RetrofitBucket retrofitBucket = getRetrofitBucketForAddParticipant(baseUrl, token, group); + retrofitBucket.getQueryMap().put("source", "groups"); + return retrofitBucket; + } + + public static RetrofitBucket getRetrofitBucketForAddMailParticipant(String baseUrl, String token, String mail) { + RetrofitBucket retrofitBucket = getRetrofitBucketForAddParticipant(baseUrl, token, mail); + retrofitBucket.getQueryMap().put("source", "emails"); + return retrofitBucket; + } + public static String getUrlForRemoveSelfFromRoom(String baseUrl, String token) { return baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token + "/participants/self"; }