flip_social_callback.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188
  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 bool about_widget_alloc(bool is_logged_in)
  12. {
  13. if (!is_logged_in)
  14. {
  15. if (!app_instance->widget_logged_out_about)
  16. {
  17. return easy_flipper_set_widget(&app_instance->widget_logged_out_about, FlipSocialViewLoggedOutAbout, "Welcome to FlipSocial\n---\nThe social media app for\nFlipper Zero, created by\nJBlanked: www.flipsocial.net\n---\nPress BACK to return.", flip_social_callback_to_submenu_logged_out, &app_instance->view_dispatcher);
  18. }
  19. }
  20. else
  21. {
  22. if (!app_instance->widget_logged_in_about)
  23. {
  24. return easy_flipper_set_widget(&app_instance->widget_logged_in_about, FlipSocialViewLoggedInSettingsAbout, "Welcome to FlipSocial\n---\nThe social media app for\nFlipper Zero, created by\nJBlanked: www.flipsocial.net\n---\nPress BACK to return.", flip_social_callback_to_settings_logged_in, &app_instance->view_dispatcher);
  25. }
  26. }
  27. return true;
  28. }
  29. static void free_about_widget(bool is_logged_in)
  30. {
  31. if (is_logged_in && app_instance->widget_logged_in_about)
  32. {
  33. widget_free(app_instance->widget_logged_in_about);
  34. app_instance->widget_logged_in_about = NULL;
  35. view_dispatcher_remove_view(app_instance->view_dispatcher, FlipSocialViewLoggedInSettingsAbout);
  36. }
  37. if (!is_logged_in && app_instance->widget_logged_out_about)
  38. {
  39. widget_free(app_instance->widget_logged_out_about);
  40. app_instance->widget_logged_out_about = NULL;
  41. view_dispatcher_remove_view(app_instance->view_dispatcher, FlipSocialViewLoggedOutAbout);
  42. }
  43. }
  44. static bool pre_saved_messages_alloc(void)
  45. {
  46. if (!app_instance)
  47. {
  48. return false;
  49. }
  50. if (!app_instance->submenu_compose)
  51. {
  52. if (!easy_flipper_set_submenu(&app_instance->submenu_compose, FlipSocialViewLoggedInCompose, "Create A Post", flip_social_callback_to_submenu_logged_in, &app_instance->view_dispatcher))
  53. {
  54. return false;
  55. }
  56. submenu_reset(app_instance->submenu_compose);
  57. submenu_add_item(app_instance->submenu_compose, "Add Pre-Save", FlipSocialSubmenuComposeIndexAddPreSave, flip_social_callback_submenu_choices, app_instance);
  58. // load the playlist
  59. if (load_playlist(&app_instance->pre_saved_messages))
  60. {
  61. // Update the playlist submenu
  62. for (uint32_t i = 0; i < app_instance->pre_saved_messages.count; i++)
  63. {
  64. if (app_instance->pre_saved_messages.messages[i])
  65. {
  66. submenu_add_item(app_instance->submenu_compose, app_instance->pre_saved_messages.messages[i], FlipSocialSubemnuComposeIndexStartIndex + i, flip_social_callback_submenu_choices, app_instance);
  67. }
  68. }
  69. }
  70. }
  71. return true;
  72. }
  73. static void free_pre_saved_messages(void)
  74. {
  75. if (app_instance->submenu_compose)
  76. {
  77. submenu_free(app_instance->submenu_compose);
  78. app_instance->submenu_compose = NULL;
  79. view_dispatcher_remove_view(app_instance->view_dispatcher, FlipSocialViewLoggedInCompose);
  80. }
  81. for (uint32_t i = 0; i < app_instance->pre_saved_messages.count; i++)
  82. {
  83. if (app_instance->pre_saved_messages.messages[i])
  84. {
  85. free(app_instance->pre_saved_messages.messages[i]);
  86. app_instance->pre_saved_messages.messages[i] = NULL;
  87. }
  88. }
  89. }
  90. static void flip_social_free_friends(void)
  91. {
  92. if (!flip_social_friends)
  93. {
  94. return;
  95. }
  96. free(flip_social_friends);
  97. flip_social_friends = NULL;
  98. if (app_instance->submenu_friends)
  99. {
  100. submenu_free(app_instance->submenu_friends);
  101. app_instance->submenu_friends = NULL;
  102. view_dispatcher_remove_view(app_instance->view_dispatcher, FlipSocialViewLoggedInFriendsSubmenu);
  103. }
  104. }
  105. void flip_social_request_error_draw(Canvas *canvas)
  106. {
  107. if (canvas == NULL)
  108. {
  109. FURI_LOG_E(TAG, "flip_social_request_error_draw - canvas is NULL");
  110. DEV_CRASH();
  111. return;
  112. }
  113. if (fhttp.last_response != NULL)
  114. {
  115. if (strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL)
  116. {
  117. canvas_clear(canvas);
  118. canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
  119. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  120. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  121. }
  122. else if (strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL)
  123. {
  124. canvas_clear(canvas);
  125. canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
  126. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  127. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  128. }
  129. else if (strstr(fhttp.last_response, "[ERROR] GET request failed or returned empty data.") != NULL)
  130. {
  131. canvas_clear(canvas);
  132. canvas_draw_str(canvas, 0, 10, "[ERROR] WiFi error.");
  133. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  134. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  135. }
  136. else if (strstr(fhttp.last_response, "[PONG]") != NULL)
  137. {
  138. canvas_clear(canvas);
  139. canvas_draw_str(canvas, 0, 10, "[STATUS]Connecting to AP...");
  140. }
  141. else
  142. {
  143. canvas_clear(canvas);
  144. FURI_LOG_E(TAG, "Received an error: %s", fhttp.last_response);
  145. canvas_draw_str(canvas, 0, 10, "[ERROR] Unusual error...");
  146. canvas_draw_str(canvas, 0, 60, "Press BACK and retry.");
  147. }
  148. }
  149. else
  150. {
  151. canvas_clear(canvas);
  152. canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
  153. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  154. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  155. }
  156. }
  157. static bool flip_social_login_fetch(DataLoaderModel *model)
  158. {
  159. UNUSED(model);
  160. if (!app_instance->login_username_logged_out || !app_instance->login_password_logged_out || strlen(app_instance->login_username_logged_out) == 0 || strlen(app_instance->login_password_logged_out) == 0)
  161. {
  162. return false;
  163. }
  164. char buffer[256];
  165. snprintf(buffer, sizeof(buffer), "{\"username\":\"%s\",\"password\":\"%s\"}", app_instance->login_username_logged_out, app_instance->login_password_logged_out);
  166. auth_headers_alloc();
  167. if (flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/login/", auth_headers, buffer))
  168. {
  169. fhttp.state = RECEIVING;
  170. return true;
  171. }
  172. else
  173. {
  174. fhttp.state = ISSUE;
  175. return false;
  176. }
  177. }
  178. static char *flip_social_login_parse(DataLoaderModel *model)
  179. {
  180. UNUSED(model);
  181. // read response
  182. if (strstr(fhttp.last_response, "[SUCCESS]") != NULL || strstr(fhttp.last_response, "User found") != NULL)
  183. {
  184. app_instance->is_logged_in = "true";
  185. // set the logged_in_username and change_password_logged_in
  186. if (app_instance->login_username_logged_out)
  187. {
  188. strcpy(app_instance->login_username_logged_in, app_instance->login_username_logged_out);
  189. }
  190. if (app_instance->login_password_logged_out)
  191. {
  192. strcpy(app_instance->change_password_logged_in, app_instance->login_password_logged_out);
  193. }
  194. 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);
  195. // send user to the logged in submenu
  196. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewLoggedInSubmenu);
  197. return "Login successful!";
  198. }
  199. else if (strstr(fhttp.last_response, "User not found") != NULL)
  200. {
  201. return "Account not found...";
  202. }
  203. else
  204. {
  205. return "Failed to login...";
  206. }
  207. }
  208. static void flip_social_login_switch_to_view(FlipSocialApp *app)
  209. {
  210. flip_social_generic_switch_to_view(app, "Logging in...", flip_social_login_fetch, flip_social_login_parse, 1, flip_social_callback_to_login_logged_out, FlipSocialViewLoader);
  211. }
  212. static bool flip_social_register_fetch(DataLoaderModel *model)
  213. {
  214. UNUSED(model);
  215. // check if the username and password are valid
  216. if (!app_instance->register_username_logged_out || !app_instance->register_password_logged_out || strlen(app_instance->register_username_logged_out) == 0 || strlen(app_instance->register_password_logged_out) == 0)
  217. {
  218. FURI_LOG_E(TAG, "Username or password is NULL");
  219. return false;
  220. }
  221. // check if both passwords match
  222. if (strcmp(app_instance->register_password_logged_out, app_instance->register_password_2_logged_out) != 0)
  223. {
  224. FURI_LOG_E(TAG, "Passwords do not match");
  225. return false;
  226. }
  227. char buffer[128];
  228. snprintf(buffer, sizeof(buffer), "{\"username\":\"%s\",\"password\":\"%s\"}", app_instance->register_username_logged_out, app_instance->register_password_logged_out);
  229. if (flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/register/", "{\"Content-Type\":\"application/json\"}", buffer))
  230. {
  231. // Set the state to RECEIVING to ensure we continue to see the receiving message
  232. fhttp.state = RECEIVING;
  233. return true;
  234. }
  235. else
  236. {
  237. fhttp.state = ISSUE;
  238. return false;
  239. }
  240. }
  241. static char *flip_social_register_parse(DataLoaderModel *model)
  242. {
  243. UNUSED(model);
  244. // read response
  245. if (fhttp.last_response != NULL && (strstr(fhttp.last_response, "[SUCCESS]") != NULL || strstr(fhttp.last_response, "User created") != NULL))
  246. {
  247. // set the login credentials
  248. if (app_instance->login_username_logged_out)
  249. {
  250. app_instance->login_username_logged_out = app_instance->register_username_logged_out;
  251. }
  252. if (app_instance->login_password_logged_out)
  253. {
  254. app_instance->login_password_logged_out = app_instance->register_password_logged_out;
  255. app_instance->change_password_logged_in = app_instance->register_password_logged_out;
  256. }
  257. if (app_instance->login_username_logged_in)
  258. {
  259. app_instance->login_username_logged_in = app_instance->register_username_logged_out;
  260. }
  261. app_instance->is_logged_in = "true";
  262. // update header credentials
  263. auth_headers_alloc();
  264. // save the credentials
  265. 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);
  266. // send user to the logged in submenu
  267. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewLoggedInSubmenu);
  268. return "Registration successful!\nWelcome to FlipSocial!";
  269. }
  270. else if (strstr(fhttp.last_response, "Username or password not provided") != NULL)
  271. {
  272. return "Please enter your credentials.\nPress BACK to return.";
  273. }
  274. else if (strstr(fhttp.last_response, "User already exists") != NULL || strstr(fhttp.last_response, "Multiple users found") != NULL)
  275. {
  276. return "Registration failed...\nUsername already exists.\nPress BACK to return.";
  277. }
  278. else
  279. {
  280. return "Registration failed...\nUpdate your credentials.\nPress BACK to return.";
  281. }
  282. }
  283. static void flip_social_register_switch_to_view(FlipSocialApp *app)
  284. {
  285. flip_social_generic_switch_to_view(app, "Registering...", flip_social_register_fetch, flip_social_register_parse, 1, flip_social_callback_to_register_logged_out, FlipSocialViewLoader);
  286. }
  287. /**
  288. * @brief Navigation callback to go back to the submenu Logged out.
  289. * @param context The context - unused
  290. * @return next view id (FlipSocialViewLoggedOutSubmenu)
  291. */
  292. uint32_t flip_social_callback_to_submenu_logged_out(void *context)
  293. {
  294. UNUSED(context);
  295. return FlipSocialViewLoggedOutSubmenu;
  296. }
  297. static void flip_social_free_explore_dialog()
  298. {
  299. if (app_instance->dialog_explore)
  300. {
  301. dialog_ex_free(app_instance->dialog_explore);
  302. app_instance->dialog_explore = NULL;
  303. view_dispatcher_remove_view(app_instance->view_dispatcher, FlipSocialViewExploreDialog);
  304. }
  305. }
  306. static void flip_social_free_friends_dialog()
  307. {
  308. if (app_instance->dialog_friends)
  309. {
  310. dialog_ex_free(app_instance->dialog_friends);
  311. app_instance->dialog_friends = NULL;
  312. view_dispatcher_remove_view(app_instance->view_dispatcher, FlipSocialViewFriendsDialog);
  313. }
  314. }
  315. static void flip_social_free_messages_dialog()
  316. {
  317. if (app_instance->dialog_messages)
  318. {
  319. dialog_ex_free(app_instance->dialog_messages);
  320. app_instance->dialog_messages = NULL;
  321. view_dispatcher_remove_view(app_instance->view_dispatcher, FlipSocialViewMessagesDialog);
  322. return;
  323. }
  324. }
  325. static void flip_social_free_compose_dialog()
  326. {
  327. if (app_instance->dialog_compose)
  328. {
  329. dialog_ex_free(app_instance->dialog_compose);
  330. app_instance->dialog_compose = NULL;
  331. view_dispatcher_remove_view(app_instance->view_dispatcher, FlipSocialViewComposeDialog);
  332. }
  333. }
  334. /**
  335. * @brief Navigation callback to go back to the submenu Logged in.
  336. * @param context The context - unused
  337. * @return next view id (FlipSocialViewLoggedInSubmenu)
  338. */
  339. uint32_t flip_social_callback_to_submenu_logged_in(void *context)
  340. {
  341. UNUSED(context);
  342. free_about_widget(false);
  343. //
  344. flip_social_free_friends();
  345. flip_social_free_message_users();
  346. flip_feed_info_free();
  347. if (flip_feed_item)
  348. {
  349. free(flip_feed_item);
  350. flip_feed_item = NULL;
  351. }
  352. // free the about widget if it exists
  353. free_about_widget(true);
  354. flip_social_free_explore_dialog();
  355. flip_social_free_friends_dialog();
  356. flip_social_free_messages_dialog();
  357. flip_social_free_compose_dialog();
  358. return FlipSocialViewLoggedInSubmenu;
  359. }
  360. /**
  361. * @brief Navigation callback to bring the user back to the (Logged out) Login screen
  362. * @param context The context - unused
  363. * @return next view id (FlipSocialViewLoggedOutLogin)
  364. */
  365. uint32_t flip_social_callback_to_login_logged_out(void *context)
  366. {
  367. UNUSED(context);
  368. flip_social_sent_login_request = false;
  369. flip_social_login_success = false;
  370. return FlipSocialViewLoggedOutLogin;
  371. }
  372. /**
  373. * @brief Navigation callback to bring the user back to the (Logged out) Register screen
  374. * @param context The context - unused
  375. * @return next view id (FlipSocialViewLoggedOutRegister)
  376. */
  377. uint32_t flip_social_callback_to_register_logged_out(void *context)
  378. {
  379. UNUSED(context);
  380. flip_social_sent_register_request = false;
  381. flip_social_register_success = false;
  382. return FlipSocialViewLoggedOutRegister;
  383. }
  384. /**
  385. * @brief Navigation callback to bring the user back to the (Logged out) Wifi Settings screen
  386. * @param context The context - unused
  387. * @return next view id (FlipSocialViewLoggedOutWifiSettings)
  388. */
  389. uint32_t flip_social_callback_to_wifi_settings_logged_out(void *context)
  390. {
  391. UNUSED(context);
  392. return FlipSocialViewLoggedOutWifiSettings;
  393. }
  394. /**
  395. * @brief Navigation callback to bring the user back to the (Logged in) Wifi Settings screen
  396. * @param context The context - unused
  397. * @return next view id (FlipSocialViewLoggedInSettingsWifi)
  398. */
  399. uint32_t flip_social_callback_to_wifi_settings_logged_in(void *context)
  400. {
  401. UNUSED(context);
  402. return FlipSocialViewLoggedInSettingsWifi;
  403. }
  404. /**
  405. * @brief Navigation callback to bring the user back to the (Logged in) Settings screen
  406. * @param context The context - unused
  407. * @return next view id (FlipSocialViewLoggedInSettingsWifi)
  408. */
  409. uint32_t flip_social_callback_to_settings_logged_in(void *context)
  410. {
  411. UNUSED(context);
  412. return FlipSocialViewLoggedInSettings;
  413. }
  414. /**
  415. * @brief Navigation callback to bring the user back to the (Logged in) Compose screen
  416. * @param context The context - unused
  417. * @return next view id (FlipSocialViewLoggedInCompose)
  418. */
  419. uint32_t flip_social_callback_to_compose_logged_in(void *context)
  420. {
  421. UNUSED(context);
  422. return FlipSocialViewLoggedInCompose;
  423. }
  424. /**
  425. * @brief Navigation callback to bring the user back to the (Logged in) Profile screen
  426. * @param context The context - unused
  427. * @return next view id (FlipSocialViewLoggedInProfile)
  428. */
  429. uint32_t flip_social_callback_to_profile_logged_in(void *context)
  430. {
  431. UNUSED(context);
  432. return FlipSocialViewLoggedInProfile;
  433. }
  434. /**
  435. * @brief Navigation callback to bring the user back to the Explore submenu
  436. * @param context The context - unused
  437. * @return next view id (FlipSocialViewLoggedInExploreSubmenu)
  438. */
  439. uint32_t flip_social_callback_to_explore_logged_in(void *context)
  440. {
  441. UNUSED(context);
  442. flip_social_dialog_stop = false;
  443. last_explore_response = "";
  444. flip_social_dialog_shown = false;
  445. if (flip_social_explore)
  446. {
  447. flip_social_explore->index = 0;
  448. }
  449. action = ActionNone;
  450. return FlipSocialViewLoggedInExploreSubmenu;
  451. }
  452. /**
  453. * @brief Navigation callback to bring the user back to the Friends submenu
  454. * @param context The context - unused
  455. * @return next view id (FlipSocialViewLoggedInFriendsSubmenu)
  456. */
  457. uint32_t flip_social_callback_to_friends_logged_in(void *context)
  458. {
  459. UNUSED(context);
  460. flip_social_dialog_stop = false;
  461. last_explore_response = "";
  462. flip_social_dialog_shown = false;
  463. flip_social_friends->index = 0;
  464. action = ActionNone;
  465. return FlipSocialViewLoggedInFriendsSubmenu;
  466. }
  467. /**
  468. * @brief Navigation callback to bring the user back to the Messages submenu
  469. * @param context The context - unused
  470. * @return next view id (FlipSocialViewLoggedInMessagesSubmenu)
  471. */
  472. uint32_t flip_social_callback_to_messages_logged_in(void *context)
  473. {
  474. UNUSED(context);
  475. return FlipSocialViewLoggedInMessagesSubmenu;
  476. }
  477. /**
  478. * @brief Navigation callback to bring the user back to the User Choices screen
  479. * @param context The context - unused
  480. * @return next view id (FlipSocialViewLoggedInMessagesUserChoices)
  481. */
  482. uint32_t flip_social_callback_to_messages_user_choices(void *context)
  483. {
  484. UNUSED(context);
  485. return FlipSocialViewLoggedInMessagesUserChoices;
  486. }
  487. static void free_flip_social_group()
  488. {
  489. flip_social_free_messages();
  490. flip_social_free_explore();
  491. }
  492. /**
  493. * @brief Navigation callback for exiting the application
  494. * @param context The context - unused
  495. * @return next view id (VIEW_NONE to exit the app)
  496. */
  497. uint32_t flip_social_callback_exit_app(void *context)
  498. {
  499. // Exit the application
  500. UNUSED(context);
  501. free_flip_social_group();
  502. free_pre_saved_messages();
  503. return VIEW_NONE; // Return VIEW_NONE to exit the app
  504. }
  505. static void explore_dialog_callback(DialogExResult result, void *context)
  506. {
  507. furi_assert(context);
  508. FlipSocialApp *app = (FlipSocialApp *)context;
  509. if (result == DialogExResultLeft) // Remove
  510. {
  511. // remove friend
  512. char remove_payload[128];
  513. snprintf(remove_payload, sizeof(remove_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_explore->usernames[flip_social_explore->index]);
  514. auth_headers_alloc();
  515. flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/remove-friend/", auth_headers, remove_payload);
  516. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInExploreSubmenu);
  517. flip_social_free_explore_dialog();
  518. }
  519. else if (result == DialogExResultRight)
  520. {
  521. // add friend
  522. char add_payload[128];
  523. snprintf(add_payload, sizeof(add_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_explore->usernames[flip_social_explore->index]);
  524. auth_headers_alloc();
  525. flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/add-friend/", auth_headers, add_payload);
  526. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInExploreSubmenu);
  527. flip_social_free_explore_dialog();
  528. }
  529. }
  530. static void friends_dialog_callback(DialogExResult result, void *context)
  531. {
  532. furi_assert(context);
  533. FlipSocialApp *app = (FlipSocialApp *)context;
  534. if (result == DialogExResultLeft) // Remove
  535. {
  536. // remove friend
  537. char remove_payload[128];
  538. snprintf(remove_payload, sizeof(remove_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_friends->usernames[flip_social_friends->index]);
  539. auth_headers_alloc();
  540. flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/remove-friend/", auth_headers, remove_payload);
  541. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFriendsSubmenu);
  542. flip_social_free_friends_dialog();
  543. }
  544. }
  545. static void messages_dialog_callback(DialogExResult result, void *context)
  546. {
  547. furi_assert(context);
  548. FlipSocialApp *app = (FlipSocialApp *)context;
  549. if (result == DialogExResultLeft) // Previous message
  550. {
  551. if (flip_social_messages->index > 0)
  552. {
  553. flip_social_messages->index--;
  554. dialog_ex_reset(app->dialog_messages);
  555. dialog_ex_set_header(app->dialog_messages, flip_social_messages->usernames[flip_social_messages->index], 0, 0, AlignLeft, AlignTop);
  556. dialog_ex_set_text(app->dialog_messages, flip_social_messages->messages[flip_social_messages->index], 0, 10, AlignLeft, AlignTop);
  557. if (flip_social_messages->index != 0)
  558. {
  559. dialog_ex_set_left_button_text(app->dialog_messages, "Prev");
  560. }
  561. dialog_ex_set_right_button_text(app->dialog_messages, "Next");
  562. dialog_ex_set_center_button_text(app->dialog_messages, "Create");
  563. // switch view, free dialog, re-alloc dialog, switch back to dialog
  564. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
  565. flip_social_free_messages_dialog();
  566. messages_dialog_alloc(false);
  567. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewMessagesDialog);
  568. }
  569. }
  570. else if (result == DialogExResultRight) // Next message
  571. {
  572. if (flip_social_messages->index < flip_social_messages->count - 1)
  573. {
  574. flip_social_messages->index++;
  575. dialog_ex_reset(app->dialog_messages);
  576. dialog_ex_set_header(app->dialog_messages, flip_social_messages->usernames[flip_social_messages->index], 0, 0, AlignLeft, AlignTop);
  577. dialog_ex_set_text(app->dialog_messages, flip_social_messages->messages[flip_social_messages->index], 0, 10, AlignLeft, AlignTop);
  578. dialog_ex_set_left_button_text(app->dialog_messages, "Prev");
  579. if (flip_social_messages->index != flip_social_messages->count - 1)
  580. {
  581. dialog_ex_set_right_button_text(app->dialog_messages, "Next");
  582. }
  583. dialog_ex_set_center_button_text(app->dialog_messages, "Create");
  584. // switch view, free dialog, re-alloc dialog, switch back to dialog
  585. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
  586. flip_social_free_messages_dialog();
  587. messages_dialog_alloc(false);
  588. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewMessagesDialog);
  589. }
  590. }
  591. else if (result == DialogExResultCenter) // new message
  592. {
  593. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageInput);
  594. }
  595. }
  596. bool messages_dialog_alloc(bool free_first)
  597. {
  598. if (free_first)
  599. {
  600. flip_social_free_messages_dialog();
  601. }
  602. if (!app_instance->dialog_messages)
  603. {
  604. if (!easy_flipper_set_dialog_ex(
  605. &app_instance->dialog_messages,
  606. FlipSocialViewMessagesDialog,
  607. flip_social_messages->usernames[flip_social_messages->index],
  608. 0,
  609. 0,
  610. flip_social_messages->messages[flip_social_messages->index],
  611. 0,
  612. 10,
  613. flip_social_messages->index != 0 ? "Prev" : NULL,
  614. flip_social_messages->index != flip_social_messages->count - 1 ? "Next" : NULL,
  615. "Create",
  616. messages_dialog_callback,
  617. flip_social_callback_to_messages_logged_in,
  618. &app_instance->view_dispatcher,
  619. app_instance))
  620. {
  621. return false;
  622. }
  623. return true;
  624. }
  625. return false;
  626. }
  627. static void compose_dialog_callback(DialogExResult result, void *context)
  628. {
  629. furi_assert(context);
  630. FlipSocialApp *app = (FlipSocialApp *)context;
  631. if (result == DialogExResultLeft) // Delete
  632. {
  633. // delete message
  634. app->pre_saved_messages.messages[app_instance->pre_saved_messages.index] = NULL;
  635. for (uint32_t i = app->pre_saved_messages.index; i < app->pre_saved_messages.count - 1; i++)
  636. {
  637. app->pre_saved_messages.messages[i] = app->pre_saved_messages.messages[i + 1];
  638. }
  639. app->pre_saved_messages.count--;
  640. // add the item to the submenu
  641. submenu_reset(app_instance->submenu_compose);
  642. submenu_add_item(app_instance->submenu_compose, "Add Pre-Save", FlipSocialSubmenuComposeIndexAddPreSave, flip_social_callback_submenu_choices, app);
  643. for (uint32_t i = 0; i < app->pre_saved_messages.count; i++)
  644. {
  645. submenu_add_item(app_instance->submenu_compose, app->pre_saved_messages.messages[i], FlipSocialSubemnuComposeIndexStartIndex + i, flip_social_callback_submenu_choices, app);
  646. }
  647. // save playlist
  648. save_playlist(&app_instance->pre_saved_messages);
  649. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  650. flip_social_free_compose_dialog();
  651. }
  652. else if (result == DialogExResultRight) // Post
  653. {
  654. // post the message
  655. // send selected_message
  656. if (selected_message && app_instance->login_username_logged_in)
  657. {
  658. if (strlen(selected_message) > MAX_MESSAGE_LENGTH)
  659. {
  660. FURI_LOG_E(TAG, "Message is too long");
  661. return;
  662. }
  663. // Send the selected_message
  664. char command[256];
  665. snprintf(command, sizeof(command), "{\"username\":\"%s\",\"content\":\"%s\"}",
  666. app_instance->login_username_logged_in, selected_message);
  667. if (!flipper_http_post_request_with_headers(
  668. "https://www.flipsocial.net/api/feed/post/",
  669. auth_headers,
  670. command))
  671. {
  672. FURI_LOG_E(TAG, "Failed to send HTTP request for feed");
  673. fhttp.state = ISSUE;
  674. return;
  675. }
  676. fhttp.state = RECEIVING;
  677. furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
  678. }
  679. else
  680. {
  681. FURI_LOG_E(TAG, "Message or username is NULL");
  682. return;
  683. }
  684. while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
  685. {
  686. furi_delay_ms(100);
  687. }
  688. if (flip_social_load_initial_feed())
  689. {
  690. flip_social_free_compose_dialog();
  691. }
  692. FURI_LOG_E(TAG, "Failed to load initial feed");
  693. return;
  694. }
  695. }
  696. /**
  697. * @brief Handle ALL submenu item selections.
  698. * @param context The context - FlipSocialApp object.
  699. * @param index The FlipSocialSubmenuIndex item that was clicked.
  700. * @return void
  701. */
  702. void flip_social_callback_submenu_choices(void *context, uint32_t index)
  703. {
  704. FlipSocialApp *app = (FlipSocialApp *)context;
  705. if (!app)
  706. {
  707. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  708. return;
  709. }
  710. switch (index)
  711. {
  712. case FlipSocialSubmenuLoggedOutIndexLogin:
  713. flip_social_sent_login_request = false;
  714. flip_social_login_success = false;
  715. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
  716. break;
  717. case FlipSocialSubmenuLoggedOutIndexRegister:
  718. flip_social_sent_register_request = false;
  719. flip_social_register_success = false;
  720. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  721. break;
  722. case FlipSocialSubmenuLoggedOutIndexAbout:
  723. if (!about_widget_alloc(false))
  724. {
  725. return;
  726. }
  727. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutAbout);
  728. break;
  729. case FlipSocialSubmenuLoggedOutIndexWifiSettings:
  730. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
  731. break;
  732. case FlipSocialSubmenuLoggedInIndexProfile:
  733. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInProfile);
  734. break;
  735. case FlipSocialSubmenuLoggedInIndexMessages:
  736. free_flip_social_group();
  737. flipper_http_loading_task(
  738. flip_social_get_message_users, // get the message users
  739. flip_social_parse_json_message_users, // parse the message users
  740. FlipSocialViewLoggedInMessagesSubmenu, // switch to the messages submenu if successful
  741. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  742. &app->view_dispatcher); // view dispatcher
  743. break;
  744. case FlipSocialSubmenuLoggedInIndexMessagesNewMessage:
  745. flipper_http_loading_task(
  746. flip_social_get_explore, // get the explore users
  747. flip_social_parse_json_message_user_choices, // parse the explore users
  748. FlipSocialViewLoggedInMessagesUserChoices, // switch to the user choices if successful
  749. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  750. &app->view_dispatcher); // view dispatcher
  751. break;
  752. case FlipSocialSubmenuLoggedInIndexFeed:
  753. free_flip_social_group();
  754. if (!flip_social_load_initial_feed())
  755. {
  756. FURI_LOG_E(TAG, "Failed to load the initial feed");
  757. return;
  758. }
  759. free_pre_saved_messages();
  760. break;
  761. case FlipSocialSubmenuExploreIndex:
  762. free_flip_social_group();
  763. flipper_http_loading_task(
  764. flip_social_get_explore, // get the explore users
  765. flip_social_parse_json_explore, // parse the explore users
  766. FlipSocialViewLoggedInExploreSubmenu, // switch to the explore submenu if successful
  767. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  768. &app->view_dispatcher); // view dispatcher
  769. break;
  770. case FlipSocialSubmenuLoggedInIndexCompose:
  771. free_pre_saved_messages();
  772. if (!pre_saved_messages_alloc())
  773. {
  774. FURI_LOG_E(TAG, "Failed to allocate pre-saved messages");
  775. return;
  776. }
  777. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  778. break;
  779. case FlipSocialSubmenuLoggedInIndexSettings:
  780. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettings);
  781. break;
  782. case FlipSocialSubmenuLoggedInSignOutButton:
  783. free_flip_social_group();
  784. app->is_logged_in = "false";
  785. 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);
  786. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutSubmenu);
  787. break;
  788. case FlipSocialSubmenuComposeIndexAddPreSave:
  789. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInComposeAddPreSaveInput);
  790. break;
  791. default:
  792. action = ActionNone;
  793. // Handle the pre-saved message selection (has a max of 25 items)
  794. if (index >= FlipSocialSubemnuComposeIndexStartIndex && index < FlipSocialSubemnuComposeIndexStartIndex + MAX_PRE_SAVED_MESSAGES)
  795. {
  796. app->pre_saved_messages.index = index - FlipSocialSubemnuComposeIndexStartIndex;
  797. snprintf(selected_message, MAX_MESSAGE_LENGTH, "%s", app->pre_saved_messages.messages[app->pre_saved_messages.index]);
  798. if (!selected_message)
  799. {
  800. FURI_LOG_E(TAG, "Selected message is NULL");
  801. return;
  802. }
  803. flip_social_free_compose_dialog();
  804. if (!app->dialog_compose)
  805. {
  806. if (!easy_flipper_set_dialog_ex(
  807. &app->dialog_compose,
  808. FlipSocialViewComposeDialog,
  809. "New Feed Post",
  810. 0,
  811. 0,
  812. selected_message,
  813. 0,
  814. 10,
  815. "Delete",
  816. "Post",
  817. NULL,
  818. compose_dialog_callback,
  819. flip_social_callback_to_compose_logged_in,
  820. &app->view_dispatcher,
  821. app))
  822. {
  823. return;
  824. }
  825. }
  826. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewComposeDialog);
  827. }
  828. // Handle the explore selection
  829. else if (index >= FlipSocialSubmenuExploreIndexStartIndex && index < FlipSocialSubmenuExploreIndexStartIndex + MAX_EXPLORE_USERS)
  830. {
  831. if (!flip_social_explore)
  832. {
  833. FURI_LOG_E(TAG, "FlipSocialExplore is NULL");
  834. return;
  835. }
  836. flip_social_explore->index = index - FlipSocialSubmenuExploreIndexStartIndex;
  837. flip_social_free_explore_dialog();
  838. if (!app->dialog_explore)
  839. {
  840. if (!easy_flipper_set_dialog_ex(
  841. &app->dialog_explore,
  842. FlipSocialViewExploreDialog,
  843. "User Options",
  844. 0,
  845. 0,
  846. flip_social_explore->usernames[flip_social_explore->index],
  847. 0,
  848. 10,
  849. "Remove",
  850. "Add",
  851. NULL,
  852. explore_dialog_callback,
  853. flip_social_callback_to_explore_logged_in,
  854. &app->view_dispatcher,
  855. app))
  856. {
  857. return;
  858. }
  859. }
  860. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewExploreDialog);
  861. }
  862. // handle the friends selection
  863. else if (index >= FlipSocialSubmenuLoggedInIndexFriendsStart && index < FlipSocialSubmenuLoggedInIndexFriendsStart + MAX_FRIENDS)
  864. {
  865. if (!flip_social_friends)
  866. {
  867. FURI_LOG_E(TAG, "FlipSocialFriends is NULL");
  868. return;
  869. }
  870. flip_social_friends->index = index - FlipSocialSubmenuLoggedInIndexFriendsStart;
  871. flip_social_free_friends_dialog();
  872. if (!app->dialog_friends)
  873. {
  874. if (!easy_flipper_set_dialog_ex(
  875. &app->dialog_friends,
  876. FlipSocialViewFriendsDialog,
  877. "User Options",
  878. 0,
  879. 0,
  880. flip_social_friends->usernames[flip_social_friends->index],
  881. 0,
  882. 10,
  883. "Remove",
  884. "",
  885. NULL,
  886. friends_dialog_callback,
  887. flip_social_callback_to_friends_logged_in,
  888. &app->view_dispatcher,
  889. app))
  890. {
  891. return;
  892. }
  893. }
  894. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewFriendsDialog);
  895. }
  896. // handle the messages selection
  897. else if (index >= FlipSocialSubmenuLoggedInIndexMessagesUsersStart && index < FlipSocialSubmenuLoggedInIndexMessagesUsersStart + MAX_MESSAGE_USERS)
  898. {
  899. if (!flip_social_message_users)
  900. {
  901. FURI_LOG_E(TAG, "FlipSocialMessageUsers is NULL");
  902. return;
  903. }
  904. flip_social_message_users->index = index - FlipSocialSubmenuLoggedInIndexMessagesUsersStart;
  905. flipper_http_loading_task(
  906. flip_social_get_messages_with_user, // get the messages with the selected user
  907. flip_social_parse_json_messages, // parse the messages
  908. FlipSocialViewMessagesDialog, // switch to the messages process if successful
  909. FlipSocialViewLoggedInMessagesSubmenu, // switch back to the messages submenu if failed
  910. &app->view_dispatcher // view dispatcher
  911. );
  912. }
  913. // handle the messages user choices selection
  914. else if (index >= FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart && index < FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart + MAX_EXPLORE_USERS)
  915. {
  916. if (!flip_social_explore)
  917. {
  918. FURI_LOG_E(TAG, "FlipSocialExplore is NULL");
  919. return;
  920. }
  921. flip_social_explore->index = index - FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart;
  922. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput);
  923. }
  924. else
  925. {
  926. FURI_LOG_E(TAG, "Unknown submenu index");
  927. }
  928. break;
  929. }
  930. }
  931. /**
  932. * @brief Text input callback for when the user finishes entering their SSID on the wifi settings (logged out) screen.
  933. * @param context The context - FlipSocialApp object.
  934. * @return void
  935. */
  936. void flip_social_logged_out_wifi_settings_ssid_updated(void *context)
  937. {
  938. FlipSocialApp *app = (FlipSocialApp *)context;
  939. if (!app)
  940. {
  941. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  942. return;
  943. }
  944. // Store the entered name
  945. strncpy(app->wifi_ssid_logged_out, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  946. // Store the entered name in the logged in name field
  947. strncpy(app->wifi_ssid_logged_in, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  948. strncpy(app->wifi_ssid_logged_in_temp_buffer, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  949. // Ensure null-termination
  950. app->wifi_ssid_logged_out[app->wifi_ssid_logged_out_temp_buffer_size - 1] = '\0';
  951. // Update the name item text
  952. if (app->variable_item_logged_out_wifi_settings_ssid)
  953. {
  954. variable_item_set_current_value_text(app->variable_item_logged_out_wifi_settings_ssid, app->wifi_ssid_logged_out);
  955. }
  956. // update the wifi settings
  957. if (strlen(app->wifi_ssid_logged_out) > 0 && strlen(app->wifi_password_logged_out) > 0)
  958. {
  959. if (!flipper_http_save_wifi(app->wifi_ssid_logged_out, app->wifi_password_logged_out))
  960. {
  961. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  962. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  963. }
  964. }
  965. // Save the settings
  966. 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);
  967. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
  968. }
  969. /**
  970. * @brief Text input callback for when the user finishes entering their password on the wifi settings (logged out) screen.
  971. * @param context The context - FlipSocialApp object.
  972. * @return void
  973. */
  974. void flip_social_logged_out_wifi_settings_password_updated(void *context)
  975. {
  976. FlipSocialApp *app = (FlipSocialApp *)context;
  977. if (!app)
  978. {
  979. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  980. return;
  981. }
  982. // Store the entered WiFi password
  983. strncpy(app->wifi_password_logged_out, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  984. // Store the entered WiFi password in the logged in password field
  985. strncpy(app->wifi_password_logged_in, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  986. strncpy(app->wifi_password_logged_in_temp_buffer, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  987. // Ensure null-termination
  988. app->wifi_password_logged_out[app->wifi_password_logged_out_temp_buffer_size - 1] = '\0';
  989. // Update the password item text
  990. if (app->variable_item_logged_out_wifi_settings_password)
  991. {
  992. variable_item_set_current_value_text(app->variable_item_logged_out_wifi_settings_password, app->wifi_password_logged_out);
  993. }
  994. // update the wifi settings
  995. if (strlen(app->wifi_ssid_logged_out) > 0 && strlen(app->wifi_password_logged_out) > 0)
  996. {
  997. if (!flipper_http_save_wifi(app->wifi_ssid_logged_out, app->wifi_password_logged_out))
  998. {
  999. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  1000. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1001. }
  1002. }
  1003. // Save the settings
  1004. 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);
  1005. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
  1006. }
  1007. /**
  1008. * @brief Callback when the user selects a menu item in the wifi settings (logged out) screen.
  1009. * @param context The context - FlipSocialApp object.
  1010. * @param index The index of the selected item.
  1011. * @return void
  1012. */
  1013. void flip_social_text_input_logged_out_wifi_settings_item_selected(void *context, uint32_t index)
  1014. {
  1015. FlipSocialApp *app = (FlipSocialApp *)context;
  1016. if (!app)
  1017. {
  1018. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1019. return;
  1020. }
  1021. switch (index)
  1022. {
  1023. case 0: // Input SSID
  1024. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsSSIDInput);
  1025. break;
  1026. case 1: // Input Password
  1027. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsPasswordInput);
  1028. break;
  1029. default:
  1030. FURI_LOG_E(TAG, "Unknown configuration item index");
  1031. break;
  1032. }
  1033. }
  1034. /**
  1035. * @brief Text input callback for when the user finishes entering their username on the login (logged out) screen.
  1036. * @param context The context - FlipSocialApp object.
  1037. * @return void
  1038. */
  1039. void flip_social_logged_out_login_username_updated(void *context)
  1040. {
  1041. FlipSocialApp *app = (FlipSocialApp *)context;
  1042. if (!app)
  1043. {
  1044. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1045. return;
  1046. }
  1047. // Store the entered name
  1048. strncpy(app->login_username_logged_out, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  1049. // Store the entered name in the logged in username field
  1050. strncpy(app->login_username_logged_in, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  1051. strncpy(app->login_username_logged_in_temp_buffer, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  1052. // Ensure null-termination
  1053. app->login_username_logged_out[app->login_username_logged_out_temp_buffer_size - 1] = '\0';
  1054. // Update the name item text
  1055. if (app->variable_item_logged_out_login_username)
  1056. {
  1057. variable_item_set_current_value_text(app->variable_item_logged_out_login_username, app->login_username_logged_out);
  1058. }
  1059. // Save the settings
  1060. 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);
  1061. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
  1062. }
  1063. /**
  1064. * @brief Text input callback for when the user finishes entering their password on the login (logged out) screen.
  1065. * @param context The context - FlipSocialApp object.
  1066. * @return void
  1067. */
  1068. void flip_social_logged_out_login_password_updated(void *context)
  1069. {
  1070. FlipSocialApp *app = (FlipSocialApp *)context;
  1071. if (!app)
  1072. {
  1073. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1074. return;
  1075. }
  1076. // Store the entered password
  1077. strncpy(app->login_password_logged_out, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  1078. // Store the entered password in the change password field
  1079. strncpy(app->change_password_logged_in, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  1080. strncpy(app->change_password_logged_in_temp_buffer, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  1081. // Ensure null-termination
  1082. app->login_password_logged_out[app->login_password_logged_out_temp_buffer_size - 1] = '\0';
  1083. // Update the password item text
  1084. if (app->variable_item_logged_out_login_password)
  1085. {
  1086. // dont show the password on the screen (version 0.2)
  1087. // variable_item_set_current_value_text(app->variable_item_logged_out_login_password, app->login_password_logged_out);
  1088. }
  1089. // Save the settings
  1090. 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);
  1091. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
  1092. }
  1093. /**
  1094. * @brief Callback when the user selects a menu item in the login (logged out) screen.
  1095. * @param context The context - FlipSocialApp object.
  1096. * @param index The index of the selected item.
  1097. * @return void
  1098. */
  1099. void flip_social_text_input_logged_out_login_item_selected(void *context, uint32_t index)
  1100. {
  1101. FlipSocialApp *app = (FlipSocialApp *)context;
  1102. if (!app)
  1103. {
  1104. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1105. return;
  1106. }
  1107. switch (index)
  1108. {
  1109. case 0: // Input Username
  1110. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginUsernameInput);
  1111. break;
  1112. case 1: // Input Password
  1113. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginPasswordInput);
  1114. break;
  1115. case 2: // Login Button
  1116. flip_social_login_switch_to_view(app);
  1117. break;
  1118. default:
  1119. FURI_LOG_E(TAG, "Unknown configuration item index");
  1120. break;
  1121. }
  1122. }
  1123. /**
  1124. * @brief Text input callback for when the user finishes entering their username on the register (logged out) screen.
  1125. * @param context The context - FlipSocialApp object.
  1126. * @return void
  1127. */
  1128. void flip_social_logged_out_register_username_updated(void *context)
  1129. {
  1130. FlipSocialApp *app = (FlipSocialApp *)context;
  1131. if (!app)
  1132. {
  1133. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1134. return;
  1135. }
  1136. // Store the entered name
  1137. strncpy(app->register_username_logged_out, app->register_username_logged_out_temp_buffer, app->register_username_logged_out_temp_buffer_size);
  1138. // Ensure null-termination
  1139. app->register_username_logged_out[app->register_username_logged_out_temp_buffer_size - 1] = '\0';
  1140. // Update the name item text
  1141. if (app->variable_item_logged_out_register_username)
  1142. {
  1143. variable_item_set_current_value_text(app->variable_item_logged_out_register_username, app->register_username_logged_out);
  1144. }
  1145. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  1146. }
  1147. /**
  1148. * @brief Text input callback for when the user finishes entering their password on the register (logged out) screen.
  1149. * @param context The context - FlipSocialApp object.
  1150. * @return void
  1151. */
  1152. void flip_social_logged_out_register_password_updated(void *context)
  1153. {
  1154. FlipSocialApp *app = (FlipSocialApp *)context;
  1155. if (!app)
  1156. {
  1157. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1158. return;
  1159. }
  1160. // Store the entered password
  1161. strncpy(app->register_password_logged_out, app->register_password_logged_out_temp_buffer, app->register_password_logged_out_temp_buffer_size);
  1162. // Ensure null-termination
  1163. app->register_password_logged_out[app->register_password_logged_out_temp_buffer_size - 1] = '\0';
  1164. // Update the password item text
  1165. if (app->variable_item_logged_out_register_password)
  1166. {
  1167. variable_item_set_current_value_text(app->variable_item_logged_out_register_password, app->register_password_logged_out);
  1168. }
  1169. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  1170. }
  1171. /**
  1172. * @brief Text input callback for when the user finishes entering their password 2 on the register (logged out) screen.
  1173. * @param context The context - FlipSocialApp object.
  1174. * @return void
  1175. */
  1176. void flip_social_logged_out_register_password_2_updated(void *context)
  1177. {
  1178. FlipSocialApp *app = (FlipSocialApp *)context;
  1179. if (!app)
  1180. {
  1181. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1182. return;
  1183. }
  1184. // Store the entered password
  1185. strncpy(app->register_password_2_logged_out, app->register_password_2_logged_out_temp_buffer, app->register_password_2_logged_out_temp_buffer_size);
  1186. // Ensure null-termination
  1187. app->register_password_2_logged_out[app->register_password_2_logged_out_temp_buffer_size - 1] = '\0';
  1188. // Update the password item text
  1189. if (app->variable_item_logged_out_register_password_2)
  1190. {
  1191. variable_item_set_current_value_text(app->variable_item_logged_out_register_password_2, app->register_password_2_logged_out);
  1192. }
  1193. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
  1194. }
  1195. /**
  1196. * @brief Callback when the user selects a menu item in the register (logged out) screen.
  1197. * @param context The context - FlipSocialApp object.
  1198. * @param index The index of the selected item.
  1199. * @return void
  1200. */
  1201. void flip_social_text_input_logged_out_register_item_selected(void *context, uint32_t index)
  1202. {
  1203. FlipSocialApp *app = (FlipSocialApp *)context;
  1204. if (!app)
  1205. {
  1206. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1207. return;
  1208. }
  1209. switch (index)
  1210. {
  1211. case 0: // Input Username
  1212. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterUsernameInput);
  1213. break;
  1214. case 1: // Input Password
  1215. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterPasswordInput);
  1216. break;
  1217. case 2: // Input Password 2
  1218. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterPassword2Input);
  1219. break;
  1220. case 3: // Register button
  1221. flip_social_register_switch_to_view(app);
  1222. break;
  1223. default:
  1224. FURI_LOG_E(TAG, "Unknown configuration item index");
  1225. break;
  1226. }
  1227. }
  1228. /**
  1229. * @brief Text input callback for when the user finishes entering their SSID on the wifi settings (logged in) screen.
  1230. * @param context The context - FlipSocialApp object.
  1231. * @return void
  1232. */
  1233. void flip_social_logged_in_wifi_settings_ssid_updated(void *context)
  1234. {
  1235. FlipSocialApp *app = (FlipSocialApp *)context;
  1236. if (!app)
  1237. {
  1238. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1239. return;
  1240. }
  1241. // Store the entered SSID
  1242. strncpy(app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer, app->wifi_ssid_logged_in_temp_buffer_size);
  1243. // Store the entered SSID in the logged out SSID
  1244. strncpy(app->wifi_ssid_logged_out, app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer_size);
  1245. strncpy(app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer_size);
  1246. // Ensure null-termination
  1247. app->wifi_ssid_logged_in[app->wifi_ssid_logged_in_temp_buffer_size - 1] = '\0';
  1248. // Update the name item text
  1249. if (app->variable_item_logged_in_wifi_settings_ssid)
  1250. {
  1251. variable_item_set_current_value_text(app->variable_item_logged_in_wifi_settings_ssid, app->wifi_ssid_logged_in);
  1252. }
  1253. // Save the settings
  1254. 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);
  1255. // update the wifi settings
  1256. if (strlen(app->wifi_ssid_logged_in) > 0 && strlen(app->wifi_password_logged_in) > 0)
  1257. {
  1258. if (!flipper_http_save_wifi(app->wifi_ssid_logged_in, app->wifi_password_logged_in))
  1259. {
  1260. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  1261. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1262. }
  1263. }
  1264. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
  1265. }
  1266. /**
  1267. * @brief Text input callback for when the user finishes entering their password on the wifi settings (logged in) screen.
  1268. * @param context The context - FlipSocialApp object.
  1269. * @return void
  1270. */
  1271. void flip_social_logged_in_wifi_settings_password_updated(void *context)
  1272. {
  1273. FlipSocialApp *app = (FlipSocialApp *)context;
  1274. if (!app)
  1275. {
  1276. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1277. return;
  1278. }
  1279. // Store the entered password
  1280. strncpy(app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer, app->wifi_password_logged_in_temp_buffer_size);
  1281. // Store the entered password in the logged out password
  1282. strncpy(app->login_password_logged_out, app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer_size);
  1283. strncpy(app->login_password_logged_out_temp_buffer, app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer_size);
  1284. // Ensure null-termination
  1285. app->wifi_password_logged_in[app->wifi_password_logged_in_temp_buffer_size - 1] = '\0';
  1286. // Update the password item text
  1287. if (app->variable_item_logged_in_wifi_settings_password)
  1288. {
  1289. // dont show the password on the screen (version 0.2)
  1290. // variable_item_set_current_value_text(app->variable_item_logged_in_wifi_settings_password, app->wifi_password_logged_in);
  1291. }
  1292. // Save the settings
  1293. 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);
  1294. // update the wifi settings
  1295. if (strlen(app->wifi_ssid_logged_in) > 0 && strlen(app->wifi_password_logged_in) > 0)
  1296. {
  1297. if (!flipper_http_save_wifi(app->wifi_ssid_logged_in, app->wifi_password_logged_in))
  1298. {
  1299. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  1300. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1301. }
  1302. }
  1303. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
  1304. }
  1305. /**
  1306. * @brief Callback when the user selects a menu item in the wifi settings (logged in) screen.
  1307. * @param context The context - FlipSocialApp object.
  1308. * @param index The index of the selected item.
  1309. * @return void
  1310. */
  1311. void flip_social_text_input_logged_in_wifi_settings_item_selected(void *context, uint32_t index)
  1312. {
  1313. FlipSocialApp *app = (FlipSocialApp *)context;
  1314. if (!app)
  1315. {
  1316. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1317. return;
  1318. }
  1319. switch (index)
  1320. {
  1321. case 0: // Input SSID
  1322. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsSSIDInput);
  1323. break;
  1324. case 1: // Input Password
  1325. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsPasswordInput);
  1326. break;
  1327. default:
  1328. FURI_LOG_E(TAG, "Unknown configuration item index");
  1329. break;
  1330. }
  1331. }
  1332. /**
  1333. * @brief Text input callback for when the user finishes entering their message on the compose (logged in) screen for Add Text
  1334. * @param context The context - FlipSocialApp object.
  1335. * @return void
  1336. */
  1337. void flip_social_logged_in_compose_pre_save_updated(void *context)
  1338. {
  1339. FlipSocialApp *app = (FlipSocialApp *)context;
  1340. if (!app)
  1341. {
  1342. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1343. return;
  1344. }
  1345. // check if the message is empty or if adding in the message would exceed the MAX_PRE_SAVED_MESSAGES
  1346. if (app->compose_pre_save_logged_in_temp_buffer_size == 0 || app->pre_saved_messages.count >= MAX_PRE_SAVED_MESSAGES)
  1347. {
  1348. FURI_LOG_E(TAG, "Message is empty or would exceed the maximum number of pre-saved messages");
  1349. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  1350. return;
  1351. }
  1352. // Store the entered message
  1353. strncpy(app->compose_pre_save_logged_in, app->compose_pre_save_logged_in_temp_buffer, app->compose_pre_save_logged_in_temp_buffer_size);
  1354. // Ensure null-termination
  1355. app->compose_pre_save_logged_in[app->compose_pre_save_logged_in_temp_buffer_size - 1] = '\0';
  1356. // add the item to the submenu
  1357. submenu_reset(app->submenu_compose);
  1358. // loop through the items and add them to the submenu
  1359. app->pre_saved_messages.messages[app->pre_saved_messages.count] = app->compose_pre_save_logged_in;
  1360. app->pre_saved_messages.count++;
  1361. submenu_add_item(app->submenu_compose, "Add Pre-Save", FlipSocialSubmenuComposeIndexAddPreSave, flip_social_callback_submenu_choices, app);
  1362. for (uint32_t i = 0; i < app->pre_saved_messages.count; i++)
  1363. {
  1364. submenu_add_item(app->submenu_compose, app->pre_saved_messages.messages[i], FlipSocialSubemnuComposeIndexStartIndex + i, flip_social_callback_submenu_choices, app);
  1365. }
  1366. // save playlist
  1367. save_playlist(&app->pre_saved_messages);
  1368. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
  1369. }
  1370. /**
  1371. * @brief Text input callback for when the user finishes entering their message on the profile (logged in) screen for change password
  1372. * @param context The context - FlipSocialApp object.
  1373. * @return void
  1374. */
  1375. void flip_social_logged_in_profile_change_password_updated(void *context)
  1376. {
  1377. FlipSocialApp *app = (FlipSocialApp *)context;
  1378. if (!app)
  1379. {
  1380. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1381. return;
  1382. }
  1383. // Correct type: old_pass should be a pointer to a string (char *)
  1384. const char *old_password = app->login_password_logged_out;
  1385. // Store the entered message
  1386. strncpy(app->change_password_logged_in, app->change_password_logged_in_temp_buffer, app->change_password_logged_in_temp_buffer_size);
  1387. // store the entered password in the logged out password
  1388. strncpy(app->login_password_logged_out, app->change_password_logged_in, app->login_password_logged_out_temp_buffer_size);
  1389. strncpy(app->login_password_logged_out_temp_buffer, app->change_password_logged_in, app->login_password_logged_out_temp_buffer_size);
  1390. // Ensure null-termination
  1391. app->change_password_logged_in[app->change_password_logged_in_temp_buffer_size - 1] = '\0';
  1392. // Update the message item text
  1393. if (app->variable_item_logged_in_profile_change_password)
  1394. {
  1395. // dont show the password on the screen (version 0.2)
  1396. // variable_item_set_current_value_text(app->variable_item_logged_in_profile_change_password, app->change_password_logged_in);
  1397. }
  1398. // send post request to change password
  1399. auth_headers_alloc();
  1400. char payload[256];
  1401. snprintf(payload, sizeof(payload), "{\"username\":\"%s\",\"old_password\":\"%s\",\"new_password\":\"%s\"}", app->login_username_logged_out, old_password, app->change_password_logged_in);
  1402. if (!flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/change-password/", auth_headers, payload))
  1403. {
  1404. FURI_LOG_E(TAG, "Failed to send post request to change password");
  1405. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1406. return;
  1407. }
  1408. // Save the settings
  1409. 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);
  1410. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInProfile);
  1411. }
  1412. /**
  1413. * @brief Callback when a user selects a menu item in the profile (logged in) screen.
  1414. * @param context The context - FlipSocialApp object.
  1415. * @param index The index of the selected item.
  1416. * @return void
  1417. */
  1418. void flip_social_text_input_logged_in_profile_item_selected(void *context, uint32_t index)
  1419. {
  1420. FlipSocialApp *app = (FlipSocialApp *)context;
  1421. if (!app)
  1422. {
  1423. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1424. return;
  1425. }
  1426. switch (index)
  1427. {
  1428. case 0: // Change Username
  1429. // do nothing since username cannot be changed
  1430. break;
  1431. case 1: // Change Password
  1432. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInChangePasswordInput);
  1433. break;
  1434. case 2: // Friends
  1435. flip_social_free_friends();
  1436. free_flip_social_group();
  1437. if (!app->submenu_friends)
  1438. {
  1439. if (!easy_flipper_set_submenu(&app->submenu_friends, FlipSocialViewLoggedInFriendsSubmenu, "Friends", flip_social_callback_to_profile_logged_in, &app->view_dispatcher))
  1440. {
  1441. FURI_LOG_DEV(TAG, "Failed to set submenu for friends");
  1442. return;
  1443. }
  1444. }
  1445. flipper_http_loading_task(flip_social_get_friends, flip_social_parse_json_friends, FlipSocialViewLoggedInFriendsSubmenu, FlipSocialViewLoggedInProfile, &app->view_dispatcher);
  1446. break;
  1447. default:
  1448. FURI_LOG_E(TAG, "Unknown configuration item index");
  1449. break;
  1450. }
  1451. }
  1452. /**
  1453. * @brief Callback when a user selects a menu item in the settings (logged in) screen.
  1454. * @param context The context - FlipSocialApp object.
  1455. * @param index The index of the selected item.
  1456. * @return void
  1457. */
  1458. void flip_social_text_input_logged_in_settings_item_selected(void *context, uint32_t index)
  1459. {
  1460. FlipSocialApp *app = (FlipSocialApp *)context;
  1461. if (!app)
  1462. {
  1463. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1464. return;
  1465. }
  1466. switch (index)
  1467. {
  1468. case 0: // About
  1469. if (!about_widget_alloc(true))
  1470. {
  1471. return;
  1472. }
  1473. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsAbout);
  1474. break;
  1475. case 1: // Wifi
  1476. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
  1477. break;
  1478. default:
  1479. break;
  1480. }
  1481. }
  1482. /**
  1483. * @brief Text input callback for when the user finishes entering their message to send to the selected user choice (user choice messages view)
  1484. * @param context The context - FlipSocialApp object.
  1485. * @return void
  1486. */
  1487. void flip_social_logged_in_messages_user_choice_message_updated(void *context)
  1488. {
  1489. FlipSocialApp *app = (FlipSocialApp *)context;
  1490. if (!app)
  1491. {
  1492. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1493. return;
  1494. }
  1495. // check if the message is empty
  1496. if (app->message_user_choice_logged_in_temp_buffer_size == 0)
  1497. {
  1498. FURI_LOG_E(TAG, "Message is empty");
  1499. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput);
  1500. return;
  1501. }
  1502. // Store the entered message
  1503. strncpy(app->message_user_choice_logged_in, app->message_user_choice_logged_in_temp_buffer, app->message_user_choice_logged_in_temp_buffer_size);
  1504. // Ensure null-termination
  1505. app->message_user_choice_logged_in[app->message_user_choice_logged_in_temp_buffer_size - 1] = '\0';
  1506. // send post request to send message
  1507. auth_headers_alloc();
  1508. char url[128];
  1509. char payload[256];
  1510. snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
  1511. snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_explore->usernames[flip_social_explore->index], app->message_user_choice_logged_in);
  1512. if (flipper_http_post_request_with_headers(url, auth_headers, payload)) // start the async request
  1513. {
  1514. furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
  1515. fhttp.state = RECEIVING;
  1516. }
  1517. else
  1518. {
  1519. FURI_LOG_E(TAG, "Failed to send post request to send message");
  1520. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1521. fhttp.state = ISSUE;
  1522. return;
  1523. }
  1524. while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
  1525. {
  1526. // Wait for the request to be received
  1527. furi_delay_ms(10);
  1528. }
  1529. furi_timer_stop(fhttp.get_timeout_timer);
  1530. // add user to the message list
  1531. 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]));
  1532. flip_social_message_users->count++;
  1533. // redraw submenu
  1534. flip_social_update_messages_submenu();
  1535. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
  1536. }
  1537. /**
  1538. * @brief Text input callback for when the user finishes entering their message to the selected user (messages view)
  1539. * @param context The context - FlipSocialApp object.
  1540. * @return void
  1541. */
  1542. void flip_social_logged_in_messages_new_message_updated(void *context)
  1543. {
  1544. FlipSocialApp *app = (FlipSocialApp *)context;
  1545. if (!app)
  1546. {
  1547. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1548. return;
  1549. }
  1550. // check if the message is empty
  1551. if (app->messages_new_message_logged_in_temp_buffer_size == 0)
  1552. {
  1553. FURI_LOG_E(TAG, "Message is empty");
  1554. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageInput);
  1555. return;
  1556. }
  1557. // Store the entered message
  1558. strncpy(app->messages_new_message_logged_in, app->messages_new_message_logged_in_temp_buffer, app->messages_new_message_logged_in_temp_buffer_size);
  1559. // Ensure null-termination
  1560. app->messages_new_message_logged_in[app->messages_new_message_logged_in_temp_buffer_size - 1] = '\0';
  1561. // send post request to send message
  1562. auth_headers_alloc();
  1563. char url[128];
  1564. char payload[256];
  1565. snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
  1566. snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_message_users->usernames[flip_social_message_users->index], app->messages_new_message_logged_in);
  1567. if (flipper_http_post_request_with_headers(url, auth_headers, payload)) // start the async request
  1568. {
  1569. furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
  1570. fhttp.state = RECEIVING;
  1571. }
  1572. else
  1573. {
  1574. FURI_LOG_E(TAG, "Failed to send post request to send message");
  1575. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1576. fhttp.state = ISSUE;
  1577. return;
  1578. }
  1579. while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
  1580. {
  1581. // Wait for the request to be received
  1582. furi_delay_ms(10);
  1583. }
  1584. furi_timer_stop(fhttp.get_timeout_timer);
  1585. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
  1586. }
  1587. static void flip_social_widget_set_text(char *message, Widget **widget)
  1588. {
  1589. if (widget == NULL)
  1590. {
  1591. FURI_LOG_E(TAG, "flip_social_set_widget_text - widget is NULL");
  1592. DEV_CRASH();
  1593. return;
  1594. }
  1595. if (message == NULL)
  1596. {
  1597. FURI_LOG_E(TAG, "flip_social_set_widget_text - message is NULL");
  1598. DEV_CRASH();
  1599. return;
  1600. }
  1601. widget_reset(*widget);
  1602. uint32_t message_length = strlen(message); // Length of the message
  1603. uint32_t i = 0; // Index tracker
  1604. uint32_t formatted_index = 0; // Tracker for where we are in the formatted message
  1605. char *formatted_message; // Buffer to hold the final formatted message
  1606. // Allocate buffer with double the message length plus one for safety
  1607. if (!easy_flipper_set_buffer(&formatted_message, message_length * 2 + 1))
  1608. {
  1609. return;
  1610. }
  1611. while (i < message_length)
  1612. {
  1613. uint32_t max_line_length = 31; // Maximum characters per line
  1614. uint32_t remaining_length = message_length - i; // Remaining characters
  1615. uint32_t line_length = (remaining_length < max_line_length) ? remaining_length : max_line_length;
  1616. // Check for newline character within the current segment
  1617. uint32_t newline_pos = i;
  1618. bool found_newline = false;
  1619. for (; newline_pos < i + line_length && newline_pos < message_length; newline_pos++)
  1620. {
  1621. if (message[newline_pos] == '\n')
  1622. {
  1623. found_newline = true;
  1624. break;
  1625. }
  1626. }
  1627. if (found_newline)
  1628. {
  1629. // If newline found, set line_length up to the newline
  1630. line_length = newline_pos - i;
  1631. }
  1632. // Temporary buffer to hold the current line
  1633. char line[32];
  1634. strncpy(line, message + i, line_length);
  1635. line[line_length] = '\0';
  1636. // If newline was found, skip it for the next iteration
  1637. if (found_newline)
  1638. {
  1639. i += line_length + 1; // +1 to skip the '\n' character
  1640. }
  1641. else
  1642. {
  1643. // Check if the line ends in the middle of a word and adjust accordingly
  1644. if (line_length == max_line_length && message[i + line_length] != '\0' && message[i + line_length] != ' ')
  1645. {
  1646. // Find the last space within the current line to avoid breaking a word
  1647. char *last_space = strrchr(line, ' ');
  1648. if (last_space != NULL)
  1649. {
  1650. // Adjust the line_length to avoid cutting the word
  1651. line_length = last_space - line;
  1652. line[line_length] = '\0'; // Null-terminate at the space
  1653. }
  1654. }
  1655. // Move the index forward by the determined line_length
  1656. i += line_length;
  1657. // Skip any spaces at the beginning of the next line
  1658. while (i < message_length && message[i] == ' ')
  1659. {
  1660. i++;
  1661. }
  1662. }
  1663. // Manually copy the fixed line into the formatted_message buffer
  1664. for (uint32_t j = 0; j < line_length; j++)
  1665. {
  1666. formatted_message[formatted_index++] = line[j];
  1667. }
  1668. // Add a newline character for line spacing
  1669. formatted_message[formatted_index++] = '\n';
  1670. }
  1671. // Null-terminate the formatted_message
  1672. formatted_message[formatted_index] = '\0';
  1673. // Add the formatted message to the widget
  1674. widget_add_text_scroll_element(*widget, 0, 0, 128, 64, formatted_message);
  1675. }
  1676. void flip_social_loader_draw_callback(Canvas *canvas, void *model)
  1677. {
  1678. if (!canvas || !model)
  1679. {
  1680. FURI_LOG_E(TAG, "flip_social_loader_draw_callback - canvas or model is NULL");
  1681. return;
  1682. }
  1683. SerialState http_state = fhttp.state;
  1684. DataLoaderModel *data_loader_model = (DataLoaderModel *)model;
  1685. DataState data_state = data_loader_model->data_state;
  1686. char *title = data_loader_model->title;
  1687. canvas_set_font(canvas, FontSecondary);
  1688. if (http_state == INACTIVE)
  1689. {
  1690. canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
  1691. canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
  1692. canvas_draw_str(canvas, 0, 32, "If your board is connected,");
  1693. canvas_draw_str(canvas, 0, 42, "make sure you have flashed");
  1694. canvas_draw_str(canvas, 0, 52, "your WiFi Devboard with the");
  1695. canvas_draw_str(canvas, 0, 62, "latest FlipperHTTP flash.");
  1696. return;
  1697. }
  1698. if (data_state == DataStateError || data_state == DataStateParseError)
  1699. {
  1700. flip_social_request_error_draw(canvas);
  1701. return;
  1702. }
  1703. canvas_draw_str(canvas, 0, 7, title);
  1704. canvas_draw_str(canvas, 0, 17, "Loading...");
  1705. if (data_state == DataStateInitial)
  1706. {
  1707. return;
  1708. }
  1709. if (http_state == SENDING)
  1710. {
  1711. canvas_draw_str(canvas, 0, 27, "Fetching...");
  1712. return;
  1713. }
  1714. if (http_state == RECEIVING || data_state == DataStateRequested)
  1715. {
  1716. canvas_draw_str(canvas, 0, 27, "Receiving...");
  1717. return;
  1718. }
  1719. if (http_state == IDLE && data_state == DataStateReceived)
  1720. {
  1721. canvas_draw_str(canvas, 0, 27, "Processing...");
  1722. return;
  1723. }
  1724. if (http_state == IDLE && data_state == DataStateParsed)
  1725. {
  1726. canvas_draw_str(canvas, 0, 27, "Processed...");
  1727. return;
  1728. }
  1729. }
  1730. static void flip_social_loader_process_callback(void *context)
  1731. {
  1732. if (context == NULL)
  1733. {
  1734. FURI_LOG_E(TAG, "flip_social_loader_process_callback - context is NULL");
  1735. DEV_CRASH();
  1736. return;
  1737. }
  1738. FlipSocialApp *app = (FlipSocialApp *)context;
  1739. View *view = app->view_loader;
  1740. DataState current_data_state;
  1741. with_view_model(view, DataLoaderModel * model, { current_data_state = model->data_state; }, false);
  1742. if (current_data_state == DataStateInitial)
  1743. {
  1744. with_view_model(
  1745. view,
  1746. DataLoaderModel * model,
  1747. {
  1748. model->data_state = DataStateRequested;
  1749. DataLoaderFetch fetch = model->fetcher;
  1750. if (fetch == NULL)
  1751. {
  1752. FURI_LOG_E(TAG, "Model doesn't have Fetch function assigned.");
  1753. model->data_state = DataStateError;
  1754. return;
  1755. }
  1756. // Clear any previous responses
  1757. strncpy(fhttp.last_response, "", 1);
  1758. bool request_status = fetch(model);
  1759. if (!request_status)
  1760. {
  1761. model->data_state = DataStateError;
  1762. }
  1763. },
  1764. true);
  1765. }
  1766. else if (current_data_state == DataStateRequested || current_data_state == DataStateError)
  1767. {
  1768. if (fhttp.state == IDLE && fhttp.last_response != NULL)
  1769. {
  1770. if (strstr(fhttp.last_response, "[PONG]") != NULL)
  1771. {
  1772. FURI_LOG_DEV(TAG, "PONG received.");
  1773. }
  1774. else if (strncmp(fhttp.last_response, "[SUCCESS]", 9) == 0)
  1775. {
  1776. FURI_LOG_DEV(TAG, "SUCCESS received. %s", fhttp.last_response ? fhttp.last_response : "NULL");
  1777. }
  1778. else if (strncmp(fhttp.last_response, "[ERROR]", 9) == 0)
  1779. {
  1780. FURI_LOG_DEV(TAG, "ERROR received. %s", fhttp.last_response ? fhttp.last_response : "NULL");
  1781. }
  1782. else if (strlen(fhttp.last_response) == 0)
  1783. {
  1784. // Still waiting on response
  1785. }
  1786. else
  1787. {
  1788. with_view_model(view, DataLoaderModel * model, { model->data_state = DataStateReceived; }, true);
  1789. }
  1790. }
  1791. else if (fhttp.state == SENDING || fhttp.state == RECEIVING)
  1792. {
  1793. // continue waiting
  1794. }
  1795. else if (fhttp.state == INACTIVE)
  1796. {
  1797. // inactive. try again
  1798. }
  1799. else if (fhttp.state == ISSUE)
  1800. {
  1801. with_view_model(view, DataLoaderModel * model, { model->data_state = DataStateError; }, true);
  1802. }
  1803. else
  1804. {
  1805. FURI_LOG_DEV(TAG, "Unexpected state: %d lastresp: %s", fhttp.state, fhttp.last_response ? fhttp.last_response : "NULL");
  1806. DEV_CRASH();
  1807. }
  1808. }
  1809. else if (current_data_state == DataStateReceived)
  1810. {
  1811. with_view_model(
  1812. view,
  1813. DataLoaderModel * model,
  1814. {
  1815. char *data_text;
  1816. if (model->parser == NULL)
  1817. {
  1818. data_text = NULL;
  1819. FURI_LOG_DEV(TAG, "Parser is NULL");
  1820. DEV_CRASH();
  1821. }
  1822. else
  1823. {
  1824. data_text = model->parser(model);
  1825. }
  1826. FURI_LOG_DEV(TAG, "Parsed data: %s\r\ntext: %s", fhttp.last_response ? fhttp.last_response : "NULL", data_text ? data_text : "NULL");
  1827. model->data_text = data_text;
  1828. if (data_text == NULL)
  1829. {
  1830. model->data_state = DataStateParseError;
  1831. }
  1832. else
  1833. {
  1834. model->data_state = DataStateParsed;
  1835. }
  1836. },
  1837. true);
  1838. }
  1839. else if (current_data_state == DataStateParsed)
  1840. {
  1841. with_view_model(
  1842. view,
  1843. DataLoaderModel * model,
  1844. {
  1845. if (++model->request_index < model->request_count)
  1846. {
  1847. model->data_state = DataStateInitial;
  1848. }
  1849. else
  1850. {
  1851. flip_social_widget_set_text(model->data_text != NULL ? model->data_text : "Empty result", &app_instance->widget_result);
  1852. if (model->data_text != NULL)
  1853. {
  1854. free(model->data_text);
  1855. model->data_text = NULL;
  1856. }
  1857. view_set_previous_callback(widget_get_view(app_instance->widget_result), model->back_callback);
  1858. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewWidgetResult);
  1859. }
  1860. },
  1861. true);
  1862. }
  1863. }
  1864. static void flip_social_loader_timer_callback(void *context)
  1865. {
  1866. if (context == NULL)
  1867. {
  1868. FURI_LOG_E(TAG, "flip_social_loader_timer_callback - context is NULL");
  1869. DEV_CRASH();
  1870. return;
  1871. }
  1872. FlipSocialApp *app = (FlipSocialApp *)context;
  1873. view_dispatcher_send_custom_event(app->view_dispatcher, FlipSocialCustomEventProcess);
  1874. }
  1875. static void flip_social_loader_on_enter(void *context)
  1876. {
  1877. if (context == NULL)
  1878. {
  1879. FURI_LOG_E(TAG, "flip_social_loader_on_enter - context is NULL");
  1880. DEV_CRASH();
  1881. return;
  1882. }
  1883. FlipSocialApp *app = (FlipSocialApp *)context;
  1884. View *view = app->view_loader;
  1885. with_view_model(
  1886. view,
  1887. DataLoaderModel * model,
  1888. {
  1889. view_set_previous_callback(view, model->back_callback);
  1890. if (model->timer == NULL)
  1891. {
  1892. model->timer = furi_timer_alloc(flip_social_loader_timer_callback, FuriTimerTypePeriodic, app);
  1893. }
  1894. furi_timer_start(model->timer, 250);
  1895. },
  1896. true);
  1897. }
  1898. static void flip_social_loader_on_exit(void *context)
  1899. {
  1900. if (context == NULL)
  1901. {
  1902. FURI_LOG_E(TAG, "flip_social_loader_on_exit - context is NULL");
  1903. DEV_CRASH();
  1904. return;
  1905. }
  1906. FlipSocialApp *app = (FlipSocialApp *)context;
  1907. View *view = app->view_loader;
  1908. with_view_model(
  1909. view,
  1910. DataLoaderModel * model,
  1911. {
  1912. if (model->timer)
  1913. {
  1914. furi_timer_stop(model->timer);
  1915. }
  1916. },
  1917. false);
  1918. }
  1919. void flip_social_loader_init(View *view)
  1920. {
  1921. if (view == NULL)
  1922. {
  1923. FURI_LOG_E(TAG, "flip_social_loader_init - view is NULL");
  1924. DEV_CRASH();
  1925. return;
  1926. }
  1927. view_allocate_model(view, ViewModelTypeLocking, sizeof(DataLoaderModel));
  1928. view_set_enter_callback(view, flip_social_loader_on_enter);
  1929. view_set_exit_callback(view, flip_social_loader_on_exit);
  1930. }
  1931. void flip_social_loader_free_model(View *view)
  1932. {
  1933. if (view == NULL)
  1934. {
  1935. FURI_LOG_E(TAG, "flip_social_loader_free_model - view is NULL");
  1936. DEV_CRASH();
  1937. return;
  1938. }
  1939. with_view_model(
  1940. view,
  1941. DataLoaderModel * model,
  1942. {
  1943. if (model->timer)
  1944. {
  1945. furi_timer_free(model->timer);
  1946. model->timer = NULL;
  1947. }
  1948. if (model->parser_context)
  1949. {
  1950. free(model->parser_context);
  1951. model->parser_context = NULL;
  1952. }
  1953. },
  1954. false);
  1955. }
  1956. bool flip_social_custom_event_callback(void *context, uint32_t index)
  1957. {
  1958. if (context == NULL)
  1959. {
  1960. FURI_LOG_E(TAG, "flip_social_custom_event_callback - context is NULL");
  1961. DEV_CRASH();
  1962. return false;
  1963. }
  1964. switch (index)
  1965. {
  1966. case FlipSocialCustomEventProcess:
  1967. flip_social_loader_process_callback(context);
  1968. return true;
  1969. default:
  1970. FURI_LOG_DEV(TAG, "flip_social_custom_event_callback. Unknown index: %ld", index);
  1971. return false;
  1972. }
  1973. }
  1974. 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)
  1975. {
  1976. if (app == NULL)
  1977. {
  1978. FURI_LOG_E(TAG, "flip_social_generic_switch_to_view - app is NULL");
  1979. DEV_CRASH();
  1980. return;
  1981. }
  1982. View *view = app->view_loader;
  1983. if (view == NULL)
  1984. {
  1985. FURI_LOG_E(TAG, "flip_social_generic_switch_to_view - view is NULL");
  1986. DEV_CRASH();
  1987. return;
  1988. }
  1989. with_view_model(
  1990. view,
  1991. DataLoaderModel * model,
  1992. {
  1993. model->title = title;
  1994. model->fetcher = fetcher;
  1995. model->parser = parser;
  1996. model->request_index = 0;
  1997. model->request_count = request_count;
  1998. model->back_callback = back;
  1999. model->data_state = DataStateInitial;
  2000. model->data_text = NULL;
  2001. },
  2002. true);
  2003. view_dispatcher_switch_to_view(app->view_dispatcher, view_id);
  2004. }