flip_social_callback.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. // flip_social_callback.h
  2. #ifndef FLIP_SOCIAL_CALLBACK_H
  3. #define FLIP_SOCIAL_CALLBACK_H
  4. /**
  5. * @brief Navigation callback to go back to the submenu Logged out.
  6. * @param context The context - unused
  7. * @return next view id (FlipSocialViewLoggedOutSubmenu)
  8. */
  9. static uint32_t flip_social_callback_to_submenu_logged_out(void *context)
  10. {
  11. UNUSED(context);
  12. return FlipSocialViewLoggedOutSubmenu;
  13. }
  14. /**
  15. * @brief Navigation callback to go back to the submenu Logged in.
  16. * @param context The context - unused
  17. * @return next view id (FlipSocialViewLoggedInSubmenu)
  18. */
  19. static uint32_t flip_social_callback_to_submenu_logged_in(void *context)
  20. {
  21. UNUSED(context);
  22. flip_social_free_explore();
  23. flip_social_free_feed();
  24. flip_social_free_friends();
  25. flip_social_free_message_users();
  26. flip_social_free_messages();
  27. return FlipSocialViewLoggedInSubmenu;
  28. }
  29. /**
  30. * @brief Navigation callback to bring the user back to the (Logged out) Login screen
  31. * @param context The context - unused
  32. * @return next view id (FlipSocialViewLoggedOutLogin)
  33. */
  34. static uint32_t flip_social_callback_to_login_logged_out(void *context)
  35. {
  36. UNUSED(context);
  37. flip_social_sent_login_request = false;
  38. flip_social_login_success = false;
  39. return FlipSocialViewLoggedOutLogin;
  40. }
  41. /**
  42. * @brief Navigation callback to bring the user back to the (Logged out) Register screen
  43. * @param context The context - unused
  44. * @return next view id (FlipSocialViewLoggedOutRegister)
  45. */
  46. static uint32_t flip_social_callback_to_register_logged_out(void *context)
  47. {
  48. UNUSED(context);
  49. flip_social_sent_register_request = false;
  50. flip_social_register_success = false;
  51. return FlipSocialViewLoggedOutRegister;
  52. }
  53. /**
  54. * @brief Navigation callback to bring the user back to the (Logged out) Wifi Settings screen
  55. * @param context The context - unused
  56. * @return next view id (FlipSocialViewLoggedOutWifiSettings)
  57. */
  58. static uint32_t flip_social_callback_to_wifi_settings_logged_out(void *context)
  59. {
  60. UNUSED(context);
  61. return FlipSocialViewLoggedOutWifiSettings;
  62. }
  63. /**
  64. * @brief Navigation callback to bring the user back to the (Logged in) Wifi Settings screen
  65. * @param context The context - unused
  66. * @return next view id (FlipSocialViewLoggedInSettingsWifi)
  67. */
  68. static uint32_t flip_social_callback_to_wifi_settings_logged_in(void *context)
  69. {
  70. UNUSED(context);
  71. return FlipSocialViewLoggedInSettingsWifi;
  72. }
  73. /**
  74. * @brief Navigation callback to bring the user back to the (Logged in) Settings screen
  75. * @param context The context - unused
  76. * @return next view id (FlipSocialViewLoggedInSettingsWifi)
  77. */
  78. static uint32_t flip_social_callback_to_settings_logged_in(void *context)
  79. {
  80. UNUSED(context);
  81. return FlipSocialViewLoggedInSettings;
  82. }
  83. /**
  84. * @brief Navigation callback to bring the user back to the (Logged in) Compose screen
  85. * @param context The context - unused
  86. * @return next view id (FlipSocialViewLoggedInCompose)
  87. */
  88. static uint32_t flip_social_callback_to_compose_logged_in(void *context)
  89. {
  90. UNUSED(context);
  91. return FlipSocialViewLoggedInCompose;
  92. }
  93. /**
  94. * @brief Navigation callback to bring the user back to the (Logged in) Profile screen
  95. * @param context The context - unused
  96. * @return next view id (FlipSocialViewLoggedInProfile)
  97. */
  98. static uint32_t flip_social_callback_to_profile_logged_in(void *context)
  99. {
  100. UNUSED(context);
  101. return FlipSocialViewLoggedInProfile;
  102. }
  103. /**
  104. * @brief Navigation callback to bring the user back to the Explore submenu
  105. * @param context The context - unused
  106. * @return next view id (FlipSocialViewLoggedInExploreSubmenu)
  107. */
  108. static uint32_t flip_social_callback_to_explore_logged_in(void *context)
  109. {
  110. UNUSED(context);
  111. flip_social_dialog_stop = true;
  112. last_explore_response = "";
  113. flip_social_dialog_shown = false;
  114. flip_social_explore->index = 0;
  115. action = ActionNone;
  116. return FlipSocialViewLoggedInExploreSubmenu;
  117. }
  118. /**
  119. * @brief Navigation callback to bring the user back to the Friends submenu
  120. * @param context The context - unused
  121. * @return next view id (FlipSocialViewLoggedInFriendsSubmenu)
  122. */
  123. static uint32_t flip_social_callback_to_friends_logged_in(void *context)
  124. {
  125. UNUSED(context);
  126. flip_social_dialog_stop = true;
  127. last_explore_response = "";
  128. flip_social_dialog_shown = false;
  129. flip_social_friends->index = 0;
  130. action = ActionNone;
  131. return FlipSocialViewLoggedInFriendsSubmenu;
  132. }
  133. /**
  134. * @brief Navigation callback to bring the user back to the Messages submenu
  135. * @param context The context - unused
  136. * @return next view id (FlipSocialViewLoggedInMessagesSubmenu)
  137. */
  138. static uint32_t flip_social_callback_to_messages_logged_in(void *context)
  139. {
  140. UNUSED(context);
  141. return FlipSocialViewLoggedInMessagesSubmenu;
  142. }
  143. /**
  144. * @brief Navigation callback to bring the user back to the User Choices screen
  145. * @param context The context - unused
  146. * @return next view id (FlipSocialViewLoggedInMessagesUserChoices)
  147. */
  148. static uint32_t flip_social_callback_to_messages_user_choices(void *context)
  149. {
  150. UNUSED(context);
  151. return FlipSocialViewLoggedInMessagesUserChoices;
  152. }
  153. /**
  154. * @brief Navigation callback for exiting the application
  155. * @param context The context - unused
  156. * @return next view id (VIEW_NONE to exit the app)
  157. */
  158. static uint32_t flip_social_callback_exit_app(void *context)
  159. {
  160. // Exit the application
  161. if (!context)
  162. {
  163. FURI_LOG_E(TAG, "Context is NULL");
  164. return VIEW_NONE;
  165. }
  166. UNUSED(context);
  167. return VIEW_NONE; // Return VIEW_NONE to exit the app
  168. }
  169. /**
  170. * @brief Handle ALL submenu item selections.
  171. * @param context The context - FlipSocialApp object.
  172. * @param index The FlipSocialSubmenuIndex item that was clicked.
  173. * @return void
  174. */
  175. static void flip_social_callback_submenu_choices(void *context, uint32_t index)
  176. {
  177. FlipSocialApp *app = (FlipSocialApp *)context;
  178. if (!app)
  179. {
  180. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  181. return;
  182. }
  183. switch (index)
  184. {
  185. case FlipSocialSubmenuLoggedOutIndexLogin:
  186. flip_social_sent_login_request = false;
  187. flip_social_login_success = false;
  188. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
  189. break;
  190. case FlipSocialSubmenuLoggedOutIndexRegister:
  191. flip_social_sent_register_request = false;
  192. flip_social_register_success = false;
  193. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  194. break;
  195. case FlipSocialSubmenuLoggedOutIndexAbout:
  196. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutAbout);
  197. break;
  198. case FlipSocialSubmenuLoggedOutIndexWifiSettings:
  199. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
  200. break;
  201. case FlipSocialSubmenuLoggedInIndexProfile:
  202. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInProfile);
  203. break;
  204. case FlipSocialSubmenuLoggedInIndexMessages:
  205. if (flipper_http_process_response_async(flip_social_get_message_users, flip_social_parse_json_message_users))
  206. {
  207. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
  208. }
  209. break;
  210. case FlipSocialSubmenuLoggedInIndexMessagesNewMessage:
  211. if (flipper_http_process_response_async(flip_social_get_explore, flip_social_parse_json_message_user_choices))
  212. {
  213. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesUserChoices);
  214. }
  215. break;
  216. case FlipSocialSubmenuLoggedInIndexFeed:
  217. if (flipper_http_process_response_async(flip_social_get_feed, flip_social_parse_json_feed))
  218. {
  219. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
  220. }
  221. else
  222. {
  223. // Set failure FlipSocialFeed object
  224. if (!flip_social_temp_feed())
  225. {
  226. return;
  227. }
  228. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
  229. }
  230. break;
  231. case FlipSocialSubmenuExploreIndex:
  232. if (flipper_http_process_response_async(flip_social_get_explore, flip_social_parse_json_explore))
  233. {
  234. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInExploreSubmenu);
  235. }
  236. break;
  237. case FlipSocialSubmenuLoggedInIndexCompose:
  238. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  239. break;
  240. case FlipSocialSubmenuLoggedInIndexSettings:
  241. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettings);
  242. break;
  243. case FlipSocialSubmenuLoggedInSignOutButton:
  244. app->is_logged_in = "false";
  245. save_settings(app_instance->wifi_ssid_logged_out, app_instance->wifi_password_logged_out, app_instance->login_username_logged_out, app_instance->login_username_logged_in, app_instance->login_password_logged_out, app_instance->change_password_logged_in, app_instance->is_logged_in);
  246. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutSubmenu);
  247. break;
  248. case FlipSocialSubmenuComposeIndexAddPreSave:
  249. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInComposeAddPreSaveInput);
  250. break;
  251. default:
  252. // Handle the pre-saved message selection (has a max of 25 items)
  253. if (index >= FlipSocialSubemnuComposeIndexStartIndex && index < FlipSocialSubemnuComposeIndexStartIndex + MAX_PRE_SAVED_MESSAGES)
  254. {
  255. flip_social_feed->index = index - FlipSocialSubemnuComposeIndexStartIndex;
  256. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInProcessCompose);
  257. }
  258. // Handle the explore selection
  259. else if (index >= FlipSocialSubmenuExploreIndexStartIndex && index < FlipSocialSubmenuExploreIndexStartIndex + MAX_EXPLORE_USERS)
  260. {
  261. flip_social_explore->index = index - FlipSocialSubmenuExploreIndexStartIndex;
  262. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInExploreProccess);
  263. }
  264. // handle the friends selection
  265. else if (index >= FlipSocialSubmenuLoggedInIndexFriendsStart && index < FlipSocialSubmenuLoggedInIndexFriendsStart + MAX_FRIENDS)
  266. {
  267. flip_social_friends->index = index - FlipSocialSubmenuLoggedInIndexFriendsStart;
  268. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFriendsProcess);
  269. }
  270. // handle the messages selection
  271. else if (index >= FlipSocialSubmenuLoggedInIndexMessagesUsersStart && index < FlipSocialSubmenuLoggedInIndexMessagesUsersStart + MAX_MESSAGE_USERS)
  272. {
  273. flip_social_message_users->index = index - FlipSocialSubmenuLoggedInIndexMessagesUsersStart;
  274. if (flipper_http_process_response_async(flip_social_get_messages_with_user, flip_social_parse_json_messages))
  275. {
  276. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesProcess);
  277. }
  278. }
  279. // handle the messages user choices selection
  280. else if (index >= FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart && index < FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart + MAX_EXPLORE_USERS)
  281. {
  282. flip_social_explore->index = index - FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart;
  283. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput);
  284. }
  285. else
  286. {
  287. FURI_LOG_E(TAG, "Unknown submenu index");
  288. }
  289. break;
  290. }
  291. }
  292. /**
  293. * @brief Text input callback for when the user finishes entering their SSID on the wifi settings (logged out) screen.
  294. * @param context The context - FlipSocialApp object.
  295. * @return void
  296. */
  297. static void flip_social_logged_out_wifi_settings_ssid_updated(void *context)
  298. {
  299. FlipSocialApp *app = (FlipSocialApp *)context;
  300. if (!app)
  301. {
  302. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  303. return;
  304. }
  305. // Store the entered name
  306. strncpy(app->wifi_ssid_logged_out, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  307. // Store the entered name in the logged in name field
  308. strncpy(app->wifi_ssid_logged_in, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  309. strncpy(app->wifi_ssid_logged_in_temp_buffer, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  310. // Ensure null-termination
  311. app->wifi_ssid_logged_out[app->wifi_ssid_logged_out_temp_buffer_size - 1] = '\0';
  312. // Update the name item text
  313. if (app->variable_item_logged_out_wifi_settings_ssid)
  314. {
  315. variable_item_set_current_value_text(app->variable_item_logged_out_wifi_settings_ssid, app->wifi_ssid_logged_out);
  316. }
  317. // update the wifi settings
  318. if (!flipper_http_save_wifi(app->wifi_ssid_logged_out, app->wifi_password_logged_out))
  319. {
  320. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  321. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  322. }
  323. // Save the settings
  324. save_settings(app_instance->wifi_ssid_logged_out, app_instance->wifi_password_logged_out, app_instance->login_username_logged_out, app_instance->login_username_logged_in, app_instance->login_password_logged_out, app_instance->change_password_logged_in, app_instance->is_logged_in);
  325. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
  326. }
  327. /**
  328. * @brief Text input callback for when the user finishes entering their password on the wifi settings (logged out) screen.
  329. * @param context The context - FlipSocialApp object.
  330. * @return void
  331. */
  332. static void flip_social_logged_out_wifi_settings_password_updated(void *context)
  333. {
  334. FlipSocialApp *app = (FlipSocialApp *)context;
  335. if (!app)
  336. {
  337. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  338. return;
  339. }
  340. // Store the entered WiFi password
  341. strncpy(app->wifi_password_logged_out, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  342. // Store the entered WiFi password in the logged in password field
  343. strncpy(app->wifi_password_logged_in, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  344. strncpy(app->wifi_password_logged_in_temp_buffer, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  345. // Ensure null-termination
  346. app->wifi_password_logged_out[app->wifi_password_logged_out_temp_buffer_size - 1] = '\0';
  347. // Update the password item text
  348. if (app->variable_item_logged_out_wifi_settings_password)
  349. {
  350. variable_item_set_current_value_text(app->variable_item_logged_out_wifi_settings_password, app->wifi_password_logged_out);
  351. }
  352. // update the wifi settings
  353. if (!flipper_http_save_wifi(app->wifi_ssid_logged_out, app->wifi_password_logged_out))
  354. {
  355. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  356. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  357. }
  358. // Save the settings
  359. save_settings(app_instance->wifi_ssid_logged_out, app_instance->wifi_password_logged_out, app_instance->login_username_logged_out, app_instance->login_username_logged_in, app_instance->login_password_logged_out, app_instance->change_password_logged_in, app_instance->is_logged_in);
  360. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
  361. }
  362. /**
  363. * @brief Callback when the user selects a menu item in the wifi settings (logged out) screen.
  364. * @param context The context - FlipSocialApp object.
  365. * @param index The index of the selected item.
  366. * @return void
  367. */
  368. static void flip_social_text_input_logged_out_wifi_settings_item_selected(void *context, uint32_t index)
  369. {
  370. FlipSocialApp *app = (FlipSocialApp *)context;
  371. if (!app)
  372. {
  373. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  374. return;
  375. }
  376. switch (index)
  377. {
  378. case 0: // Input SSID
  379. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsSSIDInput);
  380. break;
  381. case 1: // Input Password
  382. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsPasswordInput);
  383. break;
  384. default:
  385. FURI_LOG_E(TAG, "Unknown configuration item index");
  386. break;
  387. }
  388. }
  389. /**
  390. * @brief Text input callback for when the user finishes entering their username on the login (logged out) screen.
  391. * @param context The context - FlipSocialApp object.
  392. * @return void
  393. */
  394. static void flip_social_logged_out_login_username_updated(void *context)
  395. {
  396. FlipSocialApp *app = (FlipSocialApp *)context;
  397. if (!app)
  398. {
  399. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  400. return;
  401. }
  402. // Store the entered name
  403. strncpy(app->login_username_logged_out, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  404. // Store the entered name in the logged in username field
  405. strncpy(app->login_username_logged_in, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  406. strncpy(app->login_username_logged_in_temp_buffer, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  407. // Ensure null-termination
  408. app->login_username_logged_out[app->login_username_logged_out_temp_buffer_size - 1] = '\0';
  409. // Update the name item text
  410. if (app->variable_item_logged_out_login_username)
  411. {
  412. variable_item_set_current_value_text(app->variable_item_logged_out_login_username, app->login_username_logged_out);
  413. }
  414. // Save the settings
  415. save_settings(app_instance->wifi_ssid_logged_out, app_instance->wifi_password_logged_out, app_instance->login_username_logged_out, app_instance->login_username_logged_in, app_instance->login_password_logged_out, app_instance->change_password_logged_in, app_instance->is_logged_in);
  416. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
  417. }
  418. /**
  419. * @brief Text input callback for when the user finishes entering their password on the login (logged out) screen.
  420. * @param context The context - FlipSocialApp object.
  421. * @return void
  422. */
  423. static void flip_social_logged_out_login_password_updated(void *context)
  424. {
  425. FlipSocialApp *app = (FlipSocialApp *)context;
  426. if (!app)
  427. {
  428. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  429. return;
  430. }
  431. // Store the entered password
  432. strncpy(app->login_password_logged_out, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  433. // Store the entered password in the change password field
  434. strncpy(app->change_password_logged_in, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  435. strncpy(app->change_password_logged_in_temp_buffer, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  436. // Ensure null-termination
  437. app->login_password_logged_out[app->login_password_logged_out_temp_buffer_size - 1] = '\0';
  438. // Update the password item text
  439. if (app->variable_item_logged_out_login_password)
  440. {
  441. // dont show the password on the screen (version 0.2)
  442. // variable_item_set_current_value_text(app->variable_item_logged_out_login_password, app->login_password_logged_out);
  443. }
  444. // Save the settings
  445. save_settings(app_instance->wifi_ssid_logged_out, app_instance->wifi_password_logged_out, app_instance->login_username_logged_out, app_instance->login_username_logged_in, app_instance->login_password_logged_out, app_instance->change_password_logged_in, app_instance->is_logged_in);
  446. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
  447. }
  448. /**
  449. * @brief Callback when the user selects a menu item in the login (logged out) screen.
  450. * @param context The context - FlipSocialApp object.
  451. * @param index The index of the selected item.
  452. * @return void
  453. */
  454. static void flip_social_text_input_logged_out_login_item_selected(void *context, uint32_t index)
  455. {
  456. FlipSocialApp *app = (FlipSocialApp *)context;
  457. if (!app)
  458. {
  459. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  460. return;
  461. }
  462. switch (index)
  463. {
  464. case 0: // Input Username
  465. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginUsernameInput);
  466. break;
  467. case 1: // Input Password
  468. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginPasswordInput);
  469. break;
  470. case 2: // Login Button
  471. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutProcessLogin);
  472. break;
  473. default:
  474. FURI_LOG_E(TAG, "Unknown configuration item index");
  475. break;
  476. }
  477. }
  478. /**
  479. * @brief Text input callback for when the user finishes entering their username on the register (logged out) screen.
  480. * @param context The context - FlipSocialApp object.
  481. * @return void
  482. */
  483. static void flip_social_logged_out_register_username_updated(void *context)
  484. {
  485. FlipSocialApp *app = (FlipSocialApp *)context;
  486. if (!app)
  487. {
  488. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  489. return;
  490. }
  491. // Store the entered name
  492. strncpy(app->register_username_logged_out, app->register_username_logged_out_temp_buffer, app->register_username_logged_out_temp_buffer_size);
  493. // Ensure null-termination
  494. app->register_username_logged_out[app->register_username_logged_out_temp_buffer_size - 1] = '\0';
  495. // Update the name item text
  496. if (app->variable_item_logged_out_register_username)
  497. {
  498. variable_item_set_current_value_text(app->variable_item_logged_out_register_username, app->register_username_logged_out);
  499. }
  500. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  501. }
  502. /**
  503. * @brief Text input callback for when the user finishes entering their password on the register (logged out) screen.
  504. * @param context The context - FlipSocialApp object.
  505. * @return void
  506. */
  507. static void flip_social_logged_out_register_password_updated(void *context)
  508. {
  509. FlipSocialApp *app = (FlipSocialApp *)context;
  510. if (!app)
  511. {
  512. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  513. return;
  514. }
  515. // Store the entered password
  516. strncpy(app->register_password_logged_out, app->register_password_logged_out_temp_buffer, app->register_password_logged_out_temp_buffer_size);
  517. // Ensure null-termination
  518. app->register_password_logged_out[app->register_password_logged_out_temp_buffer_size - 1] = '\0';
  519. // Update the password item text
  520. if (app->variable_item_logged_out_register_password)
  521. {
  522. variable_item_set_current_value_text(app->variable_item_logged_out_register_password, app->register_password_logged_out);
  523. }
  524. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  525. }
  526. /**
  527. * @brief Text input callback for when the user finishes entering their password 2 on the register (logged out) screen.
  528. * @param context The context - FlipSocialApp object.
  529. * @return void
  530. */
  531. static void flip_social_logged_out_register_password_2_updated(void *context)
  532. {
  533. FlipSocialApp *app = (FlipSocialApp *)context;
  534. if (!app)
  535. {
  536. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  537. return;
  538. }
  539. // Store the entered password
  540. strncpy(app->register_password_2_logged_out, app->register_password_2_logged_out_temp_buffer, app->register_password_2_logged_out_temp_buffer_size);
  541. // Ensure null-termination
  542. app->register_password_2_logged_out[app->register_password_2_logged_out_temp_buffer_size - 1] = '\0';
  543. // Update the password item text
  544. if (app->variable_item_logged_out_register_password_2)
  545. {
  546. variable_item_set_current_value_text(app->variable_item_logged_out_register_password_2, app->register_password_2_logged_out);
  547. }
  548. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  549. }
  550. /**
  551. * @brief Callback when the user selects a menu item in the register (logged out) screen.
  552. * @param context The context - FlipSocialApp object.
  553. * @param index The index of the selected item.
  554. * @return void
  555. */
  556. static void flip_social_text_input_logged_out_register_item_selected(void *context, uint32_t index)
  557. {
  558. FlipSocialApp *app = (FlipSocialApp *)context;
  559. if (!app)
  560. {
  561. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  562. return;
  563. }
  564. switch (index)
  565. {
  566. case 0: // Input Username
  567. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterUsernameInput);
  568. break;
  569. case 1: // Input Password
  570. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterPasswordInput);
  571. break;
  572. case 2: // Input Password 2
  573. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterPassword2Input);
  574. break;
  575. case 3: // Register button
  576. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutProcessRegister);
  577. break;
  578. default:
  579. FURI_LOG_E(TAG, "Unknown configuration item index");
  580. break;
  581. }
  582. }
  583. /**
  584. * @brief Text input callback for when the user finishes entering their SSID on the wifi settings (logged in) screen.
  585. * @param context The context - FlipSocialApp object.
  586. * @return void
  587. */
  588. static void flip_social_logged_in_wifi_settings_ssid_updated(void *context)
  589. {
  590. FlipSocialApp *app = (FlipSocialApp *)context;
  591. if (!app)
  592. {
  593. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  594. return;
  595. }
  596. // Store the entered SSID
  597. strncpy(app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer, app->wifi_ssid_logged_in_temp_buffer_size);
  598. // Store the entered SSID in the logged out SSID
  599. strncpy(app->wifi_ssid_logged_out, app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer_size);
  600. strncpy(app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer_size);
  601. // Ensure null-termination
  602. app->wifi_ssid_logged_in[app->wifi_ssid_logged_in_temp_buffer_size - 1] = '\0';
  603. // Update the name item text
  604. if (app->variable_item_logged_in_wifi_settings_ssid)
  605. {
  606. variable_item_set_current_value_text(app->variable_item_logged_in_wifi_settings_ssid, app->wifi_ssid_logged_in);
  607. }
  608. // Save the settings
  609. save_settings(app_instance->wifi_ssid_logged_in, app_instance->wifi_password_logged_in, app_instance->login_username_logged_out, app_instance->login_username_logged_in, app_instance->login_password_logged_out, app_instance->change_password_logged_in, app_instance->is_logged_in);
  610. // update the wifi settings
  611. if (strlen(app->wifi_ssid_logged_in) > 0 && strlen(app->wifi_password_logged_in) > 0)
  612. {
  613. if (!flipper_http_save_wifi(app->wifi_ssid_logged_in, app->wifi_password_logged_in))
  614. {
  615. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  616. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  617. }
  618. }
  619. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
  620. }
  621. /**
  622. * @brief Text input callback for when the user finishes entering their password on the wifi settings (logged in) screen.
  623. * @param context The context - FlipSocialApp object.
  624. * @return void
  625. */
  626. static void flip_social_logged_in_wifi_settings_password_updated(void *context)
  627. {
  628. FlipSocialApp *app = (FlipSocialApp *)context;
  629. if (!app)
  630. {
  631. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  632. return;
  633. }
  634. // Store the entered password
  635. strncpy(app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer, app->wifi_password_logged_in_temp_buffer_size);
  636. // Store the entered password in the logged out password
  637. strncpy(app->login_password_logged_out, app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer_size);
  638. strncpy(app->login_password_logged_out_temp_buffer, app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer_size);
  639. // Ensure null-termination
  640. app->wifi_password_logged_in[app->wifi_password_logged_in_temp_buffer_size - 1] = '\0';
  641. // Update the password item text
  642. if (app->variable_item_logged_in_wifi_settings_password)
  643. {
  644. // dont show the password on the screen (version 0.2)
  645. // variable_item_set_current_value_text(app->variable_item_logged_in_wifi_settings_password, app->wifi_password_logged_in);
  646. }
  647. // Save the settings
  648. save_settings(app_instance->wifi_ssid_logged_in, app_instance->wifi_password_logged_in, app_instance->login_username_logged_out, app_instance->login_username_logged_in, app_instance->login_password_logged_out, app_instance->change_password_logged_in, app_instance->is_logged_in);
  649. // update the wifi settings
  650. if (strlen(app->wifi_ssid_logged_in) > 0 && strlen(app->wifi_password_logged_in) > 0)
  651. {
  652. if (!flipper_http_save_wifi(app->wifi_ssid_logged_in, app->wifi_password_logged_in))
  653. {
  654. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  655. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  656. }
  657. }
  658. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
  659. }
  660. /**
  661. * @brief Callback when the user selects a menu item in the wifi settings (logged in) screen.
  662. * @param context The context - FlipSocialApp object.
  663. * @param index The index of the selected item.
  664. * @return void
  665. */
  666. static void flip_social_text_input_logged_in_wifi_settings_item_selected(void *context, uint32_t index)
  667. {
  668. FlipSocialApp *app = (FlipSocialApp *)context;
  669. if (!app)
  670. {
  671. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  672. return;
  673. }
  674. switch (index)
  675. {
  676. case 0: // Input SSID
  677. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsSSIDInput);
  678. break;
  679. case 1: // Input Password
  680. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsPasswordInput);
  681. break;
  682. default:
  683. FURI_LOG_E(TAG, "Unknown configuration item index");
  684. break;
  685. }
  686. }
  687. /**
  688. * @brief Text input callback for when the user finishes entering their message on the compose (logged in) screen for Add Text
  689. * @param context The context - FlipSocialApp object.
  690. * @return void
  691. */
  692. static void flip_social_logged_in_compose_pre_save_updated(void *context)
  693. {
  694. FlipSocialApp *app = (FlipSocialApp *)context;
  695. if (!app)
  696. {
  697. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  698. return;
  699. }
  700. // check if the message is empty or if adding in the message would exceed the MAX_PRE_SAVED_MESSAGES
  701. if (app->compose_pre_save_logged_in_temp_buffer_size == 0 || app->pre_saved_messages.count >= MAX_PRE_SAVED_MESSAGES)
  702. {
  703. FURI_LOG_E(TAG, "Message is empty or would exceed the maximum number of pre-saved messages");
  704. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  705. return;
  706. }
  707. // Store the entered message
  708. strncpy(app->compose_pre_save_logged_in, app->compose_pre_save_logged_in_temp_buffer, app->compose_pre_save_logged_in_temp_buffer_size);
  709. // Ensure null-termination
  710. app->compose_pre_save_logged_in[app->compose_pre_save_logged_in_temp_buffer_size - 1] = '\0';
  711. // add the item to the submenu
  712. submenu_reset(app->submenu_compose);
  713. // loop through the items and add them to the submenu
  714. app->pre_saved_messages.messages[app->pre_saved_messages.count] = app->compose_pre_save_logged_in;
  715. app->pre_saved_messages.count++;
  716. submenu_add_item(app->submenu_compose, "Add Pre-Save", FlipSocialSubmenuComposeIndexAddPreSave, flip_social_callback_submenu_choices, app);
  717. for (uint32_t i = 0; i < app->pre_saved_messages.count; i++)
  718. {
  719. submenu_add_item(app->submenu_compose, app->pre_saved_messages.messages[i], FlipSocialSubemnuComposeIndexStartIndex + i, flip_social_callback_submenu_choices, app);
  720. }
  721. // save playlist
  722. save_playlist(&app->pre_saved_messages);
  723. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  724. }
  725. /**
  726. * @brief Text input callback for when the user finishes entering their message on the profile (logged in) screen for change password
  727. * @param context The context - FlipSocialApp object.
  728. * @return void
  729. */
  730. static void flip_social_logged_in_profile_change_password_updated(void *context)
  731. {
  732. FlipSocialApp *app = (FlipSocialApp *)context;
  733. if (!app)
  734. {
  735. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  736. return;
  737. }
  738. // Correct type: old_pass should be a pointer to a string (char *)
  739. const char *old_password = app->login_password_logged_out;
  740. // Store the entered message
  741. strncpy(app->change_password_logged_in, app->change_password_logged_in_temp_buffer, app->change_password_logged_in_temp_buffer_size);
  742. // store the entered password in the logged out password
  743. strncpy(app->login_password_logged_out, app->change_password_logged_in, app->login_password_logged_out_temp_buffer_size);
  744. strncpy(app->login_password_logged_out_temp_buffer, app->change_password_logged_in, app->login_password_logged_out_temp_buffer_size);
  745. // Ensure null-termination
  746. app->change_password_logged_in[app->change_password_logged_in_temp_buffer_size - 1] = '\0';
  747. // Update the message item text
  748. if (app->variable_item_logged_in_profile_change_password)
  749. {
  750. // dont show the password on the screen (version 0.2)
  751. // variable_item_set_current_value_text(app->variable_item_logged_in_profile_change_password, app->change_password_logged_in);
  752. }
  753. // send post request to change password
  754. char payload[256];
  755. snprintf(payload, sizeof(payload), "{\"username\":\"%s\",\"old_password\":\"%s\",\"new_password\":\"%s\"}", app->login_username_logged_out, old_password, app->change_password_logged_in);
  756. char *headers = jsmn("Content-Type", "application/json");
  757. if (!flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/change-password/", headers, payload))
  758. {
  759. FURI_LOG_E(TAG, "Failed to send post request to change password");
  760. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  761. free(headers);
  762. return;
  763. }
  764. free(headers);
  765. // Save the settings
  766. save_settings(app_instance->wifi_ssid_logged_out, app_instance->wifi_password_logged_out, app_instance->login_username_logged_out, app_instance->login_username_logged_in, app_instance->login_password_logged_out, app_instance->change_password_logged_in, app_instance->is_logged_in);
  767. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInProfile);
  768. }
  769. /**
  770. * @brief Callback when a user selects a menu item in the profile (logged in) screen.
  771. * @param context The context - FlipSocialApp object.
  772. * @param index The index of the selected item.
  773. * @return void
  774. */
  775. static void flip_social_text_input_logged_in_profile_item_selected(void *context, uint32_t index)
  776. {
  777. FlipSocialApp *app = (FlipSocialApp *)context;
  778. if (!app)
  779. {
  780. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  781. return;
  782. }
  783. switch (index)
  784. {
  785. case 0: // Change Username
  786. // do nothing since username cannot be changed
  787. break;
  788. case 1: // Change Password
  789. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInChangePasswordInput);
  790. break;
  791. case 2: // Friends
  792. // get friends then switch to the friends screen
  793. if (flip_social_get_friends()) // start the async friends request
  794. {
  795. furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
  796. }
  797. while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
  798. {
  799. // Wait for the friends to be received
  800. furi_delay_ms(100);
  801. }
  802. furi_timer_stop(fhttp.get_timeout_timer);
  803. if (!flip_social_parse_json_friends()) // parse the JSON before switching to the friends (synchonous)
  804. {
  805. FURI_LOG_E(TAG, "Failed to parse the JSON friends...");
  806. return; // just return for now, no temporary friends yet
  807. // show a popup message saving wifi is disconnected
  808. }
  809. furi_timer_stop(fhttp.get_timeout_timer);
  810. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFriendsSubmenu);
  811. break;
  812. default:
  813. FURI_LOG_E(TAG, "Unknown configuration item index");
  814. break;
  815. }
  816. }
  817. /**
  818. * @brief Callback when a user selects a menu item in the settings (logged in) screen.
  819. * @param context The context - FlipSocialApp object.
  820. * @param index The index of the selected item.
  821. * @return void
  822. */
  823. static void flip_social_text_input_logged_in_settings_item_selected(void *context, uint32_t index)
  824. {
  825. FlipSocialApp *app = (FlipSocialApp *)context;
  826. if (!app)
  827. {
  828. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  829. return;
  830. }
  831. switch (index)
  832. {
  833. case 0: // About
  834. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsAbout);
  835. break;
  836. case 1: // Wifi
  837. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
  838. break;
  839. default:
  840. break;
  841. }
  842. }
  843. /**
  844. * @brief Text input callback for when the user finishes entering their message to send to the selected user choice (user choice messages view)
  845. * @param context The context - FlipSocialApp object.
  846. * @return void
  847. */
  848. static void flip_social_logged_in_messages_user_choice_message_updated(void *context)
  849. {
  850. FlipSocialApp *app = (FlipSocialApp *)context;
  851. if (!app)
  852. {
  853. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  854. return;
  855. }
  856. // check if the message is empty
  857. if (app->message_user_choice_logged_in_temp_buffer_size == 0)
  858. {
  859. FURI_LOG_E(TAG, "Message is empty");
  860. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput);
  861. return;
  862. }
  863. // Store the entered message
  864. strncpy(app->message_user_choice_logged_in, app->message_user_choice_logged_in_temp_buffer, app->message_user_choice_logged_in_temp_buffer_size);
  865. // Ensure null-termination
  866. app->message_user_choice_logged_in[app->message_user_choice_logged_in_temp_buffer_size - 1] = '\0';
  867. // send post request to send message
  868. char url[128];
  869. char payload[256];
  870. snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
  871. snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_explore->usernames[flip_social_explore->index], app->message_user_choice_logged_in);
  872. char *headers = jsmn("Content-Type", "application/json");
  873. if (flipper_http_post_request_with_headers(url, headers, payload)) // start the async request
  874. {
  875. furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
  876. fhttp.state = RECEIVING;
  877. free(headers);
  878. }
  879. else
  880. {
  881. FURI_LOG_E(TAG, "Failed to send post request to send message");
  882. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  883. free(headers);
  884. return;
  885. }
  886. while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
  887. {
  888. // Wait for the request to be received
  889. furi_delay_ms(100);
  890. }
  891. furi_timer_stop(fhttp.get_timeout_timer);
  892. // add user to the message list
  893. strncpy(flip_social_message_users->usernames[flip_social_message_users->count], flip_social_explore->usernames[flip_social_explore->index], strlen(flip_social_explore->usernames[flip_social_explore->index]));
  894. flip_social_message_users->count++;
  895. // redraw submenu
  896. flip_social_update_messages_submenu();
  897. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
  898. }
  899. /**
  900. * @brief Text input callback for when the user finishes entering their message to the selected user (messages view)
  901. * @param context The context - FlipSocialApp object.
  902. * @return void
  903. */
  904. static void flip_social_logged_in_messages_new_message_updated(void *context)
  905. {
  906. FlipSocialApp *app = (FlipSocialApp *)context;
  907. if (!app)
  908. {
  909. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  910. return;
  911. }
  912. // check if the message is empty
  913. if (app->messages_new_message_logged_in_temp_buffer_size == 0)
  914. {
  915. FURI_LOG_E(TAG, "Message is empty");
  916. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageInput);
  917. return;
  918. }
  919. // Store the entered message
  920. strncpy(app->messages_new_message_logged_in, app->messages_new_message_logged_in_temp_buffer, app->messages_new_message_logged_in_temp_buffer_size);
  921. // Ensure null-termination
  922. app->messages_new_message_logged_in[app->messages_new_message_logged_in_temp_buffer_size - 1] = '\0';
  923. // send post request to send message
  924. char url[128];
  925. char payload[256];
  926. snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
  927. snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_message_users->usernames[flip_social_message_users->index], app->messages_new_message_logged_in);
  928. char *headers = jsmn("Content-Type", "application/json");
  929. if (flipper_http_post_request_with_headers(url, headers, payload)) // start the async request
  930. {
  931. furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
  932. fhttp.state = RECEIVING;
  933. free(headers);
  934. }
  935. else
  936. {
  937. FURI_LOG_E(TAG, "Failed to send post request to send message");
  938. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  939. free(headers);
  940. return;
  941. }
  942. while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
  943. {
  944. // Wait for the request to be received
  945. furi_delay_ms(100);
  946. }
  947. furi_timer_stop(fhttp.get_timeout_timer);
  948. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
  949. }
  950. #endif // FLIP_SOCIAL_CALLBACK_H