flip_social_callback.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  1. #include <callback/flip_social_callback.h>
  2. // Below added by Derek Jamison
  3. // FURI_LOG_DEV will log only during app development. Be sure that Settings/System/Log Device is "LPUART"; so we dont use serial port.
  4. #ifdef DEVELOPMENT
  5. #define FURI_LOG_DEV(tag, format, ...) furi_log_print_format(FuriLogLevelInfo, tag, format, ##__VA_ARGS__)
  6. #define DEV_CRASH() furi_crash()
  7. #else
  8. #define FURI_LOG_DEV(tag, format, ...)
  9. #define DEV_CRASH()
  10. #endif
  11. static void flip_social_request_error_draw(Canvas *canvas)
  12. {
  13. if (canvas == NULL)
  14. {
  15. FURI_LOG_E(TAG, "flip_social_request_error_draw - canvas is NULL");
  16. DEV_CRASH();
  17. return;
  18. }
  19. if (fhttp.last_response != NULL)
  20. {
  21. if (strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL)
  22. {
  23. canvas_clear(canvas);
  24. canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
  25. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  26. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  27. }
  28. else if (strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL)
  29. {
  30. canvas_clear(canvas);
  31. canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
  32. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  33. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  34. }
  35. else if (strstr(fhttp.last_response, "[ERROR] GET request failed or returned empty data.") != NULL)
  36. {
  37. canvas_clear(canvas);
  38. canvas_draw_str(canvas, 0, 10, "[ERROR] WiFi error.");
  39. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  40. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  41. }
  42. else if (strstr(fhttp.last_response, "[PONG]") != NULL)
  43. {
  44. canvas_clear(canvas);
  45. canvas_draw_str(canvas, 0, 10, "[STATUS]Connecting to AP...");
  46. }
  47. else
  48. {
  49. canvas_clear(canvas);
  50. FURI_LOG_E(TAG, "Received an error: %s", fhttp.last_response);
  51. canvas_draw_str(canvas, 0, 10, "[ERROR] Unusual error...");
  52. canvas_draw_str(canvas, 0, 60, "Press BACK and retry.");
  53. }
  54. }
  55. else
  56. {
  57. canvas_clear(canvas);
  58. canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
  59. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  60. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  61. }
  62. }
  63. /**
  64. * @brief Navigation callback to go back to the submenu Logged out.
  65. * @param context The context - unused
  66. * @return next view id (FlipSocialViewLoggedOutSubmenu)
  67. */
  68. uint32_t flip_social_callback_to_submenu_logged_out(void *context)
  69. {
  70. UNUSED(context);
  71. return FlipSocialViewLoggedOutSubmenu;
  72. }
  73. /**
  74. * @brief Navigation callback to go back to the submenu Logged in.
  75. * @param context The context - unused
  76. * @return next view id (FlipSocialViewLoggedInSubmenu)
  77. */
  78. uint32_t flip_social_callback_to_submenu_logged_in(void *context)
  79. {
  80. UNUSED(context);
  81. flip_social_free_explore();
  82. flip_social_free_friends();
  83. flip_social_free_message_users();
  84. flip_social_free_messages();
  85. flip_feed_info_free();
  86. if (flip_feed_item)
  87. {
  88. free(flip_feed_item);
  89. flip_feed_item = NULL;
  90. }
  91. return FlipSocialViewLoggedInSubmenu;
  92. }
  93. /**
  94. * @brief Navigation callback to bring the user back to the (Logged out) Login screen
  95. * @param context The context - unused
  96. * @return next view id (FlipSocialViewLoggedOutLogin)
  97. */
  98. uint32_t flip_social_callback_to_login_logged_out(void *context)
  99. {
  100. UNUSED(context);
  101. flip_social_sent_login_request = false;
  102. flip_social_login_success = false;
  103. return FlipSocialViewLoggedOutLogin;
  104. }
  105. /**
  106. * @brief Navigation callback to bring the user back to the (Logged out) Register screen
  107. * @param context The context - unused
  108. * @return next view id (FlipSocialViewLoggedOutRegister)
  109. */
  110. uint32_t flip_social_callback_to_register_logged_out(void *context)
  111. {
  112. UNUSED(context);
  113. flip_social_sent_register_request = false;
  114. flip_social_register_success = false;
  115. return FlipSocialViewLoggedOutRegister;
  116. }
  117. /**
  118. * @brief Navigation callback to bring the user back to the (Logged out) Wifi Settings screen
  119. * @param context The context - unused
  120. * @return next view id (FlipSocialViewLoggedOutWifiSettings)
  121. */
  122. uint32_t flip_social_callback_to_wifi_settings_logged_out(void *context)
  123. {
  124. UNUSED(context);
  125. return FlipSocialViewLoggedOutWifiSettings;
  126. }
  127. /**
  128. * @brief Navigation callback to bring the user back to the (Logged in) Wifi Settings screen
  129. * @param context The context - unused
  130. * @return next view id (FlipSocialViewLoggedInSettingsWifi)
  131. */
  132. uint32_t flip_social_callback_to_wifi_settings_logged_in(void *context)
  133. {
  134. UNUSED(context);
  135. return FlipSocialViewLoggedInSettingsWifi;
  136. }
  137. /**
  138. * @brief Navigation callback to bring the user back to the (Logged in) Settings screen
  139. * @param context The context - unused
  140. * @return next view id (FlipSocialViewLoggedInSettingsWifi)
  141. */
  142. uint32_t flip_social_callback_to_settings_logged_in(void *context)
  143. {
  144. UNUSED(context);
  145. return FlipSocialViewLoggedInSettings;
  146. }
  147. /**
  148. * @brief Navigation callback to bring the user back to the (Logged in) Compose screen
  149. * @param context The context - unused
  150. * @return next view id (FlipSocialViewLoggedInCompose)
  151. */
  152. uint32_t flip_social_callback_to_compose_logged_in(void *context)
  153. {
  154. UNUSED(context);
  155. return FlipSocialViewLoggedInCompose;
  156. }
  157. /**
  158. * @brief Navigation callback to bring the user back to the (Logged in) Profile screen
  159. * @param context The context - unused
  160. * @return next view id (FlipSocialViewLoggedInProfile)
  161. */
  162. uint32_t flip_social_callback_to_profile_logged_in(void *context)
  163. {
  164. UNUSED(context);
  165. return FlipSocialViewLoggedInProfile;
  166. }
  167. /**
  168. * @brief Navigation callback to bring the user back to the Explore submenu
  169. * @param context The context - unused
  170. * @return next view id (FlipSocialViewLoggedInExploreSubmenu)
  171. */
  172. uint32_t flip_social_callback_to_explore_logged_in(void *context)
  173. {
  174. UNUSED(context);
  175. flip_social_dialog_stop = false;
  176. last_explore_response = "";
  177. flip_social_dialog_shown = false;
  178. flip_social_explore->index = 0;
  179. action = ActionNone;
  180. return FlipSocialViewLoggedInExploreSubmenu;
  181. }
  182. /**
  183. * @brief Navigation callback to bring the user back to the Friends submenu
  184. * @param context The context - unused
  185. * @return next view id (FlipSocialViewLoggedInFriendsSubmenu)
  186. */
  187. uint32_t flip_social_callback_to_friends_logged_in(void *context)
  188. {
  189. UNUSED(context);
  190. flip_social_dialog_stop = false;
  191. last_explore_response = "";
  192. flip_social_dialog_shown = false;
  193. flip_social_friends->index = 0;
  194. action = ActionNone;
  195. return FlipSocialViewLoggedInFriendsSubmenu;
  196. }
  197. /**
  198. * @brief Navigation callback to bring the user back to the Messages submenu
  199. * @param context The context - unused
  200. * @return next view id (FlipSocialViewLoggedInMessagesSubmenu)
  201. */
  202. uint32_t flip_social_callback_to_messages_logged_in(void *context)
  203. {
  204. UNUSED(context);
  205. return FlipSocialViewLoggedInMessagesSubmenu;
  206. }
  207. /**
  208. * @brief Navigation callback to bring the user back to the User Choices screen
  209. * @param context The context - unused
  210. * @return next view id (FlipSocialViewLoggedInMessagesUserChoices)
  211. */
  212. uint32_t flip_social_callback_to_messages_user_choices(void *context)
  213. {
  214. UNUSED(context);
  215. return FlipSocialViewLoggedInMessagesUserChoices;
  216. }
  217. /**
  218. * @brief Navigation callback for exiting the application
  219. * @param context The context - unused
  220. * @return next view id (VIEW_NONE to exit the app)
  221. */
  222. uint32_t flip_social_callback_exit_app(void *context)
  223. {
  224. // Exit the application
  225. if (!context)
  226. {
  227. FURI_LOG_E(TAG, "Context is NULL");
  228. return VIEW_NONE;
  229. }
  230. UNUSED(context);
  231. return VIEW_NONE; // Return VIEW_NONE to exit the app
  232. }
  233. /**
  234. * @brief Handle ALL submenu item selections.
  235. * @param context The context - FlipSocialApp object.
  236. * @param index The FlipSocialSubmenuIndex item that was clicked.
  237. * @return void
  238. */
  239. void flip_social_callback_submenu_choices(void *context, uint32_t index)
  240. {
  241. FlipSocialApp *app = (FlipSocialApp *)context;
  242. if (!app)
  243. {
  244. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  245. return;
  246. }
  247. switch (index)
  248. {
  249. case FlipSocialSubmenuLoggedOutIndexLogin:
  250. flip_social_sent_login_request = false;
  251. flip_social_login_success = false;
  252. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
  253. break;
  254. case FlipSocialSubmenuLoggedOutIndexRegister:
  255. flip_social_sent_register_request = false;
  256. flip_social_register_success = false;
  257. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  258. break;
  259. case FlipSocialSubmenuLoggedOutIndexAbout:
  260. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutAbout);
  261. break;
  262. case FlipSocialSubmenuLoggedOutIndexWifiSettings:
  263. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
  264. break;
  265. case FlipSocialSubmenuLoggedInIndexProfile:
  266. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInProfile);
  267. break;
  268. case FlipSocialSubmenuLoggedInIndexMessages:
  269. flipper_http_loading_task(
  270. flip_social_get_message_users, // get the message users
  271. flip_social_parse_json_message_users, // parse the message users
  272. FlipSocialViewLoggedInMessagesSubmenu, // switch to the messages submenu if successful
  273. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  274. &app->view_dispatcher); // view dispatcher
  275. break;
  276. case FlipSocialSubmenuLoggedInIndexMessagesNewMessage:
  277. flipper_http_loading_task(
  278. flip_social_get_explore, // get the explore users
  279. flip_social_parse_json_message_user_choices, // parse the explore users
  280. FlipSocialViewLoggedInMessagesUserChoices, // switch to the user choices if successful
  281. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  282. &app->view_dispatcher); // view dispatcher
  283. break;
  284. case FlipSocialSubmenuLoggedInIndexFeed:
  285. if (fhttp.state == INACTIVE)
  286. {
  287. FURI_LOG_E(TAG, "HTTP state is INACTIVE");
  288. return;
  289. }
  290. if (!easy_flipper_set_loading(&app->loading, FlipSocialViewLoading, flip_social_callback_to_submenu_logged_in, &app->view_dispatcher))
  291. {
  292. FURI_LOG_E(TAG, "Failed to set loading screen");
  293. return; // already on the submenu
  294. }
  295. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoading);
  296. if (flip_social_get_feed()) // start the async request
  297. {
  298. furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
  299. fhttp.state = RECEIVING;
  300. }
  301. else
  302. {
  303. FURI_LOG_E(HTTP_TAG, "Failed to send request");
  304. fhttp.state = ISSUE;
  305. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSubmenu);
  306. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoading);
  307. loading_free(app->loading);
  308. return;
  309. }
  310. while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
  311. {
  312. // Wait for the request to be received
  313. furi_delay_ms(100);
  314. }
  315. furi_timer_stop(fhttp.get_timeout_timer);
  316. // load feed info
  317. flip_feed_info = flip_social_parse_json_feed();
  318. if (!flip_feed_info || flip_feed_info->count < 1)
  319. {
  320. FURI_LOG_E(TAG, "Failed to parse JSON feed");
  321. fhttp.state = ISSUE;
  322. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSubmenu);
  323. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoading);
  324. loading_free(app->loading);
  325. return;
  326. }
  327. // load the current feed post
  328. if (!flip_social_load_feed_post(flip_feed_info->ids[flip_feed_info->index]))
  329. {
  330. FURI_LOG_E(TAG, "Failed to load feed post");
  331. fhttp.state = ISSUE;
  332. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSubmenu);
  333. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoading);
  334. loading_free(app->loading);
  335. return;
  336. }
  337. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
  338. view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoading);
  339. loading_free(app->loading);
  340. break;
  341. case FlipSocialSubmenuExploreIndex:
  342. flipper_http_loading_task(
  343. flip_social_get_explore, // get the explore users
  344. flip_social_parse_json_explore, // parse the explore users
  345. FlipSocialViewLoggedInExploreSubmenu, // switch to the explore submenu if successful
  346. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  347. &app->view_dispatcher); // view dispatcher
  348. break;
  349. case FlipSocialSubmenuLoggedInIndexCompose:
  350. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  351. break;
  352. case FlipSocialSubmenuLoggedInIndexSettings:
  353. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettings);
  354. break;
  355. case FlipSocialSubmenuLoggedInSignOutButton:
  356. app->is_logged_in = "false";
  357. 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);
  358. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutSubmenu);
  359. break;
  360. case FlipSocialSubmenuComposeIndexAddPreSave:
  361. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInComposeAddPreSaveInput);
  362. break;
  363. default:
  364. action = ActionNone;
  365. // Handle the pre-saved message selection (has a max of 25 items)
  366. if (index >= FlipSocialSubemnuComposeIndexStartIndex && index < FlipSocialSubemnuComposeIndexStartIndex + MAX_PRE_SAVED_MESSAGES)
  367. {
  368. app->pre_saved_messages.index = index - FlipSocialSubemnuComposeIndexStartIndex;
  369. snprintf(selected_message, MAX_MESSAGE_LENGTH, "%s", app->pre_saved_messages.messages[app->pre_saved_messages.index]);
  370. if (!selected_message)
  371. {
  372. FURI_LOG_E(TAG, "Selected message is NULL");
  373. return;
  374. }
  375. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInProcessCompose);
  376. }
  377. // Handle the explore selection
  378. else if (index >= FlipSocialSubmenuExploreIndexStartIndex && index < FlipSocialSubmenuExploreIndexStartIndex + MAX_EXPLORE_USERS)
  379. {
  380. if (!flip_social_explore)
  381. {
  382. FURI_LOG_E(TAG, "FlipSocialExplore is NULL");
  383. return;
  384. }
  385. flip_social_explore->index = index - FlipSocialSubmenuExploreIndexStartIndex;
  386. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInExploreProccess);
  387. }
  388. // handle the friends selection
  389. else if (index >= FlipSocialSubmenuLoggedInIndexFriendsStart && index < FlipSocialSubmenuLoggedInIndexFriendsStart + MAX_FRIENDS)
  390. {
  391. if (!flip_social_friends)
  392. {
  393. FURI_LOG_E(TAG, "FlipSocialFriends is NULL");
  394. return;
  395. }
  396. flip_social_friends->index = index - FlipSocialSubmenuLoggedInIndexFriendsStart;
  397. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFriendsProcess);
  398. }
  399. // handle the messages selection
  400. else if (index >= FlipSocialSubmenuLoggedInIndexMessagesUsersStart && index < FlipSocialSubmenuLoggedInIndexMessagesUsersStart + MAX_MESSAGE_USERS)
  401. {
  402. if (!flip_social_message_users)
  403. {
  404. FURI_LOG_E(TAG, "FlipSocialMessageUsers is NULL");
  405. return;
  406. }
  407. flip_social_message_users->index = index - FlipSocialSubmenuLoggedInIndexMessagesUsersStart;
  408. flipper_http_loading_task(
  409. flip_social_get_messages_with_user, // get the messages with the selected user
  410. flip_social_parse_json_messages, // parse the messages
  411. FlipSocialViewLoggedInMessagesProcess, // switch to the messages process if successful
  412. FlipSocialViewLoggedInMessagesSubmenu, // switch back to the messages submenu if failed
  413. &app->view_dispatcher); // view dispatcher
  414. }
  415. // handle the messages user choices selection
  416. else if (index >= FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart && index < FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart + MAX_EXPLORE_USERS)
  417. {
  418. if (!flip_social_explore)
  419. {
  420. FURI_LOG_E(TAG, "FlipSocialExplore is NULL");
  421. return;
  422. }
  423. flip_social_explore->index = index - FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart;
  424. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput);
  425. }
  426. else
  427. {
  428. FURI_LOG_E(TAG, "Unknown submenu index");
  429. }
  430. break;
  431. }
  432. }
  433. /**
  434. * @brief Text input callback for when the user finishes entering their SSID on the wifi settings (logged out) screen.
  435. * @param context The context - FlipSocialApp object.
  436. * @return void
  437. */
  438. void flip_social_logged_out_wifi_settings_ssid_updated(void *context)
  439. {
  440. FlipSocialApp *app = (FlipSocialApp *)context;
  441. if (!app)
  442. {
  443. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  444. return;
  445. }
  446. // Store the entered name
  447. strncpy(app->wifi_ssid_logged_out, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  448. // Store the entered name in the logged in name field
  449. strncpy(app->wifi_ssid_logged_in, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  450. strncpy(app->wifi_ssid_logged_in_temp_buffer, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  451. // Ensure null-termination
  452. app->wifi_ssid_logged_out[app->wifi_ssid_logged_out_temp_buffer_size - 1] = '\0';
  453. // Update the name item text
  454. if (app->variable_item_logged_out_wifi_settings_ssid)
  455. {
  456. variable_item_set_current_value_text(app->variable_item_logged_out_wifi_settings_ssid, app->wifi_ssid_logged_out);
  457. }
  458. // update the wifi settings
  459. if (strlen(app->wifi_ssid_logged_out) > 0 && strlen(app->wifi_password_logged_out) > 0)
  460. {
  461. if (!flipper_http_save_wifi(app->wifi_ssid_logged_out, app->wifi_password_logged_out))
  462. {
  463. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  464. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  465. }
  466. }
  467. // Save the settings
  468. 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);
  469. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
  470. }
  471. /**
  472. * @brief Text input callback for when the user finishes entering their password on the wifi settings (logged out) screen.
  473. * @param context The context - FlipSocialApp object.
  474. * @return void
  475. */
  476. void flip_social_logged_out_wifi_settings_password_updated(void *context)
  477. {
  478. FlipSocialApp *app = (FlipSocialApp *)context;
  479. if (!app)
  480. {
  481. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  482. return;
  483. }
  484. // Store the entered WiFi password
  485. strncpy(app->wifi_password_logged_out, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  486. // Store the entered WiFi password in the logged in password field
  487. strncpy(app->wifi_password_logged_in, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  488. strncpy(app->wifi_password_logged_in_temp_buffer, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  489. // Ensure null-termination
  490. app->wifi_password_logged_out[app->wifi_password_logged_out_temp_buffer_size - 1] = '\0';
  491. // Update the password item text
  492. if (app->variable_item_logged_out_wifi_settings_password)
  493. {
  494. variable_item_set_current_value_text(app->variable_item_logged_out_wifi_settings_password, app->wifi_password_logged_out);
  495. }
  496. // update the wifi settings
  497. if (strlen(app->wifi_ssid_logged_out) > 0 && strlen(app->wifi_password_logged_out) > 0)
  498. {
  499. if (!flipper_http_save_wifi(app->wifi_ssid_logged_out, app->wifi_password_logged_out))
  500. {
  501. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  502. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  503. }
  504. }
  505. // Save the settings
  506. 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);
  507. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
  508. }
  509. /**
  510. * @brief Callback when the user selects a menu item in the wifi settings (logged out) screen.
  511. * @param context The context - FlipSocialApp object.
  512. * @param index The index of the selected item.
  513. * @return void
  514. */
  515. void flip_social_text_input_logged_out_wifi_settings_item_selected(void *context, uint32_t index)
  516. {
  517. FlipSocialApp *app = (FlipSocialApp *)context;
  518. if (!app)
  519. {
  520. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  521. return;
  522. }
  523. switch (index)
  524. {
  525. case 0: // Input SSID
  526. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsSSIDInput);
  527. break;
  528. case 1: // Input Password
  529. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsPasswordInput);
  530. break;
  531. default:
  532. FURI_LOG_E(TAG, "Unknown configuration item index");
  533. break;
  534. }
  535. }
  536. /**
  537. * @brief Text input callback for when the user finishes entering their username on the login (logged out) screen.
  538. * @param context The context - FlipSocialApp object.
  539. * @return void
  540. */
  541. void flip_social_logged_out_login_username_updated(void *context)
  542. {
  543. FlipSocialApp *app = (FlipSocialApp *)context;
  544. if (!app)
  545. {
  546. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  547. return;
  548. }
  549. // Store the entered name
  550. strncpy(app->login_username_logged_out, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  551. // Store the entered name in the logged in username field
  552. strncpy(app->login_username_logged_in, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  553. strncpy(app->login_username_logged_in_temp_buffer, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  554. // Ensure null-termination
  555. app->login_username_logged_out[app->login_username_logged_out_temp_buffer_size - 1] = '\0';
  556. // Update the name item text
  557. if (app->variable_item_logged_out_login_username)
  558. {
  559. variable_item_set_current_value_text(app->variable_item_logged_out_login_username, app->login_username_logged_out);
  560. }
  561. // Save the settings
  562. 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);
  563. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
  564. }
  565. /**
  566. * @brief Text input callback for when the user finishes entering their password on the login (logged out) screen.
  567. * @param context The context - FlipSocialApp object.
  568. * @return void
  569. */
  570. void flip_social_logged_out_login_password_updated(void *context)
  571. {
  572. FlipSocialApp *app = (FlipSocialApp *)context;
  573. if (!app)
  574. {
  575. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  576. return;
  577. }
  578. // Store the entered password
  579. strncpy(app->login_password_logged_out, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  580. // Store the entered password in the change password field
  581. strncpy(app->change_password_logged_in, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  582. strncpy(app->change_password_logged_in_temp_buffer, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  583. // Ensure null-termination
  584. app->login_password_logged_out[app->login_password_logged_out_temp_buffer_size - 1] = '\0';
  585. // Update the password item text
  586. if (app->variable_item_logged_out_login_password)
  587. {
  588. // dont show the password on the screen (version 0.2)
  589. // variable_item_set_current_value_text(app->variable_item_logged_out_login_password, app->login_password_logged_out);
  590. }
  591. // Save the settings
  592. 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);
  593. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
  594. }
  595. /**
  596. * @brief Callback when the user selects a menu item in the login (logged out) screen.
  597. * @param context The context - FlipSocialApp object.
  598. * @param index The index of the selected item.
  599. * @return void
  600. */
  601. void flip_social_text_input_logged_out_login_item_selected(void *context, uint32_t index)
  602. {
  603. FlipSocialApp *app = (FlipSocialApp *)context;
  604. if (!app)
  605. {
  606. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  607. return;
  608. }
  609. switch (index)
  610. {
  611. case 0: // Input Username
  612. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginUsernameInput);
  613. break;
  614. case 1: // Input Password
  615. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginPasswordInput);
  616. break;
  617. case 2: // Login Button
  618. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutProcessLogin);
  619. break;
  620. default:
  621. FURI_LOG_E(TAG, "Unknown configuration item index");
  622. break;
  623. }
  624. }
  625. /**
  626. * @brief Text input callback for when the user finishes entering their username on the register (logged out) screen.
  627. * @param context The context - FlipSocialApp object.
  628. * @return void
  629. */
  630. void flip_social_logged_out_register_username_updated(void *context)
  631. {
  632. FlipSocialApp *app = (FlipSocialApp *)context;
  633. if (!app)
  634. {
  635. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  636. return;
  637. }
  638. // Store the entered name
  639. strncpy(app->register_username_logged_out, app->register_username_logged_out_temp_buffer, app->register_username_logged_out_temp_buffer_size);
  640. // Ensure null-termination
  641. app->register_username_logged_out[app->register_username_logged_out_temp_buffer_size - 1] = '\0';
  642. // Update the name item text
  643. if (app->variable_item_logged_out_register_username)
  644. {
  645. variable_item_set_current_value_text(app->variable_item_logged_out_register_username, app->register_username_logged_out);
  646. }
  647. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  648. }
  649. /**
  650. * @brief Text input callback for when the user finishes entering their password on the register (logged out) screen.
  651. * @param context The context - FlipSocialApp object.
  652. * @return void
  653. */
  654. void flip_social_logged_out_register_password_updated(void *context)
  655. {
  656. FlipSocialApp *app = (FlipSocialApp *)context;
  657. if (!app)
  658. {
  659. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  660. return;
  661. }
  662. // Store the entered password
  663. strncpy(app->register_password_logged_out, app->register_password_logged_out_temp_buffer, app->register_password_logged_out_temp_buffer_size);
  664. // Ensure null-termination
  665. app->register_password_logged_out[app->register_password_logged_out_temp_buffer_size - 1] = '\0';
  666. // Update the password item text
  667. if (app->variable_item_logged_out_register_password)
  668. {
  669. variable_item_set_current_value_text(app->variable_item_logged_out_register_password, app->register_password_logged_out);
  670. }
  671. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  672. }
  673. /**
  674. * @brief Text input callback for when the user finishes entering their password 2 on the register (logged out) screen.
  675. * @param context The context - FlipSocialApp object.
  676. * @return void
  677. */
  678. void flip_social_logged_out_register_password_2_updated(void *context)
  679. {
  680. FlipSocialApp *app = (FlipSocialApp *)context;
  681. if (!app)
  682. {
  683. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  684. return;
  685. }
  686. // Store the entered password
  687. strncpy(app->register_password_2_logged_out, app->register_password_2_logged_out_temp_buffer, app->register_password_2_logged_out_temp_buffer_size);
  688. // Ensure null-termination
  689. app->register_password_2_logged_out[app->register_password_2_logged_out_temp_buffer_size - 1] = '\0';
  690. // Update the password item text
  691. if (app->variable_item_logged_out_register_password_2)
  692. {
  693. variable_item_set_current_value_text(app->variable_item_logged_out_register_password_2, app->register_password_2_logged_out);
  694. }
  695. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  696. }
  697. /**
  698. * @brief Callback when the user selects a menu item in the register (logged out) screen.
  699. * @param context The context - FlipSocialApp object.
  700. * @param index The index of the selected item.
  701. * @return void
  702. */
  703. void flip_social_text_input_logged_out_register_item_selected(void *context, uint32_t index)
  704. {
  705. FlipSocialApp *app = (FlipSocialApp *)context;
  706. if (!app)
  707. {
  708. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  709. return;
  710. }
  711. switch (index)
  712. {
  713. case 0: // Input Username
  714. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterUsernameInput);
  715. break;
  716. case 1: // Input Password
  717. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterPasswordInput);
  718. break;
  719. case 2: // Input Password 2
  720. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterPassword2Input);
  721. break;
  722. case 3: // Register button
  723. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutProcessRegister);
  724. break;
  725. default:
  726. FURI_LOG_E(TAG, "Unknown configuration item index");
  727. break;
  728. }
  729. }
  730. /**
  731. * @brief Text input callback for when the user finishes entering their SSID on the wifi settings (logged in) screen.
  732. * @param context The context - FlipSocialApp object.
  733. * @return void
  734. */
  735. void flip_social_logged_in_wifi_settings_ssid_updated(void *context)
  736. {
  737. FlipSocialApp *app = (FlipSocialApp *)context;
  738. if (!app)
  739. {
  740. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  741. return;
  742. }
  743. // Store the entered SSID
  744. strncpy(app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer, app->wifi_ssid_logged_in_temp_buffer_size);
  745. // Store the entered SSID in the logged out SSID
  746. strncpy(app->wifi_ssid_logged_out, app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer_size);
  747. strncpy(app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer_size);
  748. // Ensure null-termination
  749. app->wifi_ssid_logged_in[app->wifi_ssid_logged_in_temp_buffer_size - 1] = '\0';
  750. // Update the name item text
  751. if (app->variable_item_logged_in_wifi_settings_ssid)
  752. {
  753. variable_item_set_current_value_text(app->variable_item_logged_in_wifi_settings_ssid, app->wifi_ssid_logged_in);
  754. }
  755. // Save the settings
  756. 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);
  757. // update the wifi settings
  758. if (strlen(app->wifi_ssid_logged_in) > 0 && strlen(app->wifi_password_logged_in) > 0)
  759. {
  760. if (!flipper_http_save_wifi(app->wifi_ssid_logged_in, app->wifi_password_logged_in))
  761. {
  762. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  763. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  764. }
  765. }
  766. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
  767. }
  768. /**
  769. * @brief Text input callback for when the user finishes entering their password on the wifi settings (logged in) screen.
  770. * @param context The context - FlipSocialApp object.
  771. * @return void
  772. */
  773. void flip_social_logged_in_wifi_settings_password_updated(void *context)
  774. {
  775. FlipSocialApp *app = (FlipSocialApp *)context;
  776. if (!app)
  777. {
  778. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  779. return;
  780. }
  781. // Store the entered password
  782. strncpy(app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer, app->wifi_password_logged_in_temp_buffer_size);
  783. // Store the entered password in the logged out password
  784. strncpy(app->login_password_logged_out, app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer_size);
  785. strncpy(app->login_password_logged_out_temp_buffer, app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer_size);
  786. // Ensure null-termination
  787. app->wifi_password_logged_in[app->wifi_password_logged_in_temp_buffer_size - 1] = '\0';
  788. // Update the password item text
  789. if (app->variable_item_logged_in_wifi_settings_password)
  790. {
  791. // dont show the password on the screen (version 0.2)
  792. // variable_item_set_current_value_text(app->variable_item_logged_in_wifi_settings_password, app->wifi_password_logged_in);
  793. }
  794. // Save the settings
  795. 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);
  796. // update the wifi settings
  797. if (strlen(app->wifi_ssid_logged_in) > 0 && strlen(app->wifi_password_logged_in) > 0)
  798. {
  799. if (!flipper_http_save_wifi(app->wifi_ssid_logged_in, app->wifi_password_logged_in))
  800. {
  801. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  802. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  803. }
  804. }
  805. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
  806. }
  807. /**
  808. * @brief Callback when the user selects a menu item in the wifi settings (logged in) screen.
  809. * @param context The context - FlipSocialApp object.
  810. * @param index The index of the selected item.
  811. * @return void
  812. */
  813. void flip_social_text_input_logged_in_wifi_settings_item_selected(void *context, uint32_t index)
  814. {
  815. FlipSocialApp *app = (FlipSocialApp *)context;
  816. if (!app)
  817. {
  818. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  819. return;
  820. }
  821. switch (index)
  822. {
  823. case 0: // Input SSID
  824. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsSSIDInput);
  825. break;
  826. case 1: // Input Password
  827. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsPasswordInput);
  828. break;
  829. default:
  830. FURI_LOG_E(TAG, "Unknown configuration item index");
  831. break;
  832. }
  833. }
  834. /**
  835. * @brief Text input callback for when the user finishes entering their message on the compose (logged in) screen for Add Text
  836. * @param context The context - FlipSocialApp object.
  837. * @return void
  838. */
  839. void flip_social_logged_in_compose_pre_save_updated(void *context)
  840. {
  841. FlipSocialApp *app = (FlipSocialApp *)context;
  842. if (!app)
  843. {
  844. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  845. return;
  846. }
  847. // check if the message is empty or if adding in the message would exceed the MAX_PRE_SAVED_MESSAGES
  848. if (app->compose_pre_save_logged_in_temp_buffer_size == 0 || app->pre_saved_messages.count >= MAX_PRE_SAVED_MESSAGES)
  849. {
  850. FURI_LOG_E(TAG, "Message is empty or would exceed the maximum number of pre-saved messages");
  851. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  852. return;
  853. }
  854. // Store the entered message
  855. strncpy(app->compose_pre_save_logged_in, app->compose_pre_save_logged_in_temp_buffer, app->compose_pre_save_logged_in_temp_buffer_size);
  856. // Ensure null-termination
  857. app->compose_pre_save_logged_in[app->compose_pre_save_logged_in_temp_buffer_size - 1] = '\0';
  858. // add the item to the submenu
  859. submenu_reset(app->submenu_compose);
  860. // loop through the items and add them to the submenu
  861. app->pre_saved_messages.messages[app->pre_saved_messages.count] = app->compose_pre_save_logged_in;
  862. app->pre_saved_messages.count++;
  863. submenu_add_item(app->submenu_compose, "Add Pre-Save", FlipSocialSubmenuComposeIndexAddPreSave, flip_social_callback_submenu_choices, app);
  864. for (uint32_t i = 0; i < app->pre_saved_messages.count; i++)
  865. {
  866. submenu_add_item(app->submenu_compose, app->pre_saved_messages.messages[i], FlipSocialSubemnuComposeIndexStartIndex + i, flip_social_callback_submenu_choices, app);
  867. }
  868. // save playlist
  869. save_playlist(&app->pre_saved_messages);
  870. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  871. }
  872. /**
  873. * @brief Text input callback for when the user finishes entering their message on the profile (logged in) screen for change password
  874. * @param context The context - FlipSocialApp object.
  875. * @return void
  876. */
  877. void flip_social_logged_in_profile_change_password_updated(void *context)
  878. {
  879. FlipSocialApp *app = (FlipSocialApp *)context;
  880. if (!app)
  881. {
  882. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  883. return;
  884. }
  885. // Correct type: old_pass should be a pointer to a string (char *)
  886. const char *old_password = app->login_password_logged_out;
  887. // Store the entered message
  888. strncpy(app->change_password_logged_in, app->change_password_logged_in_temp_buffer, app->change_password_logged_in_temp_buffer_size);
  889. // store the entered password in the logged out password
  890. strncpy(app->login_password_logged_out, app->change_password_logged_in, app->login_password_logged_out_temp_buffer_size);
  891. strncpy(app->login_password_logged_out_temp_buffer, app->change_password_logged_in, app->login_password_logged_out_temp_buffer_size);
  892. // Ensure null-termination
  893. app->change_password_logged_in[app->change_password_logged_in_temp_buffer_size - 1] = '\0';
  894. // Update the message item text
  895. if (app->variable_item_logged_in_profile_change_password)
  896. {
  897. // dont show the password on the screen (version 0.2)
  898. // variable_item_set_current_value_text(app->variable_item_logged_in_profile_change_password, app->change_password_logged_in);
  899. }
  900. // send post request to change password
  901. auth_headers_alloc();
  902. char payload[256];
  903. snprintf(payload, sizeof(payload), "{\"username\":\"%s\",\"old_password\":\"%s\",\"new_password\":\"%s\"}", app->login_username_logged_out, old_password, app->change_password_logged_in);
  904. if (!flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/change-password/", auth_headers, payload))
  905. {
  906. FURI_LOG_E(TAG, "Failed to send post request to change password");
  907. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  908. return;
  909. }
  910. // Save the settings
  911. 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);
  912. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInProfile);
  913. }
  914. /**
  915. * @brief Callback when a user selects a menu item in the profile (logged in) screen.
  916. * @param context The context - FlipSocialApp object.
  917. * @param index The index of the selected item.
  918. * @return void
  919. */
  920. void flip_social_text_input_logged_in_profile_item_selected(void *context, uint32_t index)
  921. {
  922. FlipSocialApp *app = (FlipSocialApp *)context;
  923. if (!app)
  924. {
  925. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  926. return;
  927. }
  928. switch (index)
  929. {
  930. case 0: // Change Username
  931. // do nothing since username cannot be changed
  932. break;
  933. case 1: // Change Password
  934. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInChangePasswordInput);
  935. break;
  936. case 2: // Friends
  937. flipper_http_loading_task(flip_social_get_friends, flip_social_parse_json_friends, FlipSocialViewLoggedInFriendsSubmenu, FlipSocialViewLoggedInProfile, &app->view_dispatcher);
  938. break;
  939. default:
  940. FURI_LOG_E(TAG, "Unknown configuration item index");
  941. break;
  942. }
  943. }
  944. /**
  945. * @brief Callback when a user selects a menu item in the settings (logged in) screen.
  946. * @param context The context - FlipSocialApp object.
  947. * @param index The index of the selected item.
  948. * @return void
  949. */
  950. void flip_social_text_input_logged_in_settings_item_selected(void *context, uint32_t index)
  951. {
  952. FlipSocialApp *app = (FlipSocialApp *)context;
  953. if (!app)
  954. {
  955. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  956. return;
  957. }
  958. switch (index)
  959. {
  960. case 0: // About
  961. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsAbout);
  962. break;
  963. case 1: // Wifi
  964. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
  965. break;
  966. default:
  967. break;
  968. }
  969. }
  970. /**
  971. * @brief Text input callback for when the user finishes entering their message to send to the selected user choice (user choice messages view)
  972. * @param context The context - FlipSocialApp object.
  973. * @return void
  974. */
  975. void flip_social_logged_in_messages_user_choice_message_updated(void *context)
  976. {
  977. FlipSocialApp *app = (FlipSocialApp *)context;
  978. if (!app)
  979. {
  980. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  981. return;
  982. }
  983. // check if the message is empty
  984. if (app->message_user_choice_logged_in_temp_buffer_size == 0)
  985. {
  986. FURI_LOG_E(TAG, "Message is empty");
  987. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput);
  988. return;
  989. }
  990. // Store the entered message
  991. strncpy(app->message_user_choice_logged_in, app->message_user_choice_logged_in_temp_buffer, app->message_user_choice_logged_in_temp_buffer_size);
  992. // Ensure null-termination
  993. app->message_user_choice_logged_in[app->message_user_choice_logged_in_temp_buffer_size - 1] = '\0';
  994. // send post request to send message
  995. auth_headers_alloc();
  996. char url[128];
  997. char payload[256];
  998. snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
  999. snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_explore->usernames[flip_social_explore->index], app->message_user_choice_logged_in);
  1000. if (flipper_http_post_request_with_headers(url, auth_headers, payload)) // start the async request
  1001. {
  1002. furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
  1003. fhttp.state = RECEIVING;
  1004. }
  1005. else
  1006. {
  1007. FURI_LOG_E(TAG, "Failed to send post request to send message");
  1008. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1009. fhttp.state = ISSUE;
  1010. return;
  1011. }
  1012. while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
  1013. {
  1014. // Wait for the request to be received
  1015. furi_delay_ms(10);
  1016. }
  1017. furi_timer_stop(fhttp.get_timeout_timer);
  1018. // add user to the message list
  1019. 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]));
  1020. flip_social_message_users->count++;
  1021. // redraw submenu
  1022. flip_social_update_messages_submenu();
  1023. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
  1024. }
  1025. /**
  1026. * @brief Text input callback for when the user finishes entering their message to the selected user (messages view)
  1027. * @param context The context - FlipSocialApp object.
  1028. * @return void
  1029. */
  1030. void flip_social_logged_in_messages_new_message_updated(void *context)
  1031. {
  1032. FlipSocialApp *app = (FlipSocialApp *)context;
  1033. if (!app)
  1034. {
  1035. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1036. return;
  1037. }
  1038. // check if the message is empty
  1039. if (app->messages_new_message_logged_in_temp_buffer_size == 0)
  1040. {
  1041. FURI_LOG_E(TAG, "Message is empty");
  1042. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageInput);
  1043. return;
  1044. }
  1045. // Store the entered message
  1046. strncpy(app->messages_new_message_logged_in, app->messages_new_message_logged_in_temp_buffer, app->messages_new_message_logged_in_temp_buffer_size);
  1047. // Ensure null-termination
  1048. app->messages_new_message_logged_in[app->messages_new_message_logged_in_temp_buffer_size - 1] = '\0';
  1049. // send post request to send message
  1050. auth_headers_alloc();
  1051. char url[128];
  1052. char payload[256];
  1053. snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
  1054. snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_message_users->usernames[flip_social_message_users->index], app->messages_new_message_logged_in);
  1055. if (flipper_http_post_request_with_headers(url, auth_headers, payload)) // start the async request
  1056. {
  1057. furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
  1058. fhttp.state = RECEIVING;
  1059. }
  1060. else
  1061. {
  1062. FURI_LOG_E(TAG, "Failed to send post request to send message");
  1063. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1064. fhttp.state = ISSUE;
  1065. return;
  1066. }
  1067. while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
  1068. {
  1069. // Wait for the request to be received
  1070. furi_delay_ms(10);
  1071. }
  1072. furi_timer_stop(fhttp.get_timeout_timer);
  1073. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
  1074. }
  1075. static void flip_social_widget_set_text(char *message, Widget **widget)
  1076. {
  1077. if (widget == NULL)
  1078. {
  1079. FURI_LOG_E(TAG, "flip_social_set_widget_text - widget is NULL");
  1080. DEV_CRASH();
  1081. return;
  1082. }
  1083. if (message == NULL)
  1084. {
  1085. FURI_LOG_E(TAG, "flip_social_set_widget_text - message is NULL");
  1086. DEV_CRASH();
  1087. return;
  1088. }
  1089. widget_reset(*widget);
  1090. uint32_t message_length = strlen(message); // Length of the message
  1091. uint32_t i = 0; // Index tracker
  1092. uint32_t formatted_index = 0; // Tracker for where we are in the formatted message
  1093. char *formatted_message; // Buffer to hold the final formatted message
  1094. // Allocate buffer with double the message length plus one for safety
  1095. if (!easy_flipper_set_buffer(&formatted_message, message_length * 2 + 1))
  1096. {
  1097. return;
  1098. }
  1099. while (i < message_length)
  1100. {
  1101. uint32_t max_line_length = 31; // Maximum characters per line
  1102. uint32_t remaining_length = message_length - i; // Remaining characters
  1103. uint32_t line_length = (remaining_length < max_line_length) ? remaining_length : max_line_length;
  1104. // Check for newline character within the current segment
  1105. uint32_t newline_pos = i;
  1106. bool found_newline = false;
  1107. for (; newline_pos < i + line_length && newline_pos < message_length; newline_pos++)
  1108. {
  1109. if (message[newline_pos] == '\n')
  1110. {
  1111. found_newline = true;
  1112. break;
  1113. }
  1114. }
  1115. if (found_newline)
  1116. {
  1117. // If newline found, set line_length up to the newline
  1118. line_length = newline_pos - i;
  1119. }
  1120. // Temporary buffer to hold the current line
  1121. char line[32];
  1122. strncpy(line, message + i, line_length);
  1123. line[line_length] = '\0';
  1124. // If newline was found, skip it for the next iteration
  1125. if (found_newline)
  1126. {
  1127. i += line_length + 1; // +1 to skip the '\n' character
  1128. }
  1129. else
  1130. {
  1131. // Check if the line ends in the middle of a word and adjust accordingly
  1132. if (line_length == max_line_length && message[i + line_length] != '\0' && message[i + line_length] != ' ')
  1133. {
  1134. // Find the last space within the current line to avoid breaking a word
  1135. char *last_space = strrchr(line, ' ');
  1136. if (last_space != NULL)
  1137. {
  1138. // Adjust the line_length to avoid cutting the word
  1139. line_length = last_space - line;
  1140. line[line_length] = '\0'; // Null-terminate at the space
  1141. }
  1142. }
  1143. // Move the index forward by the determined line_length
  1144. i += line_length;
  1145. // Skip any spaces at the beginning of the next line
  1146. while (i < message_length && message[i] == ' ')
  1147. {
  1148. i++;
  1149. }
  1150. }
  1151. // Manually copy the fixed line into the formatted_message buffer
  1152. for (uint32_t j = 0; j < line_length; j++)
  1153. {
  1154. formatted_message[formatted_index++] = line[j];
  1155. }
  1156. // Add a newline character for line spacing
  1157. formatted_message[formatted_index++] = '\n';
  1158. }
  1159. // Null-terminate the formatted_message
  1160. formatted_message[formatted_index] = '\0';
  1161. // Add the formatted message to the widget
  1162. widget_add_text_scroll_element(*widget, 0, 0, 128, 64, formatted_message);
  1163. }
  1164. void flip_social_loader_draw_callback(Canvas *canvas, void *model)
  1165. {
  1166. if (!canvas || !model)
  1167. {
  1168. FURI_LOG_E(TAG, "flip_social_loader_draw_callback - canvas or model is NULL");
  1169. return;
  1170. }
  1171. SerialState http_state = fhttp.state;
  1172. DataLoaderModel *data_loader_model = (DataLoaderModel *)model;
  1173. DataState data_state = data_loader_model->data_state;
  1174. char *title = data_loader_model->title;
  1175. canvas_set_font(canvas, FontSecondary);
  1176. if (http_state == INACTIVE)
  1177. {
  1178. canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
  1179. canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
  1180. canvas_draw_str(canvas, 0, 32, "If your board is connected,");
  1181. canvas_draw_str(canvas, 0, 42, "make sure you have flashed");
  1182. canvas_draw_str(canvas, 0, 52, "your WiFi Devboard with the");
  1183. canvas_draw_str(canvas, 0, 62, "latest FlipperHTTP flash.");
  1184. return;
  1185. }
  1186. if (data_state == DataStateError || data_state == DataStateParseError)
  1187. {
  1188. flip_social_request_error_draw(canvas);
  1189. return;
  1190. }
  1191. canvas_draw_str(canvas, 0, 7, title);
  1192. canvas_draw_str(canvas, 0, 17, "Loading...");
  1193. if (data_state == DataStateInitial)
  1194. {
  1195. return;
  1196. }
  1197. if (http_state == SENDING)
  1198. {
  1199. canvas_draw_str(canvas, 0, 27, "Sending...");
  1200. return;
  1201. }
  1202. if (http_state == RECEIVING || data_state == DataStateRequested)
  1203. {
  1204. canvas_draw_str(canvas, 0, 27, "Receiving...");
  1205. return;
  1206. }
  1207. if (http_state == IDLE && data_state == DataStateReceived)
  1208. {
  1209. canvas_draw_str(canvas, 0, 27, "Processing...");
  1210. return;
  1211. }
  1212. if (http_state == IDLE && data_state == DataStateParsed)
  1213. {
  1214. canvas_draw_str(canvas, 0, 27, "Processed...");
  1215. return;
  1216. }
  1217. }
  1218. static void flip_social_loader_process_callback(void *context)
  1219. {
  1220. if (context == NULL)
  1221. {
  1222. FURI_LOG_E(TAG, "flip_social_loader_process_callback - context is NULL");
  1223. DEV_CRASH();
  1224. return;
  1225. }
  1226. FlipSocialApp *app = (FlipSocialApp *)context;
  1227. View *view = app->view_loader;
  1228. DataState current_data_state;
  1229. with_view_model(view, DataLoaderModel * model, { current_data_state = model->data_state; }, false);
  1230. if (current_data_state == DataStateInitial)
  1231. {
  1232. with_view_model(
  1233. view,
  1234. DataLoaderModel * model,
  1235. {
  1236. model->data_state = DataStateRequested;
  1237. DataLoaderFetch fetch = model->fetcher;
  1238. if (fetch == NULL)
  1239. {
  1240. FURI_LOG_E(TAG, "Model doesn't have Fetch function assigned.");
  1241. model->data_state = DataStateError;
  1242. return;
  1243. }
  1244. // Clear any previous responses
  1245. strncpy(fhttp.last_response, "", 1);
  1246. bool request_status = fetch(model);
  1247. if (!request_status)
  1248. {
  1249. model->data_state = DataStateError;
  1250. }
  1251. },
  1252. true);
  1253. }
  1254. else if (current_data_state == DataStateRequested || current_data_state == DataStateError)
  1255. {
  1256. if (fhttp.state == IDLE && fhttp.last_response != NULL)
  1257. {
  1258. if (strstr(fhttp.last_response, "[PONG]") != NULL)
  1259. {
  1260. FURI_LOG_DEV(TAG, "PONG received.");
  1261. }
  1262. else if (strncmp(fhttp.last_response, "[SUCCESS]", 9) == 0)
  1263. {
  1264. FURI_LOG_DEV(TAG, "SUCCESS received. %s", fhttp.last_response ? fhttp.last_response : "NULL");
  1265. }
  1266. else if (strncmp(fhttp.last_response, "[ERROR]", 9) == 0)
  1267. {
  1268. FURI_LOG_DEV(TAG, "ERROR received. %s", fhttp.last_response ? fhttp.last_response : "NULL");
  1269. }
  1270. else if (strlen(fhttp.last_response) == 0)
  1271. {
  1272. // Still waiting on response
  1273. }
  1274. else
  1275. {
  1276. with_view_model(view, DataLoaderModel * model, { model->data_state = DataStateReceived; }, true);
  1277. }
  1278. }
  1279. else if (fhttp.state == SENDING || fhttp.state == RECEIVING)
  1280. {
  1281. // continue waiting
  1282. }
  1283. else if (fhttp.state == INACTIVE)
  1284. {
  1285. // inactive. try again
  1286. }
  1287. else if (fhttp.state == ISSUE)
  1288. {
  1289. with_view_model(view, DataLoaderModel * model, { model->data_state = DataStateError; }, true);
  1290. }
  1291. else
  1292. {
  1293. FURI_LOG_DEV(TAG, "Unexpected state: %d lastresp: %s", fhttp.state, fhttp.last_response ? fhttp.last_response : "NULL");
  1294. DEV_CRASH();
  1295. }
  1296. }
  1297. else if (current_data_state == DataStateReceived)
  1298. {
  1299. with_view_model(
  1300. view,
  1301. DataLoaderModel * model,
  1302. {
  1303. char *data_text;
  1304. if (model->parser == NULL)
  1305. {
  1306. data_text = NULL;
  1307. FURI_LOG_DEV(TAG, "Parser is NULL");
  1308. DEV_CRASH();
  1309. }
  1310. else
  1311. {
  1312. data_text = model->parser(model);
  1313. }
  1314. FURI_LOG_DEV(TAG, "Parsed data: %s\r\ntext: %s", fhttp.last_response ? fhttp.last_response : "NULL", data_text ? data_text : "NULL");
  1315. model->data_text = data_text;
  1316. if (data_text == NULL)
  1317. {
  1318. model->data_state = DataStateParseError;
  1319. }
  1320. else
  1321. {
  1322. model->data_state = DataStateParsed;
  1323. }
  1324. },
  1325. true);
  1326. }
  1327. else if (current_data_state == DataStateParsed)
  1328. {
  1329. with_view_model(
  1330. view,
  1331. DataLoaderModel * model,
  1332. {
  1333. if (++model->request_index < model->request_count)
  1334. {
  1335. model->data_state = DataStateInitial;
  1336. }
  1337. else
  1338. {
  1339. flip_social_widget_set_text(model->data_text != NULL ? model->data_text : "Empty result", &app_instance->widget_result);
  1340. if (model->data_text != NULL)
  1341. {
  1342. free(model->data_text);
  1343. model->data_text = NULL;
  1344. }
  1345. view_set_previous_callback(widget_get_view(app_instance->widget_result), model->back_callback);
  1346. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewWidgetResult);
  1347. }
  1348. },
  1349. true);
  1350. }
  1351. }
  1352. static void flip_social_loader_timer_callback(void *context)
  1353. {
  1354. if (context == NULL)
  1355. {
  1356. FURI_LOG_E(TAG, "flip_social_loader_timer_callback - context is NULL");
  1357. DEV_CRASH();
  1358. return;
  1359. }
  1360. FlipSocialApp *app = (FlipSocialApp *)context;
  1361. view_dispatcher_send_custom_event(app->view_dispatcher, FlipSocialCustomEventProcess);
  1362. }
  1363. static void flip_social_loader_on_enter(void *context)
  1364. {
  1365. if (context == NULL)
  1366. {
  1367. FURI_LOG_E(TAG, "flip_social_loader_on_enter - context is NULL");
  1368. DEV_CRASH();
  1369. return;
  1370. }
  1371. FlipSocialApp *app = (FlipSocialApp *)context;
  1372. View *view = app->view_loader;
  1373. with_view_model(
  1374. view,
  1375. DataLoaderModel * model,
  1376. {
  1377. view_set_previous_callback(view, model->back_callback);
  1378. if (model->timer == NULL)
  1379. {
  1380. model->timer = furi_timer_alloc(flip_social_loader_timer_callback, FuriTimerTypePeriodic, app);
  1381. }
  1382. furi_timer_start(model->timer, 250);
  1383. },
  1384. true);
  1385. }
  1386. static void flip_social_loader_on_exit(void *context)
  1387. {
  1388. if (context == NULL)
  1389. {
  1390. FURI_LOG_E(TAG, "flip_social_loader_on_exit - context is NULL");
  1391. DEV_CRASH();
  1392. return;
  1393. }
  1394. FlipSocialApp *app = (FlipSocialApp *)context;
  1395. View *view = app->view_loader;
  1396. with_view_model(
  1397. view,
  1398. DataLoaderModel * model,
  1399. {
  1400. if (model->timer)
  1401. {
  1402. furi_timer_stop(model->timer);
  1403. }
  1404. },
  1405. false);
  1406. }
  1407. void flip_social_loader_init(View *view)
  1408. {
  1409. if (view == NULL)
  1410. {
  1411. FURI_LOG_E(TAG, "flip_social_loader_init - view is NULL");
  1412. DEV_CRASH();
  1413. return;
  1414. }
  1415. view_allocate_model(view, ViewModelTypeLocking, sizeof(DataLoaderModel));
  1416. view_set_enter_callback(view, flip_social_loader_on_enter);
  1417. view_set_exit_callback(view, flip_social_loader_on_exit);
  1418. }
  1419. void flip_social_loader_free_model(View *view)
  1420. {
  1421. if (view == NULL)
  1422. {
  1423. FURI_LOG_E(TAG, "flip_social_loader_free_model - view is NULL");
  1424. DEV_CRASH();
  1425. return;
  1426. }
  1427. with_view_model(
  1428. view,
  1429. DataLoaderModel * model,
  1430. {
  1431. if (model->timer)
  1432. {
  1433. furi_timer_free(model->timer);
  1434. model->timer = NULL;
  1435. }
  1436. if (model->parser_context)
  1437. {
  1438. free(model->parser_context);
  1439. model->parser_context = NULL;
  1440. }
  1441. },
  1442. false);
  1443. }
  1444. bool flip_social_custom_event_callback(void *context, uint32_t index)
  1445. {
  1446. if (context == NULL)
  1447. {
  1448. FURI_LOG_E(TAG, "flip_social_custom_event_callback - context is NULL");
  1449. DEV_CRASH();
  1450. return false;
  1451. }
  1452. switch (index)
  1453. {
  1454. case FlipSocialCustomEventProcess:
  1455. flip_social_loader_process_callback(context);
  1456. return true;
  1457. default:
  1458. FURI_LOG_DEV(TAG, "flip_social_custom_event_callback. Unknown index: %ld", index);
  1459. return false;
  1460. }
  1461. }
  1462. void flip_social_generic_switch_to_view(FlipSocialApp *app, char *title, DataLoaderFetch fetcher, DataLoaderParser parser, size_t request_count, ViewNavigationCallback back, uint32_t view_id)
  1463. {
  1464. if (app == NULL)
  1465. {
  1466. FURI_LOG_E(TAG, "flip_social_generic_switch_to_view - app is NULL");
  1467. DEV_CRASH();
  1468. return;
  1469. }
  1470. View *view = app->view_loader;
  1471. if (view == NULL)
  1472. {
  1473. FURI_LOG_E(TAG, "flip_social_generic_switch_to_view - view is NULL");
  1474. DEV_CRASH();
  1475. return;
  1476. }
  1477. with_view_model(
  1478. view,
  1479. DataLoaderModel * model,
  1480. {
  1481. model->title = title;
  1482. model->fetcher = fetcher;
  1483. model->parser = parser;
  1484. model->request_index = 0;
  1485. model->request_count = request_count;
  1486. model->back_callback = back;
  1487. model->data_state = DataStateInitial;
  1488. model->data_text = NULL;
  1489. },
  1490. true);
  1491. view_dispatcher_switch_to_view(app->view_dispatcher, view_id);
  1492. }