aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations
diff options
context:
space:
mode:
authorDaniel Gultsch <inputmice@siacs.eu>2015-01-09 13:28:01 +0100
committerDaniel Gultsch <inputmice@siacs.eu>2015-01-09 13:28:01 +0100
commitd9f88c4669b024530301fe9e48d70d42bd56190f (patch)
tree3d0d65561544f1d995fca84b7b45949160b16645 /src/main/java/eu/siacs/conversations
parentfa9cba930f0aa256522fe1bc4c4e32c0f4b4faf3 (diff)
ensure that everyone is member before making a room private
Diffstat (limited to 'src/main/java/eu/siacs/conversations')
-rw-r--r--src/main/java/eu/siacs/conversations/generator/IqGenerator.java16
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java13
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java9
3 files changed, 32 insertions, 6 deletions
diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
index 6dcccaab7..d09658211 100644
--- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
@@ -1,5 +1,6 @@
package eu.siacs.conversations.generator;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -151,12 +152,21 @@ public class IqGenerator extends AbstractGenerator {
}
public IqPacket changeAffiliation(Conversation conference, Jid jid, String affiliation) {
+ List<Jid> jids = new ArrayList<>();
+ jids.add(jid);
+ return changeAffiliation(conference,jids,affiliation);
+ }
+
+ public IqPacket changeAffiliation(Conversation conference, List<Jid> jids, String affiliation) {
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
packet.setTo(conference.getJid().toBareJid());
packet.setFrom(conference.getAccount().getJid());
- Element item = packet.query("http://jabber.org/protocol/muc#admin").addChild("item");
- item.setAttribute("jid", jid.toString());
- item.setAttribute("affiliation", affiliation);
+ Element query = packet.query("http://jabber.org/protocol/muc#admin");
+ for(Jid jid : jids) {
+ Element item = query.addChild("item");
+ item.setAttribute("jid", jid.toString());
+ item.setAttribute("affiliation", affiliation);
+ }
return packet;
}
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index e13a3e657..28a353b6e 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -1547,11 +1547,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void changeAffiliationInConference(final Conversation conference, Jid user, MucOptions.Affiliation affiliation, final OnAffiliationChanged callback) {
final Jid jid = user.toBareJid();
IqPacket request = this.mIqGenerator.changeAffiliation(conference, jid, affiliation.toString());
- Log.d(Config.LOGTAG,request.toString());
sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
- Log.d(Config.LOGTAG, packet.toString());
if (packet.getType() == IqPacket.TYPE.RESULT) {
callback.onAffiliationChangedSuccessful(jid);
} else {
@@ -1561,6 +1559,17 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
});
}
+ public void changeAffiliationsInConference(final Conversation conference, MucOptions.Affiliation before, MucOptions.Affiliation after) {
+ List<Jid> jids = new ArrayList<>();
+ for(MucOptions.User user : conference.getMucOptions().getUsers()) {
+ if (user.getAffiliation() == before) {
+ jids.add(user.getJid());
+ }
+ }
+ IqPacket request = this.mIqGenerator.changeAffiliation(conference, jids, after.toString());
+ sendIqPacket(conference.getAccount(), request, null);
+ }
+
public interface OnAffiliationChanged {
public void onAffiliationChangedSuccessful(Jid jid);
public void onAffiliationChangeFailed(Jid jid, int resId);
diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
index ce3672407..9e38790a6 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
@@ -117,10 +117,17 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
builder.setPositiveButton(R.string.confirm,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
+ if (!mucOptions.membersOnly() && values[0]) {
+ xmppConnectionService.changeAffiliationsInConference(mConversation,
+ MucOptions.Affiliation.NONE,
+ MucOptions.Affiliation.MEMBER);
+ }
Bundle options = new Bundle();
options.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0");
options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
- xmppConnectionService.pushConferenceConfiguration(mConversation,options,ConferenceDetailsActivity.this);
+ xmppConnectionService.pushConferenceConfiguration(mConversation,
+ options,
+ ConferenceDetailsActivity.this);
}
});
builder.create().show();