flip_social.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. #ifndef FLIP_SOCIAL_H
  2. #define FLIP_SOCIAL_H
  3. #include <easy_flipper/easy_flipper.h>
  4. #include <dialogs/dialogs.h>
  5. #include <storage/storage.h>
  6. #include <flipper_http/flipper_http.h>
  7. #include <input/input.h>
  8. #include <flip_social_icons.h>
  9. #define TAG "FlipSocial"
  10. #define VERSION_TAG TAG " v1.0"
  11. #define MAX_PRE_SAVED_MESSAGES 20 // Maximum number of pre-saved messages
  12. #define MAX_MESSAGE_LENGTH 100 // Maximum length of a message in the feed
  13. #define MAX_EXPLORE_USERS 50 // Maximum number of users to explore
  14. #define MAX_USER_LENGTH 32 // Maximum length of a username
  15. #define MAX_FRIENDS 50 // Maximum number of friends
  16. #define MAX_TOKENS 576 // Adjust based on expected JSON tokens
  17. #define MAX_FEED_ITEMS 50 // Maximum number of feed items
  18. #define MAX_LINE_LENGTH 30
  19. #define MAX_MESSAGE_USERS 40 // Maximum number of users to display in the submenu
  20. #define MAX_MESSAGES 20 // Maximum number of meesages between each user
  21. #define SETTINGS_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/settings.bin"
  22. #define PRE_SAVED_MESSAGES_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/pre_saved_messages.txt"
  23. // Define the submenu items for our Hello World application
  24. typedef enum
  25. {
  26. FlipSocialSubmenuLoggedOutIndexLogin, // click to go to the login screen
  27. FlipSocialSubmenuLoggedOutIndexRegister, // click to go to the register screen
  28. FlipSocialSubmenuLoggedOutIndexAbout, // click to go to the about screen
  29. FlipSocialSubmenuLoggedOutIndexWifiSettings, // click to go to the wifi settings screen
  30. //
  31. FlipSocialSubmenuLoggedInIndexProfile, // click to go to the profile screen
  32. FlipSocialSubmenuExploreIndex, // click to go to the explore
  33. FlipSocialSubmenuLoggedInIndexFeed, // click to go to the feed screen
  34. FlipSocialSubmenuLoggedInIndexMessages, // click to go to the messages screen
  35. FlipSocialSubmenuLoggedInIndexCompose, // click to go to the compose screen
  36. FlipSocialSubmenuLoggedInIndexSettings, // click to go to the settings screen
  37. FlipSocialSubmenuLoggedInSignOutButton, // click to sign out
  38. //
  39. FlipSocialSubmenuLoggedInIndexMessagesNewMessage, // click to add a new message
  40. //
  41. FlipSocialSubmenuComposeIndexAddPreSave, // click to add a pre-saved message
  42. FlipSocialSubemnuComposeIndexStartIndex = 100, // starting index for the first pre saved message
  43. //
  44. FlipSocialSubmenuExploreIndexStartIndex = 200, // starting index for the users to explore
  45. //
  46. FlipSocialSubmenuLoggedInIndexFriendsStart = 400, // starting index for the friends
  47. //
  48. FlipSocialSubmenuLoggedInIndexMessagesUsersStart = 600, // starting index for the messages
  49. //
  50. FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart = 800, // click to select a user to message
  51. } FlipSocialSubmenuIndex;
  52. // Define the ScriptPlaylist structure
  53. typedef struct
  54. {
  55. char messages[MAX_PRE_SAVED_MESSAGES][MAX_MESSAGE_LENGTH];
  56. size_t count;
  57. size_t index;
  58. } PreSavedPlaylist;
  59. // Define a FlipSocialFeed individual item
  60. typedef struct
  61. {
  62. char username[MAX_USER_LENGTH];
  63. char message[MAX_MESSAGE_LENGTH];
  64. bool is_flipped;
  65. int id;
  66. int flips;
  67. } FlipSocialFeedItem;
  68. typedef struct
  69. {
  70. int ids[MAX_FEED_ITEMS];
  71. size_t count;
  72. size_t index;
  73. } FlipSocialFeedMini;
  74. typedef struct
  75. {
  76. char *usernames[MAX_EXPLORE_USERS];
  77. int count;
  78. int index;
  79. } FlipSocialModel;
  80. typedef struct
  81. {
  82. char *usernames[MAX_MESSAGE_USERS];
  83. int count;
  84. int index;
  85. } FlipSocialModel2;
  86. typedef struct
  87. {
  88. char *usernames[MAX_MESSAGES];
  89. char *messages[MAX_MESSAGES];
  90. int count;
  91. int index;
  92. } FlipSocialMessage;
  93. // Define views for our Hello World application
  94. typedef enum
  95. {
  96. FlipSocialViewLoggedOutSubmenu, // The menu if the user is not logged in
  97. FlipSocialViewLoggedOutLogin, // The login screen
  98. FlipSocialViewLoggedOutRegister, // The register screen
  99. FlipSocialViewLoggedOutAbout, // The about screen
  100. FlipSocialViewLoggedOutWifiSettings, // The wifi settings screen
  101. //
  102. FlipSocialViewLoggedOutLoginUsernameInput, // Text input screen for username input on login screen
  103. FlipSocialViewLoggedOutLoginPasswordInput, // Text input screen for password input on login screen
  104. FlipSocialViewLoggedOutRegisterUsernameInput, // Text input screen for username input on register screen
  105. FlipSocialViewLoggedOutRegisterPasswordInput, // Text input screen for password input on register screen
  106. FlipSocialViewLoggedOutRegisterPassword2Input, // Text input screen for password 2 input on register screen
  107. FlipSocialViewLoggedOutWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
  108. FlipSocialViewLoggedOutWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
  109. FlipSocialViewLoggedOutProcessLogin, // The screen displayed after clicking login
  110. FlipSocialViewLoggedOutProcessRegister, // The screen displayed after clicking register
  111. //
  112. FlipSocialViewLoggedInSubmenu, // The menu if the user is logged in
  113. FlipSocialViewLoggedInProfile, // The profile screen
  114. FlipSocialViewLoggedInFeed, // The feed screen
  115. FlipSocialViewLoggedInCompose, // The compose screen
  116. FlipSocialViewLoggedInSettings, // The settings screen
  117. //
  118. FlipSocialViewLoggedInChangeBioInput, // Text input screen for bio input on profile screen
  119. FlipSocialViewLoggedInChangePasswordInput, // Text input screen for password input on change password screen
  120. FlipSocialViewLoggedInComposeAddPreSaveInput, // Text input screen for add text input on compose screen
  121. //
  122. FlipSocialViewLoggedInMessagesNewMessageInput, // Text input screen for new message input on messages screen
  123. FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput, // Text input screen for new message input on messages screen
  124. FlipSocialViewLoggedInMessagesUserChoices, // the view after clicking [New Message] - select a user to message, then direct to input view
  125. FlipSocialViewLoggedInExploreInput, // Text input screen for explore input on explore screen
  126. FlipSocialViewLoggedInMessageUsersInput,
  127. //
  128. FlipSocialViewLoggedInSettingsAbout, // The about screen
  129. FlipSocialViewLoggedInSettingsWifi, // The wifi settings screen
  130. FlipSocialViewLoggedInWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
  131. FlipSocialViewLoggedInWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
  132. //
  133. FlipSocialViewLoggedInSignOut, // The view after clicking the sign out button
  134. //
  135. FlipSocialViewLoggedInExploreSubmenu, // The view after clicking the explore button
  136. FlipSocialViewLoggedInFriendsSubmenu, // The view after clicking the friends button on the profile screen
  137. FlipSocialViewLoggedInMessagesSubmenu, // The view after clicking the messages button on the profile screen
  138. //
  139. FlipSocialViewLoading, // The loading screen
  140. //
  141. FlipSocialViewWidgetResult, // The text box that displays the random fact
  142. FlipSocialViewLoader, // The loader screen retrieves data from the internet
  143. //
  144. FlipSocialViewExploreDialog, // The dialog for the explore screen
  145. FlipSocialViewFriendsDialog, // The dialog for the friends screen
  146. FlipSocialViewMessagesDialog, // The dialog for the messages screen
  147. FlipSocialViewComposeDialog, // The dialog for the compose screen
  148. FlipSocialViewFeedDialog, // The dialog for the feed screen
  149. } FlipSocialView;
  150. // Define the application structure
  151. typedef struct
  152. {
  153. View *view_loader;
  154. Widget *widget_result;
  155. //
  156. ViewDispatcher *view_dispatcher; // Switches between our views
  157. Submenu *submenu_logged_out; // The application submenu (logged out)
  158. Submenu *submenu_logged_in; // The application submenu (logged in)
  159. Submenu *submenu_compose; // The application submenu (compose)
  160. Submenu *submenu_explore; // The application submenu (explore)
  161. Submenu *submenu_friends; // The application submenu (friends)
  162. Submenu *submenu_messages; // The application submenu (messages)
  163. Submenu *submenu_messages_user_choices; // The application submenu (messages user choices)
  164. Widget *widget_logged_out_about; // The about screen (logged out)
  165. Widget *widget_logged_in_about; // The about screen (logged in)
  166. VariableItemList *variable_item_list_logged_out_wifi_settings; // The wifi settings menu
  167. VariableItemList *variable_item_list_logged_out_login; // The login menu
  168. VariableItemList *variable_item_list_logged_out_register; // The register menu
  169. //
  170. VariableItemList *variable_item_list_logged_in_profile; // The profile menu
  171. VariableItemList *variable_item_list_logged_in_settings; // The settings menu
  172. VariableItemList *variable_item_list_logged_in_settings_wifi; // The wifi settings menu
  173. UART_TextInput *text_input_logged_out_wifi_settings_ssid; // Text input for ssid input on wifi settings screen
  174. UART_TextInput *text_input_logged_out_wifi_settings_password; // Text input for password input on wifi settings screen
  175. UART_TextInput *text_input_logged_out_login_username; // Text input for username input on login screen
  176. UART_TextInput *text_input_logged_out_login_password; // Text input for password input on login screen
  177. UART_TextInput *text_input_logged_out_register_username; // Text input for username input on register screen
  178. UART_TextInput *text_input_logged_out_register_password; // Text input for password input on register screen
  179. UART_TextInput *text_input_logged_out_register_password_2; // Text input for password 2 input on register screen
  180. //
  181. UART_TextInput *text_input_logged_in_change_password; // Text input for password input on change password screen
  182. UART_TextInput *text_input_logged_in_change_bio; // Text input for bio input on profile screen
  183. UART_TextInput *text_input_logged_in_compose_pre_save_input; // Text input for pre save input on compose screen
  184. UART_TextInput *text_input_logged_in_wifi_settings_ssid; // Text input for ssid input on wifi settings screen
  185. UART_TextInput *text_input_logged_in_wifi_settings_password; // Text input for password input on wifi settings screen
  186. //
  187. UART_TextInput *text_input_logged_in_messages_new_message; // Text input for new message input on messages screen
  188. UART_TextInput *text_input_logged_in_messages_new_message_user_choices; //
  189. //
  190. UART_TextInput *text_input_logged_in_explore; // Text input for explore input on explore screen
  191. UART_TextInput *text_input_logged_in_message_users;
  192. VariableItem *variable_item_logged_out_wifi_settings_ssid; // Reference to the ssid configuration item
  193. VariableItem *variable_item_logged_out_wifi_settings_password; // Reference to the password configuration item
  194. VariableItem *variable_item_logged_out_login_username; // Reference to the username configuration item
  195. VariableItem *variable_item_logged_out_login_password; // Reference to the password configuration item
  196. VariableItem *variable_item_logged_out_login_button; // Reference to the login button configuration item
  197. VariableItem *variable_item_logged_out_register_username; // Reference to the username configuration item
  198. VariableItem *variable_item_logged_out_register_password; // Reference to the password configuration item
  199. VariableItem *variable_item_logged_out_register_password_2; // Reference to the password 2 configuration item
  200. VariableItem *variable_item_logged_out_register_button; // Reference to the register button configuration item
  201. //
  202. VariableItem *variable_item_logged_in_profile_username; // Reference to the username configuration item
  203. VariableItem *variable_item_logged_in_profile_change_password; // Reference to the change password configuration item
  204. VariableItem *variable_item_logged_in_profile_change_bio; // Reference to the change bio configuration item
  205. //
  206. VariableItem *variable_item_logged_in_settings_about; // Reference to the about configuration item
  207. VariableItem *variable_item_logged_in_settings_wifi; // Reference to the wifi settings configuration item
  208. VariableItem *variable_item_logged_in_wifi_settings_ssid; // Reference to the ssid configuration item
  209. VariableItem *variable_item_logged_in_wifi_settings_password; // Reference to the password configuration item
  210. //
  211. VariableItem *variable_item_logged_in_profile_friends; // Reference to the friends configuration item
  212. //
  213. PreSavedPlaylist pre_saved_messages; // Pre-saved messages for the feed screen
  214. char *is_logged_in; // Store the login status
  215. uint32_t is_logged_in_size; // Size of the login status buffer
  216. char *login_username_logged_in; // Store the entered login username
  217. char *login_username_logged_in_temp_buffer; // Temporary buffer for login username text input
  218. uint32_t login_username_logged_in_temp_buffer_size; // Size of the login username temporary buffer
  219. char *change_bio_logged_in; // Store the entered bio
  220. char *change_bio_logged_in_temp_buffer; // Temporary buffer for bio text input
  221. uint32_t change_bio_logged_in_temp_buffer_size; // Size of the bio temporary buffer
  222. //
  223. char *wifi_ssid_logged_out; // Store the entered wifi ssid
  224. char *wifi_ssid_logged_out_temp_buffer; // Temporary buffer for wifi ssid text input
  225. uint32_t wifi_ssid_logged_out_temp_buffer_size; // Size of the wifi ssid temporary buffer
  226. char *wifi_password_logged_out; // Store the entered wifi password
  227. char *wifi_password_logged_out_temp_buffer; // Temporary buffer for wifi_password text input
  228. uint32_t wifi_password_logged_out_temp_buffer_size; // Size of the wifi_password temporary buffer
  229. char *login_username_logged_out; // Store the entered login username
  230. char *login_username_logged_out_temp_buffer; // Temporary buffer for login username text input
  231. uint32_t login_username_logged_out_temp_buffer_size; // Size of the login username temporary buffer
  232. char *login_password_logged_out; // Store the entered login password
  233. char *login_password_logged_out_temp_buffer; // Temporary buffer for login password text input
  234. uint32_t login_password_logged_out_temp_buffer_size; // Size of the login password temporary buffer
  235. char *register_username_logged_out; // Store the entered register username
  236. char *register_username_logged_out_temp_buffer; // Temporary buffer for register username text input
  237. uint32_t register_username_logged_out_temp_buffer_size; // Size of the register username temporary buffer
  238. char *register_password_logged_out; // Store the entered register password
  239. char *register_password_logged_out_temp_buffer; // Temporary buffer for register password text input
  240. uint32_t register_password_logged_out_temp_buffer_size; // Size of the register password temporary buffer
  241. char *register_password_2_logged_out; // Store the entered register password 2
  242. char *register_password_2_logged_out_temp_buffer; // Temporary buffer for register password 2 text input
  243. uint32_t register_password_2_logged_out_temp_buffer_size; // Size of the register password 2 temporary buffer
  244. //
  245. char *change_password_logged_in; // Store the entered change password
  246. char *change_password_logged_in_temp_buffer; // Temporary buffer for change password text input
  247. uint32_t change_password_logged_in_temp_buffer_size; // Size of the change password temporary buffer
  248. char *compose_pre_save_logged_in; // Store the entered add text
  249. char *compose_pre_save_logged_in_temp_buffer; // Temporary buffer for add text text input
  250. uint32_t compose_pre_save_logged_in_temp_buffer_size; // Size of the add text temporary buffer
  251. char *wifi_ssid_logged_in; // Store the entered wifi ssid
  252. char *wifi_ssid_logged_in_temp_buffer; // Temporary buffer for wifi ssid text input
  253. uint32_t wifi_ssid_logged_in_temp_buffer_size; // Size of the wifi ssid temporary buffer
  254. char *wifi_password_logged_in; // Store the entered wifi password
  255. char *wifi_password_logged_in_temp_buffer; // Temporary buffer for wifi_password text input
  256. uint32_t wifi_password_logged_in_temp_buffer_size; // Size of the wifi_password temporary buffer
  257. //
  258. char *messages_new_message_logged_in; // Store the entered new message
  259. char *messages_new_message_logged_in_temp_buffer; // Temporary buffer for new message text input
  260. uint32_t messages_new_message_logged_in_temp_buffer_size; // Size of the new message temporary buffer
  261. char *message_user_choice_logged_in; // Store the entered message to send to the selected user
  262. char *message_user_choice_logged_in_temp_buffer; // Temporary buffer for message to send to the selected user
  263. uint32_t message_user_choice_logged_in_temp_buffer_size; // Size of the message to send to the selected user temporary buffer
  264. //
  265. char *explore_logged_in; // Store the entered explore
  266. char *explore_logged_in_temp_buffer; // Temporary buffer for explore text input
  267. uint32_t explore_logged_in_temp_buffer_size; // Size of the explore temporary buffer
  268. char *message_users_logged_in; // Store the entered message users
  269. char *message_users_logged_in_temp_buffer; // Temporary buffer for message users text input
  270. uint32_t message_users_logged_in_temp_buffer_size; // Size of the message users temporary buffer
  271. Loading *loading; // The loading screen
  272. DialogEx *dialog_explore;
  273. DialogEx *dialog_friends;
  274. DialogEx *dialog_messages;
  275. DialogEx *dialog_compose;
  276. DialogEx *dialog_feed;
  277. char *explore_user_bio; // Store the bio of the selected user
  278. } FlipSocialApp;
  279. void flip_social_app_free(FlipSocialApp *app);
  280. extern FlipSocialModel *flip_social_friends; // Store the friends
  281. extern FlipSocialModel2 *flip_social_message_users; // Store the users that have sent messages to the logged in user
  282. extern FlipSocialModel *flip_social_explore; // Store the users to explore
  283. extern FlipSocialMessage *flip_social_messages; // Store the messages between the logged in user and the selected user
  284. extern FlipSocialFeedMini *flip_feed_info; // Store the feed info
  285. extern FlipSocialFeedItem *flip_feed_item; // Store a feed item
  286. extern FlipSocialApp *app_instance;
  287. extern bool flip_social_sent_login_request;
  288. extern bool flip_social_sent_register_request;
  289. extern bool flip_social_login_success;
  290. extern bool flip_social_register_success;
  291. extern bool flip_social_dialog_shown;
  292. extern bool flip_social_dialog_stop;
  293. extern bool flip_social_send_message;
  294. extern char *selected_message;
  295. extern char auth_headers[256];
  296. void auth_headers_alloc(void);
  297. FlipSocialFeedMini *flip_feed_info_alloc(void);
  298. void flip_feed_info_free(void);
  299. #endif