flip_social_callback.c 42 KB

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