瀏覽代碼

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 3 年之前
父節點
當前提交
5627e92619
共有 1 個文件被更改,包括 5 次插入0 次删除
  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