make newly created conferences private by default

This commit is contained in:
Daniel Gultsch 2016-05-26 12:39:31 +02:00
parent c4e82eb3f8
commit 841e718d6a
5 changed files with 32 additions and 10 deletions

View file

@ -118,6 +118,7 @@ public class MucOptions {
public static final String STATUS_CODE_ROOM_CONFIG_CHANGED = "104";
public static final String STATUS_CODE_SELF_PRESENCE = "110";
public static final String STATUS_CODE_ROOM_CREATED = "201";
public static final String STATUS_CODE_BANNED = "301";
public static final String STATUS_CODE_CHANGED_NICK = "303";
public static final String STATUS_CODE_KICKED = "307";

View file

@ -1,6 +1,7 @@
package eu.siacs.conversations.generator;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
@ -343,4 +344,13 @@ public class IqGenerator extends AbstractGenerator {
packet.query("http://jabber.org/protocol/muc#admin").addChild("item").setAttribute("affiliation",affiliation);
return packet;
}
public static Bundle defaultRoomConfiguration() {
Bundle options = new Bundle();
options.putString("muc#roomconfig_persistentroom", "1");
options.putString("muc#roomconfig_membersonly", "1");
options.putString("muc#roomconfig_publicroom", "0");
options.putString("muc#roomconfig_whois", "anyone");
return options;
}
}

View file

@ -14,6 +14,7 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.Presence;
import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.generator.PresenceGenerator;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
@ -77,6 +78,15 @@ public class PresenceParser extends AbstractParser implements
} else {
mucOptions.addUser(user);
}
if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED)) {
Log.d(Config.LOGTAG,mucOptions.getAccount().getJid().toBareJid()
+": room '"
+mucOptions.getConversation().getJid().toBareJid()
+"' created. pushing default configuration");
mXmppConnectionService.pushConferenceConfiguration(mucOptions.getConversation(),
IqGenerator.defaultRoomConfiguration(),
null);
}
if (mXmppConnectionService.getPgpEngine() != null) {
Element signed = packet.findChild("x", "jabber:x:signed");
if (signed != null) {

View file

@ -2034,7 +2034,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return null;
}
public void createAdhocConference(final Account account, final Iterable<Jid> jids, final UiCallback<Conversation> callback) {
public void createAdhocConference(final Account account,
final String subject,
final Iterable<Jid> jids,
final UiCallback<Conversation> callback) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": creating adhoc conference with " + jids.toString());
if (account.getStatus() == Account.State.ONLINE) {
try {
@ -2045,20 +2048,18 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
return;
}
String name = new BigInteger(75, getRNG()).toString(32);
Jid jid = Jid.fromParts(name, server, null);
String localpart = new BigInteger(75, getRNG()).toString(32);
Jid jid = Jid.fromParts(localpart, server, null);
final Conversation conversation = findOrCreateConversation(account, jid, true);
joinMuc(conversation, new OnConferenceJoined() {
@Override
public void onConferenceJoined(final Conversation conversation) {
Bundle options = new Bundle();
options.putString("muc#roomconfig_persistentroom", "1");
options.putString("muc#roomconfig_membersonly", "1");
options.putString("muc#roomconfig_publicroom", "0");
options.putString("muc#roomconfig_whois", "anyone");
pushConferenceConfiguration(conversation, options, new OnConferenceOptionsPushed() {
pushConferenceConfiguration(conversation, IqGenerator.defaultRoomConfiguration(), new OnConferenceOptionsPushed() {
@Override
public void onPushSucceeded() {
if (subject != null && !subject.trim().isEmpty()) {
pushSubjectToConference(conversation, subject);
}
for (Jid invite : jids) {
invite(conversation, invite);
}

View file

@ -1159,7 +1159,7 @@ public abstract class XmppActivity extends Activity {
}
} else {
jids.add(conversation.getJid().toBareJid());
service.createAdhocConference(conversation.getAccount(), jids, activity.adhocCallback);
service.createAdhocConference(conversation.getAccount(), null, jids, activity.adhocCallback);
}
}
}