allow for very basic muc configuration

This commit is contained in:
Daniel Gultsch 2015-01-08 21:29:26 +01:00
parent 0fe193b027
commit a9159568b9
6 changed files with 229 additions and 118 deletions

View file

@ -13,7 +13,6 @@ import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.PresencePacket; import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.util.Log;
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
public class MucOptions { public class MucOptions {
@ -224,6 +223,10 @@ public class MucOptions {
return hasFeature("muc_membersonly"); return hasFeature("muc_membersonly");
} }
public boolean nonanonymous() {
return hasFeature("muc_nonanonymous");
}
public void deleteUser(String name) { public void deleteUser(String name) {
for (int i = 0; i < users.size(); ++i) { for (int i = 0; i < users.size(); ++i) {
if (users.get(i).getName().equals(name)) { if (users.get(i).getName().equals(name)) {
@ -244,7 +247,6 @@ public class MucOptions {
} }
public void processPacket(PresencePacket packet, PgpEngine pgp) { public void processPacket(PresencePacket packet, PgpEngine pgp) {
Log.d(Config.LOGTAG, packet.toString());
final Jid from = packet.getFrom(); final Jid from = packet.getFrom();
if (!from.isBareJid()) { if (!from.isBareJid()) {
final String name = from.getResourcepart(); final String name = from.getResourcepart();

View file

@ -1497,6 +1497,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
} }
conversation.getMucOptions().updateFeatures(features); conversation.getMucOptions().updateFeatures(features);
updateConversationUi();
} }
} }
}); });
@ -2229,7 +2230,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void onMucRosterUpdate(); public void onMucRosterUpdate();
} }
private interface OnConferenceOptionsPushed { public interface OnConferenceOptionsPushed {
public void onPushSucceeded(); public void onPushSucceeded();
public void onPushFailed(); public void onPushFailed();
} }

View file

@ -41,7 +41,7 @@ import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdat
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket; import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged { public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConferenceOptionsPushed {
public static final String ACTION_VIEW_MUC = "view_muc"; public static final String ACTION_VIEW_MUC = "view_muc";
private Conversation mConversation; private Conversation mConversation;
private OnClickListener inviteListener = new OnClickListener() { private OnClickListener inviteListener = new OnClickListener() {
@ -59,6 +59,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
private TextView mAccountJid; private TextView mAccountJid;
private LinearLayout membersView; private LinearLayout membersView;
private LinearLayout mMoreDetails; private LinearLayout mMoreDetails;
private TextView mConferenceType;
private ImageButton mChangeConferenceSettingsButton;
private Button mInviteButton; private Button mInviteButton;
private String uuid = null; private String uuid = null;
private List<User> users = new ArrayList<>(); private List<User> users = new ArrayList<>();
@ -94,6 +96,36 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
} }
}; };
private OnClickListener mChangeConferenceSettings = new OnClickListener() {
@Override
public void onClick(View v) {
final MucOptions mucOptions = mConversation.getMucOptions();
AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
builder.setTitle(R.string.conference_options);
String[] options = {getString(R.string.members_only),
getString(R.string.non_anonymous)};
final boolean[] values = new boolean[options.length];
values[0] = mucOptions.membersOnly();
values[1] = mucOptions.nonanonymous();
builder.setMultiChoiceItems(options,values,new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
values[which] = isChecked;
}
});
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.confirm,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
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);
}
});
builder.create().show();
}
};
@Override @Override
public void onConversationUpdate() { public void onConversationUpdate() {
@ -129,8 +161,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
mAccountJid = (TextView) findViewById(R.id.details_account); mAccountJid = (TextView) findViewById(R.id.details_account);
mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details); mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details);
mMoreDetails.setVisibility(View.GONE); mMoreDetails.setVisibility(View.GONE);
mChangeConferenceSettingsButton = (ImageButton) findViewById(R.id.change_conference_button);
mChangeConferenceSettingsButton.setOnClickListener(this.mChangeConferenceSettings);
mConferenceType = (TextView) findViewById(R.id.muc_conference_type);
mInviteButton = (Button) findViewById(R.id.invite); mInviteButton = (Button) findViewById(R.id.invite);
mInviteButton.setOnClickListener(inviteListener); mInviteButton.setOnClickListener(inviteListener);
mConferenceType = (TextView) findViewById(R.id.muc_conference_type);
if (getActionBar() != null) { if (getActionBar() != null) {
getActionBar().setHomeButtonEnabled(true); getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true);
@ -361,16 +397,17 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
} }
private void updateView() { private void updateView() {
final MucOptions mucOptions = mConversation.getMucOptions();
final User self = mucOptions.getSelf();
mAccountJid.setText(getString(R.string.using_account, mConversation mAccountJid.setText(getString(R.string.using_account, mConversation
.getAccount().getJid().toBareJid())); .getAccount().getJid().toBareJid()));
mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48))); mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
setTitle(mConversation.getName()); setTitle(mConversation.getName());
mFullJid.setText(mConversation.getJid().toBareJid().toString()); mFullJid.setText(mConversation.getJid().toBareJid().toString());
mYourNick.setText(mConversation.getMucOptions().getActualNick()); mYourNick.setText(mucOptions.getActualNick());
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role); mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
if (mConversation.getMucOptions().online()) { if (mucOptions.online()) {
mMoreDetails.setVisibility(View.VISIBLE); mMoreDetails.setVisibility(View.VISIBLE);
User self = mConversation.getMucOptions().getSelf();
final String status = getStatus(self); final String status = getStatus(self);
if (status != null) { if (status != null) {
mRoleAffiliaton.setVisibility(View.VISIBLE); mRoleAffiliaton.setVisibility(View.VISIBLE);
@ -378,9 +415,19 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
} else { } else {
mRoleAffiliaton.setVisibility(View.GONE); mRoleAffiliaton.setVisibility(View.GONE);
} }
if (mucOptions.membersOnly()) {
mConferenceType.setText(R.string.private_conference);
} else {
mConferenceType.setText(R.string.public_conference);
}
if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
mChangeConferenceSettingsButton.setVisibility(View.VISIBLE);
} else {
mChangeConferenceSettingsButton.setVisibility(View.GONE);
}
} }
this.users.clear(); this.users.clear();
this.users.addAll(mConversation.getMucOptions().getUsers()); this.users.addAll(mucOptions.getUsers());
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
membersView.removeAllViews(); membersView.removeAllViews();
for (final User user : mConversation.getMucOptions().getUsers()) { for (final User user : mConversation.getMucOptions().getUsers()) {
@ -479,7 +526,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override @Override
public void onAffiliationChangeFailed(Jid jid, int resId) { public void onAffiliationChangeFailed(Jid jid, int resId) {
displayToast(getString(resId,jid.toBareJid().toString()));
} }
@Override @Override
@ -488,7 +535,26 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
} }
@Override @Override
public void onRoleChangeFailed(String nick, int resid) { public void onRoleChangeFailed(String nick, int resId) {
displayToast(getString(resId,nick));
}
@Override
public void onPushSucceeded() {
displayToast(getString(R.string.modified_conference_options));
}
@Override
public void onPushFailed() {
displayToast(getString(R.string.could_not_modify_conference_options));
}
private void displayToast(final String msg) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(ConferenceDetailsActivity.this,msg,Toast.LENGTH_SHORT).show();
}
});
} }
} }

