Explorar o código

Make Server's hashCode stable vs. version changes

Bug #9906 seems to be triggered by a version change of the nextcloud server the client is connected to. It appears the most logical solution to make nextcloud object IDs stable against server version changes. These object IDs are derived from the User object using account/anonymous, and the referenced Server object. Providing a hashCode function in Server that ignores the server's version therefore provides stability of object IDs. This seems safe to do, as an URI is already designed to be an identificator.
pelzvieh %!s(int64=3) %!d(string=hai) anos
pai
achega
5627e92619
Modificáronse 1 ficheiros con 5 adicións e 0 borrados
  1. 5 0
      app/src/main/java/com/nextcloud/client/account/Server.kt

+ 5 - 0
app/src/main/java/com/nextcloud/client/account/Server.kt

@@ -24,6 +24,7 @@ import android.os.Parcel
 import android.os.Parcelable
 import com.owncloud.android.lib.resources.status.OwnCloudVersion
 import java.net.URI
+import java.util.Objects
 
 /**
  * This object provides all information necessary to interact
@@ -42,6 +43,10 @@ data class Server(val uri: URI, val version: OwnCloudVersion) : Parcelable {
         writeSerializable(uri)
         writeParcelable(version, 0)
     }
+    
+    override fun hashCode() = 
+        // a server is identified by its uri, the version is an attribute of this one server
+        Objects.hash(uri)
 
     companion object {
         @JvmField