ensure that everyone is member before making a room private
This commit is contained in:
parent
fa9cba930f
commit
d9f88c4669
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue