jblanked 1 年間 前
コミット
a9ab799852
3 ファイル変更110 行追加16 行削除
  1. 99 5
      callback/flip_social_callback.c
  2. 1 1
      explore/flip_social_explore.c
  3. 10 10
      feed/flip_social_feed.c

+ 99 - 5
callback/flip_social_callback.c

@@ -758,7 +758,7 @@ static void feed_dialog_callback(DialogExResult result, void *context)
             flip_feed_info->index--;
             flip_feed_info->index--;
         }
         }
         // switch view, free dialog, re-alloc dialog, switch back to dialog
         // switch view, free dialog, re-alloc dialog, switch back to dialog
-        view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSubmenu);
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettings);
         // load feed item
         // load feed item
         if (!flip_social_load_feed_post(flip_feed_info->ids[flip_feed_info->index]))
         if (!flip_social_load_feed_post(flip_feed_info->ids[flip_feed_info->index]))
         {
         {
@@ -784,7 +784,7 @@ static void feed_dialog_callback(DialogExResult result, void *context)
             flip_feed_info->index++;
             flip_feed_info->index++;
         }
         }
         // switch view, free dialog, re-alloc dialog, switch back to dialog
         // switch view, free dialog, re-alloc dialog, switch back to dialog
-        view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSubmenu);
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettings);
         // load feed item
         // load feed item
         if (!flip_social_load_feed_post(flip_feed_info->ids[flip_feed_info->index]))
         if (!flip_social_load_feed_post(flip_feed_info->ids[flip_feed_info->index]))
         {
         {
@@ -840,7 +840,7 @@ static void feed_dialog_callback(DialogExResult result, void *context)
             }
             }
         }
         }
         // switch view, free dialog, re-alloc dialog, switch back to dialog
         // switch view, free dialog, re-alloc dialog, switch back to dialog
-        view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSubmenu);
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettings);
         if (feed_dialog_alloc())
         if (feed_dialog_alloc())
         {
         {
             view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewFeedDialog);
             view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewFeedDialog);
@@ -853,6 +853,90 @@ static void feed_dialog_callback(DialogExResult result, void *context)
         }
         }
     }
     }
 }
 }
