Просмотр исходного кода

handle out of memory in friends view

jblanked 9 месяцев назад
Родитель
Сommit
c22423f1f6
2 измененных файлов с 19 добавлено и 5 удалено
  1. 4 1
      callback/callback.c
  2. 15 4
      friends/friends.c

+ 4 - 1
callback/callback.c

@@ -2270,13 +2270,16 @@ void callback_logged_in_profile_item_selected(void *context, uint32_t index)
         {
             return;
         }
+
         callback_loading_task(
             app->fhttp,
             friends_fetch,
             friends_parse_json,
             FlipSocialViewSubmenu,
             FlipSocialViewVariableItemList,
-            &app->view_dispatcher, true);
+            &app->view_dispatcher,
+            true);
+
         free_flipper_http();
         break;
     default:

+ 15 - 4
friends/friends.c

@@ -18,23 +18,23 @@ bool friends_fetch(FlipperHTTP *fhttp)
     // Create the directory
     Storage *storage = furi_record_open(RECORD_STORAGE);
     storage_common_mkdir(storage, STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/friends");
-    // will return true unless the devboard is not connected
+    furi_record_close(RECORD_STORAGE);
+
     char url[100];
     snprintf(
         fhttp->file_path,
         sizeof(fhttp->file_path),
-        STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/friends.json");
+        STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/friends/friends.json");
 
     fhttp->save_received_data = true;
     alloc_headers();
-    snprintf(url, sizeof(url), "https://www.jblanked.com/flipper/api/user/friends/%s/", app_instance->login_username_logged_in);
+    snprintf(url, sizeof(url), "https://www.jblanked.com/flipper/api/user/friends/%s/%d/", app_instance->login_username_logged_in, MAX_FRIENDS);
     if (!flipper_http_request(fhttp, GET, url, auth_headers, NULL))
     {
         FURI_LOG_E(TAG, "Failed to send HTTP request for friends");
         fhttp->state = ISSUE;
         return false;
     }
-    fhttp->state = RECEIVING;
     return true;
 }
 
@@ -72,6 +72,17 @@ bool friends_parse_json(FlipperHTTP *fhttp)
         FURI_LOG_E(TAG, "FlipperHTTP is NULL");
         return false;
     }
+    if (!app_instance)
+    {
+        FURI_LOG_E(TAG, "App instance is NULL");
+        return false;
+    }
+    if (!app_instance->submenu)
+    {
+        FURI_LOG_E(TAG, "Friends submenu is NULL");
+        return false;
+    }
+
     // load the received data from the saved file
     FuriString *friend_data = flipper_http_load_from_file(fhttp->file_path);
     if (friend_data == NULL)