Browse Source

Fixed a freeze that occurred when sending a DM

I also did some renaming and updated the README/CHANGELOG accordingly
jblanked 1 year ago
parent
commit
fa0499dbf8
11 changed files with 69 additions and 105 deletions
  1. 5 37
      README.md
  2. 2 2
      application.fam
  3. 3 0
      assets/CHANGELOG.md
  4. 5 37
      assets/README.md
  5. 37 15
      callback/flip_social_callback.c
  6. 1 1
      flip_social.h
  7. 1 1
      jsmn/jsmn.c
  8. 1 7
      jsmn/jsmn.h
  9. 1 4
      jsmn/jsmn_furi.c
  10. 1 1
      jsmn/jsmn_furi.h
  11. 12 0
      jsmn/jsmn_h.h

+ 5 - 37
README.md

@@ -7,16 +7,16 @@ The highlight of this app is customizable pre-saves, which, as explained below,
 - WiFi Developer Board, Raspberry Pi, or ESP32 Device with FlipperHTTP Flash: https://github.com/jblanked/FlipperHTTP
 - 2.4 Ghz WiFi Access Point
 
-
 ## Features
 - Login/Logout
 - Registration
 - Feed
 - Profile
 - Customizable Pre-Saves
-- Explore (NEW)
-- Friends (NEW)
-- Direct Messaging (NEW)
+- Explore 
+- Friends 
+- Direct Messaging 
+
 
 **Login/Logout:** Log in to your account to view and post on the Feed. You can also change your password and log out when needed.
 
@@ -30,36 +30,4 @@ The highlight of this app is customizable pre-saves, which, as explained below,
 
 **Friends:** View and remove friends.
 
-**Direct Messaging:** Send direct messages to other Flipper users and view your conversations.
-
-## Roadmap
-**v0.2**
-- Stability Patch
-
-**v0.3**
-- Explore Page
-- Friends
-
-**v0.4**
-- Direct Messaging
-
-**v0.5**
-- Improve memory allocation
-- Improve Feed Page
-- Raspberry Pi Pico W Support
-
-**v0.6**
-- Improve memory allocation
-- Update the Direct Messaging View
-- Update the Pre-Save View
-
-**v0.7**
-- Improve memory allocation
-- Loading screens.
-
-**v0.8**
-- Improve User Profile
-- Improve Explore Page
-
-**v1.0**
-- Official Release
+**Direct Messaging:** Send direct messages to other Flipper users and view your conversations.

+ 2 - 2
application.fam

@@ -7,8 +7,8 @@ App(
     fap_icon="app_new.png",
     fap_category="GPIO",
     fap_icon_assets="assets",
-    fap_author="jblanked",
+    fap_author="JBlanked",
     fap_weburl="https://github.com/jblanked/FlipSocial",
-    fap_version="1.0",
+    fap_version="1.0.1",
     fap_description="Social media platform for the Flipper Zero.",
 )

+ 3 - 0
assets/CHANGELOG.md

@@ -1,3 +1,6 @@
+## 1.0.1  
+- Fixed a freeze that occurred when sending a direct message.
+
 ## 1.0 - Official Release
 - Final memory improvements.
 - Updated the New Message option in the Messages view to allow users to search for recipients to send messages to.

+ 5 - 37
assets/README.md

@@ -7,16 +7,16 @@ The highlight of this app is customizable pre-saves, which, as explained below,
 - WiFi Developer Board, Raspberry Pi, or ESP32 Device with FlipperHTTP Flash: https://github.com/jblanked/FlipperHTTP
 - 2.4 Ghz WiFi Access Point
 
-
 ## Features
 - Login/Logout
 - Registration
 - Feed
 - Profile
 - Customizable Pre-Saves
-- Explore (NEW)
-- Friends (NEW)
-- Direct Messaging (NEW)
+- Explore 
+- Friends 
+- Direct Messaging 
+
 
 **Login/Logout:** Log in to your account to view and post on the Feed. You can also change your password and log out when needed.
 
@@ -30,36 +30,4 @@ The highlight of this app is customizable pre-saves, which, as explained below,
 
 **Friends:** View and remove friends.
 
-**Direct Messaging:** Send direct messages to other Flipper users and view your conversations.
-
-## Roadmap
-**v0.2**
-- Stability Patch
-
-**v0.3**
-- Explore Page
-- Friends
-
-**v0.4**
-- Direct Messaging
-
-**v0.5**
-- Improve memory allocation
-- Improve Feed Page
-- Raspberry Pi Pico W Support
-
-**v0.6**
-- Improve memory allocation
-- Update the Direct Messaging View
-- Update the Pre-Save View
-
-**v0.7**
-- Improve memory allocation
-- Loading screens.
-
-**v0.8**
-- Improve User Profile
-- Improve Explore Page
-
-**v1.0**
-- Official Release
+**Direct Messaging:** Send direct messages to other Flipper users and view your conversations.

+ 37 - 15
callback/flip_social_callback.c

@@ -2024,25 +2024,47 @@ void flip_social_logged_in_messages_new_message_updated(void *context)
     // Ensure null-termination
     app->messages_new_message_logged_in[app->messages_new_message_logged_in_temp_buffer_size - 1] = '\0';
 
