From 1553cdf107450b94471a661618305b6ce0935691 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Mon, 25 Mar 2024 15:11:36 +0100 Subject: [PATCH] remove 'source' variable from Participant As far i could see this is identical to actorType, so 'source' was removed and actorType is now used. This makes checks in ParticipantItem etc more clean Signed-off-by: Marcel Hibbe --- .../talk/adapters/items/ContactItem.java | 18 ++++----- .../talk/adapters/items/ParticipantItem.kt | 12 ++++-- .../talk/contacts/ContactsActivity.kt | 38 +++++++++---------- .../models/json/participants/Participant.kt | 4 +- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.java index a6f27fd92..998243f99 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.java @@ -35,10 +35,6 @@ import eu.davidea.viewholders.FlexibleViewHolder; public class ContactItem extends AbstractFlexibleItem implements ISectionable, IFilterable { - public static final String PARTICIPANT_SOURCE_CIRCLES = "circles"; - public static final String PARTICIPANT_SOURCE_GROUPS = "groups"; - public static final String PARTICIPANT_SOURCE_USERS = "users"; - private final Participant participant; private final User user; private GenericTextHeaderItem header; @@ -133,9 +129,7 @@ public class ContactItem extends AbstractFlexibleItem 0) { diff --git a/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivity.kt b/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivity.kt index 8ac2f21f4..5d6f44c4b 100644 --- a/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivity.kt @@ -574,7 +574,6 @@ class ContactsActivity : participant.actorId = autocompleteUser.id participant.actorType = actorTypeConverter.getFromString(autocompleteUser.source) participant.displayName = autocompleteUser.label - participant.source = autocompleteUser.source return participant } @@ -593,30 +592,30 @@ class ContactsActivity : (o2 as GenericTextHeaderItem).model } if (o1 is ContactItem && o2 is ContactItem) { - val firstSource: String = o1.model.source!! - val secondSource: String = o2.model.source!! + val firstSource: Participant.ActorType = o1.model.actorType!! + val secondSource: Participant.ActorType = o2.model.actorType!! if (firstSource == secondSource) { return@sort firstName.compareTo(secondName, ignoreCase = true) } // First users - if ("users" == firstSource) { + if (Participant.ActorType.USERS == firstSource) { return@sort -1 - } else if ("users" == secondSource) { + } else if (Participant.ActorType.USERS == secondSource) { return@sort 1 } // Then groups - if ("groups" == firstSource) { + if (Participant.ActorType.GROUPS == firstSource) { return@sort -1 - } else if ("groups" == secondSource) { + } else if (Participant.ActorType.GROUPS == secondSource) { return@sort 1 } // Then circles - if ("circles" == firstSource) { + if (Participant.ActorType.CIRCLES == firstSource) { return@sort -1 - } else if ("circles" == secondSource) { + } else if (Participant.ActorType.CIRCLES == secondSource) { return@sort 1 } @@ -638,13 +637,13 @@ class ContactsActivity : (o2 as GenericTextHeaderItem).model } if (o1 is ContactItem && o2 is ContactItem) { - if ("groups" == o1.model.source && - "groups" == o2.model.source + if (Participant.ActorType.GROUPS == o1.model.actorType && + Participant.ActorType.GROUPS == o2.model.actorType ) { return@sort firstName.compareTo(secondName, ignoreCase = true) - } else if ("groups" == o1.model.source) { + } else if (Participant.ActorType.GROUPS == o1.model.actorType) { return@sort -1 - } else if ("groups" == o2.model.source) { + } else if (Participant.ActorType.GROUPS == o2.model.actorType) { return@sort 1 } } @@ -775,7 +774,7 @@ class ContactsActivity : private fun createRoom(contactItem: ContactItem) { var roomType = "1" - if ("groups" == contactItem.model.source) { + if (Participant.ActorType.GROUPS == contactItem.model.actorType) { roomType = "2" } val apiVersion: Int = ApiUtils.getConversationApiVersion(currentUser!!, intArrayOf(ApiUtils.API_V4, 1)) @@ -817,19 +816,19 @@ class ContactsActivity : } private fun updateSelectionLists(participant: Participant) { - if ("groups" == participant.source) { + if (Participant.ActorType.GROUPS == participant.actorType) { if (participant.selected) { selectedGroupIds.add(participant.calculatedActorId!!) } else { selectedGroupIds.remove(participant.calculatedActorId!!) } - } else if ("emails" == participant.source) { + } else if (Participant.ActorType.EMAILS == participant.actorType) { if (participant.selected) { selectedEmails.add(participant.calculatedActorId!!) } else { selectedEmails.remove(participant.calculatedActorId!!) } - } else if ("circles" == participant.source) { + } else if (Participant.ActorType.CIRCLES == participant.actorType) { if (participant.selected) { selectedCircleIds.add(participant.calculatedActorId!!) } else { @@ -849,7 +848,8 @@ class ContactsActivity : participant: Participant, adapter: FlexibleAdapter<*>? ): Boolean { - return "groups" == contactItem.model.source && participant.selected && adapter?.selectedItemCount!! > 1 + return Participant.ActorType.GROUPS == contactItem.model.actorType && + participant.selected && adapter?.selectedItemCount!! > 1 } private fun listOpenConversations() { @@ -869,7 +869,7 @@ class ContactsActivity : for (i in 0 until adapter!!.itemCount) { if (adapter?.getItem(i) is ContactItem) { val contactItem: ContactItem = adapter?.getItem(i) as ContactItem - if ("groups" == contactItem.model.source) { + if (Participant.ActorType.GROUPS == contactItem.model.actorType) { contactItem.isEnabled = !isPublicCall } } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.kt b/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.kt index acbb16f85..11b92d61e 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.kt +++ b/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.kt @@ -72,8 +72,6 @@ data class Participant( @JsonField(name = ["statusMessage"]) var statusMessage: String? = null, - var source: String? = null, - var selected: Boolean = false ) : Parcelable { // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject' @@ -84,7 +82,7 @@ data class Participant( ) /** - * actorType is only guaranteed in APIv3+ so use calculatedActorId + * actorType is only guaranteed in APIv3+ so use calculatedActorType * * https://github.com/nextcloud/spreed/blob/stable21/lib/Controller/RoomController.php#L1145-L1148 */