callback.c 84 KB

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