Explorar o código

Merge pull request #2103 from nextcloud/bugfix/2101/fixNPE-AccountRemovalWorker

Add GenericOCS
Marcel Hibbe %!s(int64=3) %!d(string=hai) anos
pai
achega
fd9a70c891

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

@@ -988,7 +988,7 @@ class SettingsController : NewBaseController(R.layout.controller_settings) {
                 }
 
                 override fun onNext(genericOverall: GenericOverall) {
-                    val statusCode = genericOverall.meta?.statusCode
+                    val statusCode = genericOverall.ocs?.meta?.statusCode
                     if (statusCode == HTTP_CODE) {
                         dialog.dismiss()
                         Toast.makeText(

+ 6 - 3
app/src/main/java/com/nextcloud/talk/jobs/AccountRemovalWorker.java

@@ -35,6 +35,7 @@ import com.nextcloud.talk.R;
 import com.nextcloud.talk.api.NcApi;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.models.database.UserEntity;
+import com.nextcloud.talk.models.json.generic.GenericMeta;
 import com.nextcloud.talk.models.json.generic.GenericOverall;
 import com.nextcloud.talk.models.json.push.PushConfigurationState;
 import com.nextcloud.talk.utils.ApiUtils;
@@ -110,14 +111,16 @@ public class AccountRemovalWorker extends Worker {
 
                                 @Override
                                 public void onNext(@NotNull GenericOverall genericOverall) {
-                                    if (Objects.requireNonNull(genericOverall.getMeta()).getStatusCode() == 200 ||
-                                        genericOverall.getMeta().getStatusCode() == 202) {
+                                    GenericMeta meta = Objects.requireNonNull(genericOverall.getOcs()).getMeta();
+                                    int statusCode = Objects.requireNonNull(meta).getStatusCode();
+
+                                    if (statusCode == 200 || statusCode == 202) {
                                         HashMap<String, String> queryMap = new HashMap<>();
                                         queryMap.put("deviceIdentifier",
                                                      finalPushConfigurationState.getDeviceIdentifier());
                                         queryMap.put("userPublicKey", finalPushConfigurationState.getUserPublicKey());
                                         queryMap.put("deviceIdentifierSignature",
-                                                finalPushConfigurationState.getDeviceIdentifierSignature());
+                                                     finalPushConfigurationState.getDeviceIdentifierSignature());
                                         unregisterDeviceForNotificationWithProxy(queryMap, userEntity);
                                     }
                                 }

+ 37 - 0
app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOCS.kt

@@ -0,0 +1,37 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * @author Andy Scherzinger
+ * Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
+ * Copyright (C) 2017 Mario Danic (mario@lovelyhq.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.nextcloud.talk.models.json.generic
+
+import android.os.Parcelable
+import com.bluelinelabs.logansquare.annotation.JsonField
+import com.bluelinelabs.logansquare.annotation.JsonObject
+import kotlinx.android.parcel.Parcelize
+
+@Parcelize
+@JsonObject
+data class GenericOCS(
+    @JsonField(name = ["meta"])
+    var meta: GenericMeta? = null
+) : Parcelable {
+    // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
+    constructor() : this(null)
+}

+ 2 - 2
app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOverall.kt

@@ -29,8 +29,8 @@ import kotlinx.android.parcel.Parcelize
 @Parcelize
 @JsonObject
 data class GenericOverall(
-    @JsonField(name = ["meta"])
-    var meta: GenericMeta? = null
+    @JsonField(name = ["ocs"])
+    var ocs: GenericOCS? = null
 ) : Parcelable {
     // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
     constructor() : this(null)

+ 1 - 1
app/src/main/java/com/nextcloud/talk/ui/dialog/MessageActionsDialog.kt

@@ -321,7 +321,7 @@ class MessageActionsDialog(
                 }
 
                 override fun onNext(@NonNull genericOverall: GenericOverall) {
-                    val statusCode = genericOverall.meta?.statusCode
+                    val statusCode = genericOverall.ocs?.meta?.statusCode
                     if (statusCode == HTTP_CREATED) {
                         chatController.updateAdapterAfterSendReaction(message, emoji)
                     }