+
+static char *updated_user_message(const char *user_message)
+{
+    if (user_message == NULL)
+    {
+        FURI_LOG_E(TAG, "User message is NULL.");
+        return NULL;
+    }
+
+    size_t msg_length = strlen(user_message);
+    size_t start = 0;
+    int line_num = 0;
+
+    // Allocate memory for the updated message
+    char *updated_message = malloc(MAX_MESSAGE_LENGTH + 10);
+    if (updated_message == NULL)
+    {
+        FURI_LOG_E(TAG, "Failed to allocate memory for updated_message.");
+        return NULL;
+    }
+    size_t current_pos = 0;    // Tracks the current position in updated_message
+    updated_message[0] = '\0'; // Initialize as empty string
+
+    while (start < msg_length && line_num < 4)
+    {
+        size_t remaining = msg_length - start;
+        size_t len = (remaining > MAX_LINE_LENGTH) ? MAX_LINE_LENGTH : remaining;
+
+        // Adjust length to the last space if the line exceeds MAX_LINE_LENGTH
+        if (remaining > MAX_LINE_LENGTH)
+        {
+            size_t last_space = len;
+            while (last_space > 0 && user_message[start + last_space - 1] != ' ')
+            {
+                last_space--;
+            }
+
+            if (last_space > 0)
+            {
+                len = last_space; // Adjust len to the position of the last space
+            }
+        }
+
+        // Check if the new line fits in the updated_message buffer
+        if (current_pos + len + 1 >= (MAX_MESSAGE_LENGTH + 10))
+        {
+            FURI_LOG_E(TAG, "Updated message exceeds maximum length.");
+            // break and return what we have so far
+            break;
+        }
+
+        // Copy the line and append a newline character
+        memcpy(updated_message + current_pos, user_message + start, len);
+        current_pos += len;
+        updated_message[current_pos++] = '\n'; // Append newline
+
+        // Update the start position for the next line
+        start += len;
+
+        // Skip any spaces to avoid leading spaces on the next line
+        while (start < msg_length && user_message[start] == ' ')
+        {
+            start++;
+        }
+
+        // Increment the line number
+        line_num++;
+    }
+
+    // Null-terminate the final string
+    if (current_pos < (MAX_MESSAGE_LENGTH + 10))
+    {
+        updated_message[current_pos] = '\0';
+    }
+    else
+    {
+        FURI_LOG_E(TAG, "Buffer overflow while null-terminating.");
+        free(updated_message);
+        return NULL;
+    }
+
+    return updated_message;
+}
+
 bool feed_dialog_alloc()
 bool feed_dialog_alloc()
 {
 {
     if (!flip_feed_item)
     if (!flip_feed_item)
@@ -863,13 +947,21 @@ bool feed_dialog_alloc()
     flip_social_free_feed_dialog();
     flip_social_free_feed_dialog();
     if (!app_instance->dialog_feed)
     if (!app_instance->dialog_feed)
     {
     {
+        char updated_message[MAX_MESSAGE_LENGTH + 10];
+        snprintf(updated_message, MAX_MESSAGE_LENGTH + 10, "%s (%u %s)", flip_feed_item->message, flip_feed_item->flips, flip_feed_item->flips == 1 ? "flip" : "flips");
+        char *real_message = updated_user_message(updated_message);
+        if (!real_message)
+        {
+            FURI_LOG_E(TAG, "Failed to update the user message");
+            return false;
+        }
         if (!easy_flipper_set_dialog_ex(
         if (!easy_flipper_set_dialog_ex(
                 &app_instance->dialog_feed,
                 &app_instance->dialog_feed,
                 FlipSocialViewFeedDialog,
                 FlipSocialViewFeedDialog,
                 flip_feed_item->username,
                 flip_feed_item->username,
                 0,
                 0,
                 0,
                 0,
-                flip_feed_item->message,
+                updated_message,
                 0,
                 0,
                 10,
                 10,
                 flip_feed_info->index != 0 ? "Prev" : NULL,
                 flip_feed_info->index != 0 ? "Prev" : NULL,
@@ -880,8 +972,10 @@ bool feed_dialog_alloc()
                 &app_instance->view_dispatcher,
                 &app_instance->view_dispatcher,
                 app_instance))
                 app_instance))
         {
         {
+            free(real_message);
             return false;
             return false;
         }
         }
+        free(real_message);
         return true;
         return true;
     }
     }
     return false;
     return false;
@@ -1071,7 +1165,7 @@ void flip_social_callback_submenu_choices(void *context, uint32_t index)
                 if (!easy_flipper_set_dialog_ex(
                 if (!easy_flipper_set_dialog_ex(
                         &app->dialog_friends,
                         &app->dialog_friends,
                         FlipSocialViewFriendsDialog,
                         FlipSocialViewFriendsDialog,
-                        "User Options",
+                        "Friend Options",
                         0,
                         0,
                         0,
                         0,
                         flip_social_friends->usernames[flip_social_friends->index],
                         flip_social_friends->usernames[flip_social_friends->index],

+ 1 - 1
explore/flip_social_explore.c

@@ -120,7 +120,7 @@ bool flip_social_parse_json_explore()
     // Parse the JSON array of usernames
     // Parse the JSON array of usernames
     for (size_t i = 0; i < MAX_EXPLORE_USERS; i++)
     for (size_t i = 0; i < MAX_EXPLORE_USERS; i++)
     {
     {
-        char *username = get_json_array_value("users", i, data_cstr, MAX_TOKENS);
+        char *username = get_json_array_value("users", i, data_cstr, MAX_TOKENS); // currently its 330 tokens
         if (username == NULL)
         if (username == NULL)
         {
         {
             break;
             break;

+ 10 - 10
feed/flip_social_feed.c

@@ -81,11 +81,11 @@ FlipSocialFeedMini *flip_social_parse_json_feed()
         }
         }
 
 
         // Extract individual fields from the JSON object
         // Extract individual fields from the JSON object
-        char *username = get_json_value("username", item, 64);
-        char *message = get_json_value("message", item, 64);
-        char *flipped = get_json_value("flipped", item, 64);
-        char *flips = get_json_value("flip_count", item, 64);
-        char *id = get_json_value("id", item, 64);
+        char *username = get_json_value("username", item, 40);
+        char *message = get_json_value("message", item, 40);
+        char *flipped = get_json_value("flipped", item, 40);
+        char *flips = get_json_value("flip_count", item, 40);
+        char *id = get_json_value("id", item, 40);
 
 
         if (username == NULL || message == NULL || flipped == NULL || id == NULL)
         if (username == NULL || message == NULL || flipped == NULL || id == NULL)
         {
         {
@@ -167,11 +167,11 @@ bool flip_social_load_feed_post(int post_id)
     }
     }
 
 
     // Extract individual fields from the JSON object
     // Extract individual fields from the JSON object
-    char *username = get_json_value("username", data_cstr, 64);
-    char *message = get_json_value("message", data_cstr, 64);
-    char *flipped = get_json_value("flipped", data_cstr, 64);
-    char *flips = get_json_value("flip_count", data_cstr, 64);
-    char *id = get_json_value("id", data_cstr, 64);
+    char *username = get_json_value("username", data_cstr, 40);
+    char *message = get_json_value("message", data_cstr, 40);
+    char *flipped = get_json_value("flipped", data_cstr, 40);
+    char *flips = get_json_value("flip_count", data_cstr, 40);
+    char *id = get_json_value("id", data_cstr, 40);
 
 
     if (username == NULL || message == NULL || flipped == NULL || id == NULL)
     if (username == NULL || message == NULL || flipped == NULL || id == NULL)
     {
     {