hide lock icon in channels; modify muc user context

This commit is contained in:
Daniel Gultsch 2019-02-07 13:18:42 +01:00
parent b6a501d24b
commit ad64058d25
12 changed files with 91 additions and 94 deletions

View File

@ -840,40 +840,6 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}); });
} }
public enum AxolotlCapability {
FULL,
MISSING_PRESENCE,
MISSING_KEYS,
WRONG_CONFIGURATION,
NO_MEMBERS
}
public boolean isConversationAxolotlCapable(Conversation conversation) {
return conversation.isSingleOrPrivateAndNonAnonymous();
}
public Pair<AxolotlCapability, Jid> isConversationAxolotlCapableDetailed(Conversation conversation) {
if (conversation.isSingleOrPrivateAndNonAnonymous()) {
final List<Jid> jids = getCryptoTargets(conversation);
for (Jid jid : jids) {
if (!hasAny(jid) && (!deviceIds.containsKey(jid) || deviceIds.get(jid).isEmpty())) {
if (conversation.getAccount().getRoster().getContact(jid).mutualPresenceSubscription()) {
return new Pair<>(AxolotlCapability.MISSING_KEYS, jid);
} else {
return new Pair<>(AxolotlCapability.MISSING_PRESENCE, jid);
}
}
}
if (jids.size() > 0) {
return new Pair<>(AxolotlCapability.FULL, null);
} else {
return new Pair<>(AxolotlCapability.NO_MEMBERS, null);
}
} else {
return new Pair<>(AxolotlCapability.WRONG_CONFIGURATION, null);
}
}
public List<Jid> getCryptoTargets(Conversation conversation) { public List<Jid> getCryptoTargets(Conversation conversation) {
final List<Jid> jids; final List<Jid> jids;
if (conversation.getMode() == Conversation.MODE_SINGLE) { if (conversation.getMode() == Conversation.MODE_SINGLE) {

View File

@ -60,9 +60,10 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
private static final String ATTRIBUTE_NEXT_MESSAGE_TIMESTAMP = "next_message_timestamp"; private static final String ATTRIBUTE_NEXT_MESSAGE_TIMESTAMP = "next_message_timestamp";
private static final String ATTRIBUTE_CRYPTO_TARGETS = "crypto_targets"; private static final String ATTRIBUTE_CRYPTO_TARGETS = "crypto_targets";
private static final String ATTRIBUTE_NEXT_ENCRYPTION = "next_encryption"; private static final String ATTRIBUTE_NEXT_ENCRYPTION = "next_encryption";
public static final String ATTRIBUTE_MEMBERS_ONLY = "members_only"; static final String ATTRIBUTE_MEMBERS_ONLY = "members_only";
public static final String ATTRIBUTE_MODERATED = "moderated"; static final String ATTRIBUTE_MODERATED = "moderated";
public static final String ATTRIBUTE_NON_ANONYMOUS = "non_anonymous"; static final String ATTRIBUTE_NON_ANONYMOUS = "non_anonymous";
public static final String ATTRIBUTE_FORMERLY_PRIVATE_NON_ANONYMOUS = "formerly_private_non_anonymous";
protected final ArrayList<Message> messages = new ArrayList<>(); protected final ArrayList<Message> messages = new ArrayList<>();
public AtomicBoolean messagesLoaded = new AtomicBoolean(true); public AtomicBoolean messagesLoaded = new AtomicBoolean(true);
protected Account account = null; protected Account account = null;
@ -74,7 +75,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
private int status; private int status;
private long created; private long created;
private int mode; private int mode;
private JSONObject attributes = new JSONObject(); private JSONObject attributes;
private Jid nextCounterpart; private Jid nextCounterpart;
private transient MucOptions mucOptions = null; private transient MucOptions mucOptions = null;
private boolean messagesLeftOnServer = true; private boolean messagesLeftOnServer = true;
@ -653,12 +654,11 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
if (Config.OMEMO_EXCEPTIONS.CONTACT_DOMAINS.contains(contact) || Config.OMEMO_EXCEPTIONS.ACCOUNT_DOMAINS.contains(account)) { if (Config.OMEMO_EXCEPTIONS.CONTACT_DOMAINS.contains(contact) || Config.OMEMO_EXCEPTIONS.ACCOUNT_DOMAINS.contains(account)) {
return false; return false;
} }
final AxolotlService axolotlService = conversation.getAccount().getAxolotlService(); return conversation.isSingleOrPrivateAndNonAnonymous() || conversation.getBooleanAttribute(ATTRIBUTE_FORMERLY_PRIVATE_NON_ANONYMOUS, false);
return axolotlService != null && axolotlService.isConversationAxolotlCapable(conversation);
} }
public void setNextEncryption(int encryption) { public boolean setNextEncryption(int encryption) {
this.setAttribute(ATTRIBUTE_NEXT_ENCRYPTION, String.valueOf(encryption)); return this.setAttribute(ATTRIBUTE_NEXT_ENCRYPTION, encryption);
} }
public String getNextMessage() { public String getNextMessage() {
@ -772,15 +772,17 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
} }
public boolean setAttribute(String key, boolean value) { public boolean setAttribute(String key, boolean value) {
boolean prev = getBooleanAttribute(key,false); return setAttribute(key, String.valueOf(value));
setAttribute(key,Boolean.toString(value));
return prev != value;
} }
private boolean setAttribute(String key, long value) { private boolean setAttribute(String key, long value) {
return setAttribute(key, Long.toString(value)); return setAttribute(key, Long.toString(value));
} }
private boolean setAttribute(String key, int value) {
return setAttribute(key, String.valueOf(value));
}
public boolean setAttribute(String key, String value) { public boolean setAttribute(String key, String value) {
synchronized (this.attributes) { synchronized (this.attributes) {
try { try {

View File

@ -511,7 +511,7 @@ public class MucOptions {
return users; return users;
} }
public String createNameFromParticipants() { String createNameFromParticipants() {
List<User> users = getUsersRelevantForNameAndAvatar(); List<User> users = getUsersRelevantForNameAndAvatar();
if (users.size() >= 2) { if (users.size() >= 2) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();

View File

@ -1310,6 +1310,12 @@ public class XmppConnectionService extends Service {
boolean saveInDb = addToConversation; boolean saveInDb = addToConversation;
message.setStatus(Message.STATUS_WAITING); message.setStatus(Message.STATUS_WAITING);
if (message.getEncryption() != Message.ENCRYPTION_NONE && conversation.getMode() == Conversation.MODE_MULTI && conversation.isPrivateAndNonAnonymous()) {
if (conversation.setAttribute(Conversation.ATTRIBUTE_FORMERLY_PRIVATE_NON_ANONYMOUS, true)) {
databaseBackend.updateConversation(conversation);
}
}
if (account.isOnlineAndConnected()) { if (account.isOnlineAndConnected()) {
switch (message.getEncryption()) { switch (message.getEncryption()) {
case Message.ENCRYPTION_NONE: case Message.ENCRYPTION_NONE:

View File

@ -356,6 +356,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.muc_details, menu); getMenuInflater().inflate(R.menu.muc_details, menu);
final MenuItem share = menu.findItem(R.id.action_share);
share.setVisible(mConversation != null && !mConversation.isPrivateAndNonAnonymous());
AccountUtils.showHideMenuItems(menu); AccountUtils.showHideMenuItems(menu);
return super.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu);
} }

View File

@ -1254,34 +1254,39 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (conversation == null) { if (conversation == null) {
return; return;
} }
final boolean updated;
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.encryption_choice_none: case R.id.encryption_choice_none:
conversation.setNextEncryption(Message.ENCRYPTION_NONE); updated = conversation.setNextEncryption(Message.ENCRYPTION_NONE);
item.setChecked(true); item.setChecked(true);
break; break;
case R.id.encryption_choice_pgp: case R.id.encryption_choice_pgp:
if (activity.hasPgp()) { if (activity.hasPgp()) {
if (conversation.getAccount().getPgpSignature() != null) { if (conversation.getAccount().getPgpSignature() != null) {
conversation.setNextEncryption(Message.ENCRYPTION_PGP); updated = conversation.setNextEncryption(Message.ENCRYPTION_PGP);
item.setChecked(true); item.setChecked(true);
} else { } else {
updated = false;
activity.announcePgp(conversation.getAccount(), conversation, null, activity.onOpenPGPKeyPublished); activity.announcePgp(conversation.getAccount(), conversation, null, activity.onOpenPGPKeyPublished);
} }
} else { } else {
activity.showInstallPgpDialog(); activity.showInstallPgpDialog();
updated = false;
} }
break; break;
case R.id.encryption_choice_axolotl: case R.id.encryption_choice_axolotl:
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(conversation.getAccount()) Log.d(Config.LOGTAG, AxolotlService.getLogprefix(conversation.getAccount())
+ "Enabled axolotl for Contact " + conversation.getContact().getJid()); + "Enabled axolotl for Contact " + conversation.getContact().getJid());
conversation.setNextEncryption(Message.ENCRYPTION_AXOLOTL); updated = conversation.setNextEncryption(Message.ENCRYPTION_AXOLOTL);
item.setChecked(true); item.setChecked(true);
break; break;
default: default:
conversation.setNextEncryption(Message.ENCRYPTION_NONE); updated = conversation.setNextEncryption(Message.ENCRYPTION_NONE);
break; break;
} }
if (updated) {
activity.xmppConnectionService.updateConversation(conversation); activity.xmppConnectionService.updateConversation(conversation);
}
updateChatMsgHint(); updateChatMsgHint();
getActivity().invalidateOptionsMenu(); getActivity().invalidateOptionsMenu();
activity.refreshUi(); activity.refreshUi();

View File

@ -479,7 +479,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
EnterJidDialog dialog = EnterJidDialog.newInstance( EnterJidDialog dialog = EnterJidDialog.newInstance(
mActivatedAccounts, mActivatedAccounts,
getString(R.string.add_contact), getString(R.string.add_contact),
getString(R.string.create), getString(R.string.add),
prefilledJid, prefilledJid,
null, null,
invite == null || !invite.hasFingerprints() invite == null || !invite.hasFingerprints()

View File

@ -83,11 +83,17 @@ public class ConversationMenuConfigurator {
final MenuItem pgp = menu.findItem(R.id.encryption_choice_pgp); final MenuItem pgp = menu.findItem(R.id.encryption_choice_pgp);
final MenuItem axolotl = menu.findItem(R.id.encryption_choice_axolotl); final MenuItem axolotl = menu.findItem(R.id.encryption_choice_axolotl);
final int next = conversation.getNextEncryption();
boolean visible; boolean visible;
if (OmemoSetting.isAlways()) { if (OmemoSetting.isAlways()) {
visible = false; visible = false;
} else if (conversation.getMode() == Conversation.MODE_MULTI) { } else if (conversation.getMode() == Conversation.MODE_MULTI) {
if (next == Message.ENCRYPTION_NONE && !conversation.isPrivateAndNonAnonymous() && !conversation.getBooleanAttribute(Conversation.ATTRIBUTE_FORMERLY_PRIVATE_NON_ANONYMOUS, false)) {
visible = false;
} else {
visible = (Config.supportOpenPgp() || Config.supportOmemo()) && Config.multipleEncryptionChoices(); visible = (Config.supportOpenPgp() || Config.supportOmemo()) && Config.multipleEncryptionChoices();
}
} else { } else {
visible = Config.multipleEncryptionChoices(); visible = Config.multipleEncryptionChoices();
} }
@ -105,10 +111,6 @@ public class ConversationMenuConfigurator {
pgp.setVisible(Config.supportOpenPgp()); pgp.setVisible(Config.supportOpenPgp());
none.setVisible(Config.supportUnencrypted() || conversation.getMode() == Conversation.MODE_MULTI); none.setVisible(Config.supportUnencrypted() || conversation.getMode() == Conversation.MODE_MULTI);
axolotl.setVisible(Config.supportOmemo()); axolotl.setVisible(Config.supportOmemo());
final AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
if (axolotlService == null || !axolotlService.isConversationAxolotlCapable(conversation)) {
axolotl.setEnabled(false);
}
switch (conversation.getNextEncryption()) { switch (conversation.getNextEncryption()) {
case Message.ENCRYPTION_NONE: case Message.ENCRYPTION_NONE:
none.setChecked(true); none.setChecked(true);

View File

@ -63,7 +63,10 @@ public final class MucDetailsContextMenuHelper {
MenuItem removeOwnerPrivileges = menu.findItem(R.id.revoke_owner_privileges); MenuItem removeOwnerPrivileges = menu.findItem(R.id.revoke_owner_privileges);
MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges); MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room); MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
MenuItem managePermisisons = menu.findItem(R.id.manage_permissions);
removeFromRoom.setTitle(isGroupChat ? R.string.remove_from_room : R.string.remove_from_channel);
MenuItem banFromConference = menu.findItem(R.id.ban_from_conference); MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
banFromConference.setTitle(isGroupChat ? R.string.ban_from_conference : R.string.ban_from_channel);
MenuItem invite = menu.findItem(R.id.invite); MenuItem invite = menu.findItem(R.id.invite);
startConversation.setVisible(true); startConversation.setVisible(true);
final Contact contact = user.getContact(); final Contact contact = user.getContact();
@ -74,8 +77,10 @@ public final class MucDetailsContextMenuHelper {
if ((activity instanceof ConferenceDetailsActivity || activity instanceof MucUsersActivity) && user.getRole() == MucOptions.Role.NONE) { if ((activity instanceof ConferenceDetailsActivity || activity instanceof MucUsersActivity) && user.getRole() == MucOptions.Role.NONE) {
invite.setVisible(true); invite.setVisible(true);
} }
if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && self.getAffiliation().outranks(user.getAffiliation())) { boolean managePermissionsVisible = false;
if ((self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && self.getAffiliation().outranks(user.getAffiliation())) || self.getAffiliation() == MucOptions.Affiliation.OWNER) {
if (advancedMode) { if (advancedMode) {
managePermissionsVisible = true;
if (!user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) { if (!user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) {
giveMembership.setVisible(true); giveMembership.setVisible(true);
} else if (user.getAffiliation() == MucOptions.Affiliation.MEMBER) { } else if (user.getAffiliation() == MucOptions.Affiliation.MEMBER) {
@ -86,12 +91,14 @@ public final class MucDetailsContextMenuHelper {
} }
} else { } else {
if (!Config.DISABLE_BAN || conversation.getMucOptions().membersOnly()) { if (!Config.DISABLE_BAN || conversation.getMucOptions().membersOnly()) {
managePermissionsVisible = true;
removeFromRoom.setVisible(true); removeFromRoom.setVisible(true);
} }
} }
} }
if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) { if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
if (isGroupChat || advancedMode || user.getAffiliation() == MucOptions.Affiliation.OWNER) { if (isGroupChat || advancedMode || user.getAffiliation() == MucOptions.Affiliation.OWNER) {
managePermissionsVisible = true;
if (!user.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) { if (!user.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
giveOwnerPrivileges.setVisible(true); giveOwnerPrivileges.setVisible(true);
} else if (user.getAffiliation() == MucOptions.Affiliation.OWNER){ } else if (user.getAffiliation() == MucOptions.Affiliation.OWNER){
@ -99,6 +106,7 @@ public final class MucDetailsContextMenuHelper {
} }
} }
if (!isGroupChat || advancedMode || user.getAffiliation() == MucOptions.Affiliation.ADMIN) { if (!isGroupChat || advancedMode || user.getAffiliation() == MucOptions.Affiliation.ADMIN) {
managePermissionsVisible = true;
if (!user.getAffiliation().ranks(MucOptions.Affiliation.ADMIN)) { if (!user.getAffiliation().ranks(MucOptions.Affiliation.ADMIN)) {
giveAdminPrivileges.setVisible(true); giveAdminPrivileges.setVisible(true);
} else if (user.getAffiliation() == MucOptions.Affiliation.ADMIN) { } else if (user.getAffiliation() == MucOptions.Affiliation.ADMIN) {
@ -106,6 +114,7 @@ public final class MucDetailsContextMenuHelper {
} }
} }
} }
managePermisisons.setVisible(managePermissionsVisible);
sendPrivateMessage.setVisible(!isGroupChat && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR)); sendPrivateMessage.setVisible(!isGroupChat && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR));
} else { } else {
sendPrivateMessage.setVisible(true); sendPrivateMessage.setVisible(true);

View File

@ -156,7 +156,6 @@
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_toStartOf="@+id/change_conference_button" android:layout_toStartOf="@+id/change_conference_button"
android:text="@string/private_conference"
android:textAppearance="@style/TextAppearance.Conversations.Body1" android:textAppearance="@style/TextAppearance.Conversations.Body1"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/change_conference_button" /> android:layout_toLeftOf="@+id/change_conference_button" />

View File

@ -16,6 +16,9 @@
android:id="@+id/send_private_message" android:id="@+id/send_private_message"
android:title="@string/send_private_message" android:title="@string/send_private_message"
android:visible="false"/> android:visible="false"/>
<item android:id="@+id/manage_permissions"
android:title="@string/manage_permission">
<menu>
<item <item
android:id="@+id/give_membership" android:id="@+id/give_membership"
android:title="@string/grant_membership" android:title="@string/grant_membership"
@ -49,3 +52,5 @@
android:title="@string/remove_from_room" android:title="@string/remove_from_room"
android:visible="false"/> android:visible="false"/>
</menu> </menu>
</item>
</menu>

View File

@ -371,13 +371,13 @@
<string name="grant_owner_privileges">Grant owner privileges</string> <string name="grant_owner_privileges">Grant owner privileges</string>
<string name="remove_owner_privileges">Revoke owner privileges</string> <string name="remove_owner_privileges">Revoke owner privileges</string>
<string name="remove_from_room">Remove from group chat</string> <string name="remove_from_room">Remove from group chat</string>
<string name="remove_from_channel">Remove from channel</string>
<string name="could_not_change_affiliation">Could not change affiliation of %s</string> <string name="could_not_change_affiliation">Could not change affiliation of %s</string>
<string name="ban_from_conference">Ban from group chat</string> <string name="ban_from_conference">Ban from group chat</string>
<string name="ban_from_channel">Ban from channel</string>
<string name="removing_from_public_conference">You are trying to remove %s from a public group chat. 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 group chat. 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 of %s</string> <string name="could_not_change_role">Could not change role of %s</string>
<string name="public_conference">Publicly accessible group chat</string>
<string name="private_conference">Private, members only group chat</string>
<string name="conference_options">Private group chat configuration</string> <string name="conference_options">Private group chat configuration</string>
<string name="channel_options">Public channel configuration</string> <string name="channel_options">Public channel configuration</string>
<string name="members_only">Private, members only</string> <string name="members_only">Private, members only</string>
@ -846,6 +846,7 @@
<string name="anyone_can_invite_others">Anyone can invite others.</string> <string name="anyone_can_invite_others">Anyone can invite others.</string>
<string name="jabber_ids_are_visible_to_admins">Jabber IDs are visible to admins.</string> <string name="jabber_ids_are_visible_to_admins">Jabber IDs are visible to admins.</string>
<string name="jabber_ids_are_visible_to_anyone">Jabber IDs are visible to anyone.</string> <string name="jabber_ids_are_visible_to_anyone">Jabber IDs are visible to anyone.</string>
<string name="no_users_hint_channel">This public channel has no participants.</string> <string name="no_users_hint_channel">This public channel has no participants. Invite your contacts or use the share button to distribute its XMPP address.</string>
<string name="no_users_hint_group_chat">This private group chat has no participants.</string> <string name="no_users_hint_group_chat">This private group chat has no participants.</string>
<string name="manage_permission">Manage permissions</string>
</resources> </resources>