Эх сурвалжийг харах

Remove participants usage outside the conversation usage

Signed-off-by: Joas Schilling <coding@schilljs.com>
Joas Schilling 4 жил өмнө
parent
commit
f32c0867e5

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

@@ -362,7 +362,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
                 )
                 .setPositiveButtonColor(context!!.resources.getColor(R.color.nc_darkRed))
                 .setTitle(R.string.nc_delete_call)
-                .setMessage(conversation!!.deleteWarningMessage)
+                .setMessage(R.string.nc_delete_conversation_more)
                 .setPositiveButton(R.string.nc_delete) { deleteConversation() }
                 .setNegativeButton(R.string.nc_cancel, null)
                 .setInstanceStateHandler(ID_DELETE_CONVERSATION_DIALOG, saveStateHandler!!)

+ 1 - 1
app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java

@@ -802,7 +802,7 @@ public class ConversationsListController extends BaseController implements Searc
                                                                 R.drawable.ic_delete_black_24dp, R.color.bg_default))
                         .setPositiveButtonColor(context.getResources().getColor(R.color.nc_darkRed))
                         .setTitle(R.string.nc_delete_call)
-                        .setMessage(conversation.getDeleteWarningMessage())
+                        .setMessage(R.string.nc_delete_conversation_more)
                         .setPositiveButton(R.string.nc_delete, new View.OnClickListener() {
                             @Override
                             public void onClick(View v) {

+ 13 - 25
app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.java

@@ -20,12 +20,8 @@
  */
 package com.nextcloud.talk.models.json.conversations;
 
-import android.content.res.Resources;
-
 import com.bluelinelabs.logansquare.annotation.JsonField;
 import com.bluelinelabs.logansquare.annotation.JsonObject;
-import com.nextcloud.talk.R;
-import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.models.database.UserEntity;
 import com.nextcloud.talk.models.json.chat.ChatMessage;
 import com.nextcloud.talk.models.json.converters.EnumLobbyStateConverter;
@@ -88,6 +84,8 @@ public class Conversation {
     public int lastReadMessage;
     @JsonField(name = "callFlag")
     public int callFlag;
+    @JsonField(name = "canLeaveConversation")
+    public Boolean canLeaveConversation;
 
     public boolean isPublic() {
         return (ConversationType.ROOM_PUBLIC_CALL.equals(type));
@@ -126,20 +124,13 @@ public class Conversation {
     }
 
     public boolean canLeave(UserEntity conversationUser) {
-        return !canModerate(conversationUser) ||
-                (getType() != ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL && getParticipants().size() > 1);
-    }
-
-    public String getDeleteWarningMessage() {
-        Resources resources = NextcloudTalkApplication.Companion.getSharedApplication().getResources();
-        if (getType() == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) {
-            return String.format(resources.getString(R.string.nc_delete_conversation_one2one),
-                    getDisplayName());
-        } else if (getParticipants().size() > 1) {
-            return resources.getString(R.string.nc_delete_conversation_more);
+        if (canLeaveConversation != null) {
+            // Available since APIv2
+            return canLeaveConversation;
         }
-
-        return resources.getString(R.string.nc_delete_conversation_default);
+        // Fallback for APIv1
+        return !canModerate(conversationUser) ||
+                (getType() != ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL && this.participants.size() > 1);
     }
 
     public String getRoomId() {
@@ -166,10 +157,6 @@ public class Conversation {
         return this.lastPing;
     }
 
-    public HashMap<String, HashMap<String, Object>> getParticipants() {
-        return this.participants;
-    }
-
     public Participant.ParticipantType getParticipantType() {
         return this.participantType;
     }
@@ -258,6 +245,7 @@ public class Conversation {
         this.lastPing = lastPing;
     }
 
+    @Deprecated
     public void setParticipants(HashMap<String, HashMap<String, Object>> participants) {
         this.participants = participants;
     }
@@ -365,8 +353,8 @@ public class Conversation {
         if (this.getLastPing() != other.getLastPing()) {
             return false;
         }
-        final Object this$participants = this.getParticipants();
-        final Object other$participants = other.getParticipants();
+        final Object this$participants = this.participants;
+        final Object other$participants = other.participants;
         if (this$participants == null ? other$participants != null : !this$participants.equals(other$participants)) {
             return false;
         }
@@ -456,7 +444,7 @@ public class Conversation {
         result = result * PRIME + ($type == null ? 43 : $type.hashCode());
         final long $lastPing = this.getLastPing();
         result = result * PRIME + (int) ($lastPing >>> 32 ^ $lastPing);
-        final Object $participants = this.getParticipants();
+        final Object $participants = this.participants;
         result = result * PRIME + ($participants == null ? 43 : $participants.hashCode());
         final Object $participantType = this.getParticipantType();
         result = result * PRIME + ($participantType == null ? 43 : $participantType.hashCode());
@@ -488,7 +476,7 @@ public class Conversation {
     }
 
     public String toString() {
-        return "Conversation(roomId=" + this.getRoomId() + ", token=" + this.getToken() + ", name=" + this.getName() + ", displayName=" + this.getDisplayName() + ", type=" + this.getType() + ", lastPing=" + this.getLastPing() + ", participants=" + this.getParticipants() + ", participantType=" + this.getParticipantType() + ", hasPassword=" + this.isHasPassword() + ", sessionId=" + this.getSessionId() + ", password=" + this.getPassword() + ", isFavorite=" + this.isFavorite() + ", lastActivity=" + this.getLastActivity() + ", unreadMessages=" + this.getUnreadMessages() + ", unreadMention=" + this.isUnreadMention() + ", lastMessage=" + this.getLastMessage() + ", objectType=" + this.getObjectType() + ", notificationLevel=" + this.getNotificationLevel() + ", conversationReadOnlyState=" + this.getConversationReadOnlyState() + ", lobbyState=" + this.getLobbyState() + ", lobbyTimer=" + this.getLobbyTimer() + ", lastReadMessage=" + this.getLastReadMessage() + ", callFlag=" + this.getCallFlag() + ")";
+        return "Conversation(roomId=" + this.getRoomId() + ", token=" + this.getToken() + ", name=" + this.getName() + ", displayName=" + this.getDisplayName() + ", type=" + this.getType() + ", lastPing=" + this.getLastPing() + ", participants=" + this.participants + ", participantType=" + this.getParticipantType() + ", hasPassword=" + this.isHasPassword() + ", sessionId=" + this.getSessionId() + ", password=" + this.getPassword() + ", isFavorite=" + this.isFavorite() + ", lastActivity=" + this.getLastActivity() + ", unreadMessages=" + this.getUnreadMessages() + ", unreadMention=" + this.isUnreadMention() + ", lastMessage=" + this.getLastMessage() + ", objectType=" + this.getObjectType() + ", notificationLevel=" + this.getNotificationLevel() + ", conversationReadOnlyState=" + this.getConversationReadOnlyState() + ", lobbyState=" + this.getLobbyState() + ", lobbyTimer=" + this.getLobbyTimer() + ", lastReadMessage=" + this.getLastReadMessage() + ", callFlag=" + this.getCallFlag() + ")";
     }
 
     public enum NotificationLevel {