Skip to content

Commit

Permalink
Merge pull request #21 from jblanked/dev_1.0
Browse files Browse the repository at this point in the history
Fixed a freeze that occurred when sending a DM
  • Loading branch information
jblanked authored Dec 28, 2024
2 parents 47fba8d + fa0499d commit 8291261
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 105 deletions.
42 changes: 5 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
4 changes: 2 additions & 2 deletions application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 3 additions & 0 deletions assets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
42 changes: 5 additions & 37 deletions assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
52 changes: 37 additions & 15 deletions callback/flip_social_callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion flip_social.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jsmn/jsmn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions jsmn/jsmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 1 addition & 4 deletions jsmn/jsmn_furi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}",
Expand Down
2 changes: 1 addition & 1 deletion jsmn/jsmn_furi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions jsmn/jsmn_h.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 8291261

Please sign in to comment.