sort muc users by affiliation, name. fixes #1913

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/entities/MucOptions.java | 24 +++-
1 file changed, 15 insertions(+), 9 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/entities/MucOptions.java 🔗

@@ -296,16 +296,22 @@ public class MucOptions {
 
 		@Override
 		public int compareTo(User another) {
-			Contact ourContact = getContact();
-			Contact anotherContact = another.getContact();
-			if (ourContact != null && anotherContact != null) {
-				return ourContact.compareTo(anotherContact);
-			} else if (ourContact == null && anotherContact != null) {
-				return getName().compareToIgnoreCase(anotherContact.getDisplayName());
-			} else if (ourContact != null) {
-				return ourContact.getDisplayName().compareToIgnoreCase(another.getName());
+			if (another.getAffiliation().outranks(getAffiliation())) {
+				return 1;
+			} else if (getAffiliation().outranks(another.getAffiliation())) {
+				return -1;
 			} else {
-				return getName().compareToIgnoreCase(another.getName());
+				Contact ourContact = getContact();
+				Contact anotherContact = another.getContact();
+				if (ourContact != null && anotherContact != null) {
+					return ourContact.compareTo(anotherContact);
+				} else if (ourContact == null && anotherContact != null) {
+					return getName().compareToIgnoreCase(anotherContact.getDisplayName());
+				} else if (ourContact != null) {
+					return ourContact.getDisplayName().compareToIgnoreCase(another.getName());
+				} else {
+					return getName().compareToIgnoreCase(another.getName());
+				}
 			}
 		}