View file

@ -2,12 +2,12 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="@color/secondarybackground" > android:background="@color/secondarybackground">
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" > android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -15,28 +15,29 @@
android:layout_margin="8dp" android:layout_margin="8dp"
android:background="@drawable/infocard_border" android:background="@drawable/infocard_border"
android:orientation="vertical" android:orientation="vertical"
android:padding="16dp" > android:padding="16dp">
<TextView <TextView
android:id="@+id/muc_jabberid" android:id="@+id/muc_jabberid"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="@string/account_settings_example_jabber_id" android:text="@string/account_settings_example_jabber_id"
android:textColor="@color/primarytext" android:textColor="@color/primarytext"
android:textSize="?attr/TextSizeHeadline" android:textSize="?attr/TextSizeHeadline"
android:textStyle="bold" android:textStyle="bold"/>
android:layout_marginBottom="16dp"/>
<RelativeLayout <RelativeLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:layout_marginBottom="32dp">
<ImageView <ImageView
android:id="@+id/your_photo" android:id="@+id/your_photo"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:src="@drawable/ic_profile" > android:src="@drawable/ic_profile">
</ImageView> </ImageView>
<LinearLayout <LinearLayout
@ -45,7 +46,7 @@
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_toRightOf="@+id/your_photo" android:layout_toRightOf="@+id/your_photo"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="8dp" > android:paddingLeft="8dp">
<TextView <TextView
android:id="@+id/muc_your_nick" android:id="@+id/muc_your_nick"
@ -53,7 +54,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
android:textColor="@color/primarytext" android:textColor="@color/primarytext"
android:textSize="?attr/TextSizeHeadline" /> android:textSize="?attr/TextSizeHeadline"/>
<TextView <TextView
android:id="@+id/muc_role" android:id="@+id/muc_role"
@ -61,7 +62,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
android:textColor="@color/primarytext" android:textColor="@color/primarytext"
android:textSize="?attr/TextSizeBody" /> android:textSize="?attr/TextSizeBody"/>
</LinearLayout> </LinearLayout>
<ImageButton <ImageButton
@ -72,8 +73,34 @@
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:background="?android:selectableItemBackground" android:background="?android:selectableItemBackground"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/ic_action_edit_dark" /> android:src="@drawable/ic_action_edit_dark"/>
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/muc_conference_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/private_conference"
android:layout_centerVertical="true"
android:textColor="@color/primarytext"
android:textSize="?attr/TextSizeBody"
/>
<ImageButton
android:id="@+id/change_conference_button"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="?android:selectableItemBackground"
android:padding="8dp"
android:src="@drawable/ic_action_settings"/>
</RelativeLayout>
<TextView <TextView
android:id="@+id/details_account" android:id="@+id/details_account"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -82,7 +109,7 @@
android:layout_marginTop="32dp" android:layout_marginTop="32dp"
android:text="@string/using_account" android:text="@string/using_account"
android:textColor="@color/secondarytext" android:textColor="@color/secondarytext"
android:textSize="?attr/TextSizeInfo" /> android:textSize="?attr/TextSizeInfo"/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -92,7 +119,7 @@
android:layout_margin="8dp" android:layout_margin="8dp"
android:background="@drawable/infocard_border" android:background="@drawable/infocard_border"
android:orientation="vertical" android:orientation="vertical"
android:padding="8dp" > android:padding="8dp">
<LinearLayout <LinearLayout
@ -102,7 +129,7 @@
android:layout_weight="1" android:layout_weight="1"
android:divider="?android:dividerHorizontal" android:divider="?android:dividerHorizontal"
android:orientation="vertical" android:orientation="vertical"
android:showDividers="middle" > android:showDividers="middle">
</LinearLayout> </LinearLayout>
<Button <Button
@ -112,8 +139,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:text="@string/invite_contact" /> android:text="@string/invite_contact"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View file