-    // send post request to send message
-    if (!flipper_http_init(flipper_http_rx_callback, app))
+    bool send_message_to_user()
     {
-        FURI_LOG_E(TAG, "Failed to initialize HTTP");
-        return;
+        // send post request to send message
+        if (!flipper_http_init(flipper_http_rx_callback, app))
+        {
+            FURI_LOG_E(TAG, "Failed to initialize HTTP");
+            return false;
+        }
+        auth_headers_alloc();
+        char url[128];
+        char payload[256];
+        snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
+        snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_message_users->usernames[flip_social_message_users->index], app->messages_new_message_logged_in);
+        if (!flipper_http_post_request_with_headers(url, auth_headers, payload))
+        {
+            FURI_LOG_E(TAG, "Failed to send post request to send message");
+            FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
+            easy_flipper_dialog("Error", "Failed to send message\n\n\nPress BACK to return :D");
+            flipper_http_deinit();
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
+            return false;
+        }
+        fhttp.state = RECEIVING;
+        return true;
     }
-    auth_headers_alloc();
-    char url[128];
-    char payload[256];
-    snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
-    snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_message_users->usernames[flip_social_message_users->index], app->messages_new_message_logged_in);
-    if (!flipper_http_post_request_with_headers(url, auth_headers, payload))
+    bool parse_message_to_user()
     {
-        FURI_LOG_E(TAG, "Failed to send post request to send message");
-        FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
+        while (fhttp.state != IDLE)
+        {
+            furi_delay_ms(10);
+        }
+        flipper_http_deinit();
+        return true;
     }
-    furi_delay_ms(1000);
-    flipper_http_deinit();
-    view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
+    // well, we got a freeze here, so let's use the loading task to switch views and force refresh
+    flipper_http_loading_task(
+        send_message_to_user,
+        parse_message_to_user,
+        FlipSocialViewSubmenu,
+        FlipSocialViewLoggedInMessagesNewMessageInput,
+        &app->view_dispatcher);
 }
 
 void flip_social_logged_in_explore_updated(void *context)

+ 1 - 1
flip_social.h

@@ -10,7 +10,7 @@
 #include <font/font.h>
 
 #define TAG "FlipSocial"
-#define VERSION_TAG TAG " v1.0"
+#define VERSION_TAG TAG " v1.0.1"
 
 #define MAX_PRE_SAVED_MESSAGES 20 // Maximum number of pre-saved messages
 #define MAX_MESSAGE_LENGTH 100    // Maximum length of a message in the feed

+ 1 - 1
jsmn/jsmn.c

@@ -422,7 +422,7 @@ int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
 }
 
 // Helper function to create a JSON object
-char *jsmn(const char *key, const char *value)
+char *get_json(const char *key, const char *value)
 {
     int length = strlen(key) + strlen(value) + 8;         // Calculate required length
     char *result = (char *)malloc(length * sizeof(char)); // Allocate memory

+ 1 - 7
jsmn/jsmn.h

@@ -56,14 +56,8 @@ extern "C"
 #define JB_JSMN_EDIT
 /* Added in by JBlanked on 2024-10-16 for use in Flipper Zero SDK*/
 
-#include <string.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <furi.h>
-
 // Helper function to create a JSON object
-char *jsmn(const char *key, const char *value);
+char *get_json(const char *key, const char *value);
 // Helper function to compare JSON keys
 int jsoneq(const char *json, jsmntok_t *tok, const char *s);
 

+ 1 - 4
jsmn/jsmn_furi.c

@@ -400,11 +400,8 @@ int jsmn_parse_furi(jsmn_parser *parser, const FuriString *js,
     return count;
 }
 
-// The rest of your code (e.g., get_json_value_furi, get_json_array_value_furi, etc.)
-// remains unchanged and can still rely on these updated parsing functions.
-
 // Helper function to create a JSON object: {"key":"value"}
-FuriString *jsmn_create_object(const FuriString *key, const FuriString *value)
+FuriString *get_json_furi(const FuriString *key, const FuriString *value)
 {
     FuriString *result = furi_string_alloc();
     furi_string_printf(result, "{\"%s\":\"%s\"}",

+ 1 - 1
jsmn/jsmn_furi.h

@@ -47,7 +47,7 @@ extern "C"
 #define JB_JSMN_FURI_EDIT
 
 // Helper function to create a JSON object
-FuriString *jsmn_create_object(const FuriString *key, const FuriString *value);
+FuriString *get_json_furi(const FuriString *key, const FuriString *value);
 
 // Updated signatures to accept const char* key
 FuriString *get_json_value_furi(const char *key, const FuriString *json_data);

+ 12 - 0
jsmn/jsmn_h.h

@@ -38,4 +38,16 @@ typedef struct
     int toksuper;         /* superior token node, e.g. parent object or array */
 } jsmn_parser;
 
+typedef struct
+{
+    char *key;
+    char *value;
+} JSON;
+
+typedef struct
+{
+    FuriString *key;
+    FuriString *value;
+} FuriJSON;
+
 FuriString *char_to_furi_string(const char *str);