flip_social.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. #include "flip_social.h"
  2. FlipSocialFeed *flip_social_feed = NULL; // Store the feed
  3. FlipSocialModel *flip_social_friends = NULL; // Store the friends
  4. FlipSocialModel2 *flip_social_message_users = NULL; // Store the users that have sent messages to the logged in user
  5. FlipSocialModel *flip_social_explore = NULL; // Store the users to explore
  6. FlipSocialMessage *flip_social_messages = NULL; // Store the messages between the logged in user and the selected user
  7. FlipSocialApp *app_instance = NULL;
  8. bool flip_social_sent_login_request = false;
  9. bool flip_social_sent_register_request = false;
  10. bool flip_social_login_success = false;
  11. bool flip_social_register_success = false;
  12. bool flip_social_dialog_shown = false;
  13. bool flip_social_dialog_stop = false;
  14. bool flip_social_send_message = false;
  15. char *last_explore_response = NULL;
  16. char *selected_message = NULL;
  17. char auth_headers[256] = {0};
  18. /**
  19. * @brief Function to free the resources used by FlipSocialApp.
  20. * @details Cleans up all allocated resources before exiting the application.
  21. * @param app The FlipSocialApp object to free.
  22. * @return void
  23. */
  24. void flip_social_app_free(FlipSocialApp *app)
  25. {
  26. if (!app)
  27. {
  28. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  29. return;
  30. }
  31. if (!app->view_dispatcher)
  32. {
  33. FURI_LOG_E(TAG, "ViewDispatcher is NULL");
  34. return;
  35. }
  36. // Free Submenu(s)
  37. if (app->submenu_logged_out)
  38. {
  39. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutSubmenu);
  40. submenu_free(app->submenu_logged_out);
  41. }
  42. if (app->submenu_logged_in)
  43. {
  44. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInSubmenu);
  45. submenu_free(app->submenu_logged_in);
  46. }
  47. if (app->submenu_compose)
  48. {
  49. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  50. submenu_free(app->submenu_compose);
  51. }
  52. if (app->submenu_explore)
  53. {
  54. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInExploreSubmenu);
  55. submenu_free(app->submenu_explore);
  56. }
  57. if (app->submenu_friends)
  58. {
  59. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInFriendsSubmenu);
  60. submenu_free(app->submenu_friends);
  61. }
  62. if (app->submenu_messages)
  63. {
  64. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
  65. submenu_free(app->submenu_messages);
  66. }
  67. if (app->submenu_messages_user_choices)
  68. {
  69. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesUserChoices);
  70. submenu_free(app->submenu_messages_user_choices);
  71. }
  72. // Free Variable Item List(s)
  73. if (app->variable_item_list_logged_out_wifi_settings)
  74. {
  75. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
  76. variable_item_list_free(app->variable_item_list_logged_out_wifi_settings);
  77. }
  78. if (app->variable_item_list_logged_out_login)
  79. {
  80. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
  81. variable_item_list_free(app->variable_item_list_logged_out_login);
  82. }
  83. if (app->variable_item_list_logged_out_register)
  84. {
  85. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  86. variable_item_list_free(app->variable_item_list_logged_out_register);
  87. }
  88. if (app->variable_item_list_logged_in_profile)
  89. {
  90. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInProfile);
  91. variable_item_list_free(app->variable_item_list_logged_in_profile);
  92. }
  93. if (app->variable_item_list_logged_in_settings)
  94. {
  95. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInSettings);
  96. variable_item_list_free(app->variable_item_list_logged_in_settings);
  97. }
  98. if (app->variable_item_list_logged_in_settings_wifi)
  99. {
  100. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
  101. variable_item_list_free(app->variable_item_list_logged_in_settings_wifi);
  102. }
  103. // Free Text Input(s)
  104. if (app->text_input_logged_out_wifi_settings_ssid)
  105. {
  106. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsSSIDInput);
  107. uart_text_input_free(app->text_input_logged_out_wifi_settings_ssid);
  108. }
  109. if (app->text_input_logged_out_wifi_settings_password)
  110. {
  111. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsPasswordInput);
  112. uart_text_input_free(app->text_input_logged_out_wifi_settings_password);
  113. }
  114. if (app->text_input_logged_out_login_username)
  115. {
  116. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginUsernameInput);
  117. uart_text_input_free(app->text_input_logged_out_login_username);
  118. }
  119. if (app->text_input_logged_out_login_password)
  120. {
  121. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginPasswordInput);
  122. uart_text_input_free(app->text_input_logged_out_login_password);
  123. }
  124. if (app->text_input_logged_out_register_username)
  125. {
  126. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterUsernameInput);
  127. uart_text_input_free(app->text_input_logged_out_register_username);
  128. }
  129. if (app->text_input_logged_out_register_password)
  130. {
  131. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterPasswordInput);
  132. uart_text_input_free(app->text_input_logged_out_register_password);
  133. }
  134. if (app->text_input_logged_out_register_password_2)
  135. {
  136. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterPassword2Input);
  137. uart_text_input_free(app->text_input_logged_out_register_password_2);
  138. }
  139. if (app->text_input_logged_in_change_password)
  140. {
  141. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInChangePasswordInput);
  142. uart_text_input_free(app->text_input_logged_in_change_password);
  143. }
  144. if (app->text_input_logged_in_compose_pre_save_input)
  145. {
  146. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInComposeAddPreSaveInput);
  147. uart_text_input_free(app->text_input_logged_in_compose_pre_save_input);
  148. }
  149. if (app->text_input_logged_in_wifi_settings_ssid)
  150. {
  151. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsSSIDInput);
  152. uart_text_input_free(app->text_input_logged_in_wifi_settings_ssid);
  153. }
  154. if (app->text_input_logged_in_wifi_settings_password)
  155. {
  156. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsPasswordInput);
  157. uart_text_input_free(app->text_input_logged_in_wifi_settings_password);
  158. }
  159. if (app->text_input_logged_in_messages_new_message)
  160. {
  161. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageInput);
  162. uart_text_input_free(app->text_input_logged_in_messages_new_message);
  163. }
  164. if (app->text_input_logged_in_messages_new_message_user_choices)
  165. {
  166. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput);
  167. uart_text_input_free(app->text_input_logged_in_messages_new_message_user_choices);
  168. }
  169. // Free Widget(s)
  170. if (app->widget_logged_out_about)
  171. {
  172. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutAbout);
  173. widget_free(app->widget_logged_out_about);
  174. }
  175. if (app->widget_logged_in_about)
  176. {
  177. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsAbout);
  178. widget_free(app->widget_logged_in_about);
  179. }
  180. // Free View(s)
  181. if (app->view_process_login)
  182. {
  183. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutProcessLogin);
  184. view_free(app->view_process_login);
  185. }
  186. if (app->view_process_register)
  187. {
  188. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutProcessRegister);
  189. view_free(app->view_process_register);
  190. }
  191. if (app->view_process_feed)
  192. {
  193. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
  194. view_free(app->view_process_feed);
  195. }
  196. if (app->view_process_compose)
  197. {
  198. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInProcessCompose);
  199. view_free(app->view_process_compose);
  200. }
  201. if (app->view_process_explore)
  202. {
  203. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInExploreProccess);
  204. view_free(app->view_process_explore);
  205. }
  206. if (app->view_process_friends)
  207. {
  208. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInFriendsProcess);
  209. view_free(app->view_process_friends);
  210. }
  211. if (app->view_process_messages)
  212. {
  213. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesProcess);
  214. view_free(app->view_process_messages);
  215. }
  216. if (app->view_dispatcher)
  217. view_dispatcher_free(app->view_dispatcher);
  218. // Free the app structure members
  219. if (app->wifi_ssid_logged_out)
  220. free(app->wifi_ssid_logged_out);
  221. if (app->wifi_ssid_logged_out_temp_buffer)
  222. free(app->wifi_ssid_logged_out_temp_buffer);
  223. if (app->wifi_password_logged_out)
  224. free(app->wifi_password_logged_out);
  225. if (app->wifi_password_logged_out_temp_buffer)
  226. free(app->wifi_password_logged_out_temp_buffer);
  227. if (app->login_username_logged_out)
  228. free(app->login_username_logged_out);
  229. if (app->login_username_logged_out_temp_buffer)
  230. free(app->login_username_logged_out_temp_buffer);
  231. if (app->login_password_logged_out)
  232. free(app->login_password_logged_out);
  233. if (app->login_password_logged_out_temp_buffer)
  234. free(app->login_password_logged_out_temp_buffer);
  235. if (app->register_username_logged_out)
  236. free(app->register_username_logged_out);
  237. if (app->register_username_logged_out_temp_buffer)
  238. free(app->register_username_logged_out_temp_buffer);
  239. if (app->register_password_logged_out)
  240. free(app->register_password_logged_out);
  241. if (app->register_password_logged_out_temp_buffer)
  242. free(app->register_password_logged_out_temp_buffer);
  243. if (app->register_password_2_logged_out)
  244. free(app->register_password_2_logged_out);
  245. if (app->register_password_2_logged_out_temp_buffer)
  246. free(app->register_password_2_logged_out_temp_buffer);
  247. if (app->change_password_logged_in)
  248. free(app->change_password_logged_in);
  249. if (app->change_password_logged_in_temp_buffer)
  250. free(app->change_password_logged_in_temp_buffer);
  251. if (app->compose_pre_save_logged_in)
  252. free(app->compose_pre_save_logged_in);
  253. if (app->compose_pre_save_logged_in_temp_buffer)
  254. free(app->compose_pre_save_logged_in_temp_buffer);
  255. if (app->wifi_ssid_logged_in)
  256. free(app->wifi_ssid_logged_in);
  257. if (app->wifi_ssid_logged_in_temp_buffer)
  258. free(app->wifi_ssid_logged_in_temp_buffer);
  259. if (app->wifi_password_logged_in)
  260. free(app->wifi_password_logged_in);
  261. if (app->wifi_password_logged_in_temp_buffer)
  262. free(app->wifi_password_logged_in_temp_buffer);
  263. if (app->is_logged_in)
  264. free(app->is_logged_in);
  265. if (app->login_username_logged_in)
  266. free(app->login_username_logged_in);
  267. if (app->login_username_logged_in_temp_buffer)
  268. free(app->login_username_logged_in_temp_buffer);
  269. if (app->messages_new_message_logged_in)
  270. free(app->messages_new_message_logged_in);
  271. if (app->messages_new_message_logged_in_temp_buffer)
  272. free(app->messages_new_message_logged_in_temp_buffer);
  273. if (app->message_user_choice_logged_in)
  274. free(app->message_user_choice_logged_in);
  275. if (app->message_user_choice_logged_in_temp_buffer)
  276. free(app->message_user_choice_logged_in_temp_buffer);
  277. if (last_explore_response)
  278. free(last_explore_response);
  279. if (selected_message)
  280. free(selected_message);
  281. if (app->input_event && app->input_event_queue)
  282. furi_pubsub_unsubscribe(app->input_event_queue, app->input_event);
  283. // DeInit UART
  284. flipper_http_deinit();
  285. // Free the app structure
  286. if (app_instance)
  287. free(app_instance);
  288. }
  289. void auth_headers_alloc(void)
  290. {
  291. if (!app_instance)
  292. {
  293. return;
  294. }
  295. if (app_instance->login_username_logged_out && app_instance->login_password_logged_out)
  296. {
  297. snprintf(auth_headers, sizeof(auth_headers), "{\"Content-Type\":\"application/json\",\"username\":\"%s\",\"password\":\"%s\"}", app_instance->login_username_logged_out, app_instance->login_password_logged_out);
  298. }
  299. else if (app_instance->login_username_logged_in && app_instance->change_password_logged_in)
  300. {
  301. snprintf(auth_headers, sizeof(auth_headers), "{\"Content-Type\":\"application/json\",\"username\":\"%s\",\"password\":\"%s\"}", app_instance->login_username_logged_in, app_instance->change_password_logged_in);
  302. }
  303. else
  304. {
  305. snprintf(auth_headers, sizeof(auth_headers), "{\"Content-Type\":\"application/json\"}");
  306. }
  307. }