@ -390,8 +390,16 @@
<string name="grant_admin_privileges">Administratorrechte gewähren</string> <string name="grant_admin_privileges">Administratorrechte gewähren</string>
<string name="remove_admin_privileges">Administratorrechte entziehen</string> <string name="remove_admin_privileges">Administratorrechte entziehen</string>
<string name="remove_from_room">Aus Konferenz entfernen</string> <string name="remove_from_room">Aus Konferenz entfernen</string>
<string name="could_not_change_affiliation">Zugehörigkeit kann nicht geändert werden</string> <string name="could_not_change_affiliation">Zugehörigkeit von %s konnte nicht verändernd werden</string>
<string name="ban_from_conference">Von Konferenz ausschließen.</string> <string name="ban_from_conference">Von Konferenz ausschließen.</string>
<string name="removing_from_public_conference">Du versuchst %s aus einer öffentlichen Konferenz zu entfernen. Die einzige Möglichkeit, dies dauerhaft zu tun, ist den Kontakt aus dieser Konferenz zu verbannen.</string> <string name="removing_from_public_conference">Du versuchst %s aus einer öffentlichen Konferenz zu entfernen. Die einzige Möglichkeit, dies dauerhaft zu tun, ist den Kontakt aus dieser Konferenz zu verbannen.</string>
<string name="ban_now">Kontakt ausschließen</string> <string name="ban_now">Kontakt ausschließen</string>
<string name="could_not_change_role">Rolle von %s konnte nicht geändert werden</string>
<string name="public_conference">Das ist eine öffentlich zugängliche Konferenz</string>
<string name="private_conference">Das ist eine private Konferenz nur für Mitglieder</string>
<string name="conference_options">Konferenzoptionen</string>
<string name="members_only">Privat (Nur für Mitglieder)</string>
<string name="non_anonymous">De-anonymisiert</string>
<string name="modified_conference_options">Konferenzoptionen wurden modifiziert!</string>
<string name="could_not_modify_conference_options">Konferenzoptionen konnten nicht modifiziert werden</string>
</resources> </resources>

View file

@ -416,9 +416,16 @@
<string name="grant_admin_privileges">Grant admin privileges</string> <string name="grant_admin_privileges">Grant admin privileges</string>
<string name="remove_admin_privileges">Revoke admin privileges</string> <string name="remove_admin_privileges">Revoke admin privileges</string>
<string name="remove_from_room">Remove from conference</string> <string name="remove_from_room">Remove from conference</string>
<string name="could_not_change_affiliation">Could not change affiliation</string> <string name="could_not_change_affiliation">Could not change affiliation of %s</string>
<string name="ban_from_conference">Ban from conference</string> <string name="ban_from_conference">Ban from conference</string>
<string name="removing_from_public_conference">You are trying to remove %s from a public conference. The only way to do that is to ban that user for ever.</string> <string name="removing_from_public_conference">You are trying to remove %s from a public conference. The only way to do that is to ban that user for ever.</string>
<string name="ban_now">Ban now</string> <string name="ban_now">Ban now</string>
<string name="could_not_change_role">Could not change role</string> <string name="could_not_change_role">Could not change role of %s</string>
<string name="public_conference">This is a publicly accessible conference</string>
<string name="private_conference">This is a private, members only conference</string>
<string name="conference_options">Conference options</string>
<string name="members_only">Private (Members only)</string>
<string name="non_anonymous">Non-anonymous</string>
<string name="modified_conference_options">Modified conference options!</string>
<string name="could_not_modify_conference_options">Could not modify conference options</string>
</resources> </resources>