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;
|
package eu.siacs.conversations.generator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -151,12 +152,21 @@ public class IqGenerator extends AbstractGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket changeAffiliation(Conversation conference, Jid jid, String affiliation) {
|
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);
|
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
packet.setTo(conference.getJid().toBareJid());
|
packet.setTo(conference.getJid().toBareJid());
|
||||||
packet.setFrom(conference.getAccount().getJid());
|
packet.setFrom(conference.getAccount().getJid());
|
||||||
Element item = packet.query("http://jabber.org/protocol/muc#admin").addChild("item");
|
Element query = packet.query("http://jabber.org/protocol/muc#admin");
|
||||||
item.setAttribute("jid", jid.toString());
|
for(Jid jid : jids) {
|
||||||
item.setAttribute("affiliation", affiliation);
|
Element item = query.addChild("item");
|
||||||
|
item.setAttribute("jid", jid.toString());
|
||||||
|
item.setAttribute("affiliation", affiliation);
|
||||||
|
}
|
||||||
return packet;
|
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) {
|
public void changeAffiliationInConference(final Conversation conference, Jid user, MucOptions.Affiliation affiliation, final OnAffiliationChanged callback) {
|
||||||
final Jid jid = user.toBareJid();
|
final Jid jid = user.toBareJid();
|
||||||
IqPacket request = this.mIqGenerator.changeAffiliation(conference, jid, affiliation.toString());
|
IqPacket request = this.mIqGenerator.changeAffiliation(conference, jid, affiliation.toString());
|
||||||
Log.d(Config.LOGTAG,request.toString());
|
|
||||||
sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() {
|
sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() {
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(Account account, IqPacket packet) {
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
||||||
Log.d(Config.LOGTAG, packet.toString());
|
|
||||||
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||||
callback.onAffiliationChangedSuccessful(jid);
|
callback.onAffiliationChangedSuccessful(jid);
|
||||||
} else {
|
} 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 interface OnAffiliationChanged {
|
||||||
public void onAffiliationChangedSuccessful(Jid jid);
|
public void onAffiliationChangedSuccessful(Jid jid);
|
||||||
public void onAffiliationChangeFailed(Jid jid, int resId);
|
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() {
|
builder.setPositiveButton(R.string.confirm,new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
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();
|
Bundle options = new Bundle();
|
||||||
options.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0");
|
options.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0");
|
||||||
options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
|
options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
|
||||||
xmppConnectionService.pushConferenceConfiguration(mConversation,options,ConferenceDetailsActivity.this);
|
xmppConnectionService.pushConferenceConfiguration(mConversation,
|
||||||
|
options,
|
||||||
|
ConferenceDetailsActivity.this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
|
|
Loading…
Reference in a new issue