Browse Source

Display the pin if the participant has one

Signed-off-by: Joas Schilling <coding@schilljs.com>
Joas Schilling 4 years ago
parent
commit
32bb98e43e

+ 50 - 15
app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt

@@ -89,13 +89,11 @@ import io.reactivex.schedulers.Schedulers
 import org.greenrobot.eventbus.EventBus
 import org.greenrobot.eventbus.Subscribe
 import org.greenrobot.eventbus.ThreadMode
-import retrofit2.adapter.rxjava2.HttpException
 import java.util.Calendar
 import java.util.Collections
 import java.util.Comparator
 import java.util.Locale
 import javax.inject.Inject
-import kotlin.reflect.typeOf
 
 @AutoInjector(NextcloudTalkApplication::class)
 class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleAdapter.OnItemClickListener {
@@ -922,9 +920,30 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
 
         val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
 
-        if (participant.getUserId() == conversationUser!!.userId
-            || participant.type == Participant.ParticipantType.OWNER) {
-            // FIXME Show pin?
+        if (participant.getUserId() == conversationUser!!.userId) {
+            if (participant.attendeePin.isNotEmpty()) {
+                val items = mutableListOf(
+                    BasicListItemWithImage(
+                        R.drawable.ic_lock_grey600_24px,
+                        context.getString(R.string.nc_attendee_pin, participant.attendeePin)
+                    )
+                )
+                MaterialDialog(activity!!, BottomSheet(WRAP_CONTENT)).show {
+                    cornerRadius(res = R.dimen.corner_radius)
+
+                    title(text = participant.displayName)
+                    listItemsWithImage(items = items) { dialog, index, _ ->
+                        if (index == 0) {
+                            removeAttendeeFromConversation(apiVersion, participant)
+                        }
+                    }
+                }
+            }
+            return true
+        }
+
+        if (participant.type == Participant.ParticipantType.OWNER) {
+            // Can not moderate owner
             return true
         }
 
@@ -949,6 +968,10 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
         }
 
         var items = mutableListOf(
+            BasicListItemWithImage(
+                R.drawable.ic_lock_grey600_24px,
+                context.getString(R.string.nc_attendee_pin, participant.attendeePin)
+            ),
             BasicListItemWithImage(R.drawable.ic_pencil_grey600_24dp, context.getString(R.string.nc_promote)),
             BasicListItemWithImage(R.drawable.ic_pencil_grey600_24dp, context.getString(R.string.nc_demote)),
             BasicListItemWithImage(
@@ -959,13 +982,17 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
 
         if (participant.type == Participant.ParticipantType.MODERATOR
             || participant.type == Participant.ParticipantType.GUEST_MODERATOR) {
-            items.removeAt(0)
+            items.removeAt(1)
         } else if (participant.type == Participant.ParticipantType.USER
             || participant.type == Participant.ParticipantType.GUEST) {
-            items.removeAt(1)
+            items.removeAt(2)
         } else {
             // Self joined users can not be promoted nor demoted
-            items.removeAt(0)
+            items.removeAt(2)
+            items.removeAt(1)
+        }
+
+        if (participant.attendeePin.isEmpty()) {
             items.removeAt(0)
         }
 
@@ -975,13 +1002,21 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
 
                 title(text = participant.displayName)
                 listItemsWithImage(items = items) { dialog, index, _ ->
-                    if (index == 0) {
-                        if (participant.type == Participant.ParticipantType.USER_FOLLOWING_LINK) {
-                            removeAttendeeFromConversation(apiVersion, participant)
-                        } else {
-                            toggleModeratorStatus(apiVersion, participant)
-                        }
-                    } else if (index == 1) {
+                    var actionToTrigger = index
+                    if (participant.attendeePin.isEmpty()) {
+                        actionToTrigger++
+                    }
+                    if (participant.type == Participant.ParticipantType.USER_FOLLOWING_LINK) {
+                        actionToTrigger++
+                    }
+
+                    if (actionToTrigger == 0) {
+                        // Pin, nothing to do
+                    } else if (actionToTrigger == 1) {
+                        // Promote/demote
+                        toggleModeratorStatus(apiVersion, participant)
+                    } else if (actionToTrigger == 2) {
+                        // Remove from conversation
                         removeAttendeeFromConversation(apiVersion, participant)
                     }
                 }

+ 17 - 2
app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java

@@ -44,6 +44,9 @@ public class Participant {
     @JsonField(name = "actorId")
     public String actorId;
 
+    @JsonField(name = "attendeePin")
+    public String attendeePin;
+
     @Deprecated
     @JsonField(name = "userId")
     public String userId;
@@ -115,6 +118,9 @@ public class Participant {
         return actorId;
     }
 
+    public String getAttendeePin() {
+        return attendeePin;
+    }
 
     @Deprecated
     public String getUserId() {
@@ -184,6 +190,10 @@ public class Participant {
         this.actorId = actorId;
     }
 
+    public void setAttendeePin(String attendeePin) {
+        this.attendeePin = attendeePin;
+    }
+
     public void setType(ParticipantType type) {
         this.type = type;
     }
@@ -256,6 +266,9 @@ public class Participant {
         if (!actorId.equals(that.actorId)) {
             return false;
         }
+        if (!attendeePin.equals(that.attendeePin)) {
+            return false;
+        }
         if (!userId.equals(that.userId)) {
             return false;
         }
@@ -288,8 +301,9 @@ public class Participant {
     @Override
     public int hashCode() {
         int result = attendeeId.hashCode();
-        result = 31 * result + actorType.hashCode();
-        result = 31 * result + actorId.hashCode();
+        result = 31 * result + (actorType != null ? actorType.hashCode() : 0);
+        result = 31 * result + (actorId != null ? actorId.hashCode() : 0);
+        result = 31 * result + (attendeePin != null ? attendeePin.hashCode() : 0);
         result = 31 * result + (userId != null ? userId.hashCode() : 0);
         result = 31 * result + (type != null ? type.hashCode() : 0);
         result = 31 * result + (name != null ? name.hashCode() : 0);
@@ -310,6 +324,7 @@ public class Participant {
                 "attendeeId=" + attendeeId +
                 ", actorType='" + actorType + '\'' +
                 ", actorId='" + actorId + '\'' +
+                ", attendeePin='" + attendeePin + '\'' +
                 ", userId='" + userId + '\'' +
                 ", type=" + type +
                 ", name='" + name + '\'' +

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -256,6 +256,7 @@
     <string name="nc_promote">Promote to moderator</string>
     <string name="nc_remove_participant">Remove participant</string>
     <string name="nc_remove_group_and_members">Remove group and members</string>
+    <string name="nc_attendee_pin">Pin: %1$s</string>
 
     <!-- Chat -->
     <string name="nc_hint_enter_a_message">Enter a message…</string>