flip_social.h 17 KB

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