flip_social_callback.c 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794
  1. #include <callback/flip_social_callback.h>
  2. // Below added by Derek Jamison
  3. // FURI_LOG_DEV will log only during app development. Be sure that Settings/System/Log Device is "LPUART"; so we dont use serial port.
  4. #ifdef DEVELOPMENT
  5. #define FURI_LOG_DEV(tag, format, ...) furi_log_print_format(FuriLogLevelInfo, tag, format, ##__VA_ARGS__)
  6. #define DEV_CRASH() furi_crash()
  7. #else
  8. #define FURI_LOG_DEV(tag, format, ...)
  9. #define DEV_CRASH()
  10. #endif
  11. static void flip_social_request_error_draw(Canvas *canvas)
  12. {
  13. if (canvas == NULL)
  14. {
  15. FURI_LOG_E(TAG, "flip_social_request_error_draw - canvas is NULL");
  16. DEV_CRASH();
  17. return;
  18. }
  19. if (fhttp.last_response != NULL)
  20. {
  21. if (strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL)
  22. {
  23. canvas_clear(canvas);
  24. canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
  25. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  26. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  27. }
  28. else if (strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL)
  29. {
  30. canvas_clear(canvas);
  31. canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
  32. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  33. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  34. }
  35. else if (strstr(fhttp.last_response, "[ERROR] GET request failed or returned empty data.") != NULL)
  36. {
  37. canvas_clear(canvas);
  38. canvas_draw_str(canvas, 0, 10, "[ERROR] WiFi error.");
  39. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  40. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  41. }
  42. else if (strstr(fhttp.last_response, "[PONG]") != NULL)
  43. {
  44. canvas_clear(canvas);
  45. canvas_draw_str(canvas, 0, 10, "[STATUS]Connecting to AP...");
  46. }
  47. else
  48. {
  49. canvas_clear(canvas);
  50. FURI_LOG_E(TAG, "Received an error: %s", fhttp.last_response);
  51. canvas_draw_str(canvas, 0, 10, "[ERROR] Unusual error...");
  52. canvas_draw_str(canvas, 0, 60, "Press BACK and retry.");
  53. }
  54. }
  55. else
  56. {
  57. canvas_clear(canvas);
  58. canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
  59. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  60. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  61. }
  62. }
  63. static bool flip_social_login_fetch(DataLoaderModel *model)
  64. {
  65. UNUSED(model);
  66. if (!app_instance)
  67. {
  68. FURI_LOG_E(TAG, "app_instance is NULL");
  69. return false;
  70. }
  71. 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)
  72. {
  73. return false;
  74. }
  75. char buffer[256];
  76. snprintf(buffer, sizeof(buffer), "{\"username\":\"%s\",\"password\":\"%s\"}", app_instance->login_username_logged_out, app_instance->login_password_logged_out);
  77. auth_headers_alloc();
  78. return flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/login/", auth_headers, buffer);
  79. }
  80. static char *flip_social_login_parse(DataLoaderModel *model)
  81. {
  82. UNUSED(model);
  83. if (!app_instance)
  84. {
  85. FURI_LOG_E(TAG, "app_instance is NULL");
  86. return "Failed to login...";
  87. }
  88. if (!fhttp.last_response)
  89. {
  90. flipper_http_deinit();
  91. return "Failed to login...";
  92. }
  93. // read response
  94. if (strstr(fhttp.last_response, "[SUCCESS]") != NULL || strstr(fhttp.last_response, "User found") != NULL)
  95. {
  96. flipper_http_deinit();
  97. app_instance->is_logged_in = "true";
  98. // set the logged_in_username and change_password_logged_in
  99. if (app_instance->login_username_logged_out)
  100. {
  101. strcpy(app_instance->login_username_logged_in, app_instance->login_username_logged_out);
  102. }
  103. if (app_instance->login_password_logged_out)
  104. {
  105. strcpy(app_instance->change_password_logged_in, app_instance->login_password_logged_out);
  106. }
  107. 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);
  108. // send user to the logged in submenu
  109. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewLoggedInSubmenu);
  110. return "Login successful!";
  111. }
  112. else if (strstr(fhttp.last_response, "User not found") != NULL)
  113. {
  114. flipper_http_deinit();
  115. return "Account not found...";
  116. }
  117. else
  118. {
  119. flipper_http_deinit();
  120. return "Failed to login...";
  121. }
  122. }
  123. static void flip_social_login_switch_to_view(FlipSocialApp *app)
  124. {
  125. flip_social_generic_switch_to_view(app, "Logging in...", flip_social_login_fetch, flip_social_login_parse, 1, flip_social_callback_to_login_logged_out, FlipSocialViewLoader);
  126. }
  127. static bool flip_social_register_fetch(DataLoaderModel *model)
  128. {
  129. UNUSED(model);
  130. // check if the username and password are valid
  131. 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)
  132. {
  133. FURI_LOG_E(TAG, "Username or password is NULL");
  134. return false;
  135. }
  136. // check if both passwords match
  137. if (strcmp(app_instance->register_password_logged_out, app_instance->register_password_2_logged_out) != 0)
  138. {
  139. FURI_LOG_E(TAG, "Passwords do not match");
  140. return false;
  141. }
  142. char buffer[128];
  143. snprintf(buffer, sizeof(buffer), "{\"username\":\"%s\",\"password\":\"%s\"}", app_instance->register_username_logged_out, app_instance->register_password_logged_out);
  144. return flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/register/", "{\"Content-Type\":\"application/json\"}", buffer);
  145. }
  146. static char *flip_social_register_parse(DataLoaderModel *model)
  147. {
  148. UNUSED(model);
  149. // read response
  150. if (fhttp.last_response != NULL && (strstr(fhttp.last_response, "[SUCCESS]") != NULL || strstr(fhttp.last_response, "User created") != NULL))
  151. {
  152. flipper_http_deinit();
  153. // set the login credentials
  154. if (app_instance->login_username_logged_out)
  155. {
  156. app_instance->login_username_logged_out = app_instance->register_username_logged_out;
  157. }
  158. if (app_instance->login_password_logged_out)
  159. {
  160. app_instance->login_password_logged_out = app_instance->register_password_logged_out;
  161. app_instance->change_password_logged_in = app_instance->register_password_logged_out;
  162. }
  163. if (app_instance->login_username_logged_in)
  164. {
  165. app_instance->login_username_logged_in = app_instance->register_username_logged_out;
  166. }
  167. app_instance->is_logged_in = "true";
  168. // update header credentials
  169. auth_headers_alloc();
  170. // save the credentials
  171. 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);
  172. // send user to the logged in submenu
  173. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewLoggedInSubmenu);
  174. return "Registration successful!\nWelcome to FlipSocial!";
  175. }
  176. else if (strstr(fhttp.last_response, "Username or password not provided") != NULL)
  177. {
  178. flipper_http_deinit();
  179. return "Please enter your credentials.\nPress BACK to return.";
  180. }
  181. else if (strstr(fhttp.last_response, "User already exists") != NULL || strstr(fhttp.last_response, "Multiple users found") != NULL)
  182. {
  183. flipper_http_deinit();
  184. return "Registration failed...\nUsername already exists.\nPress BACK to return.";
  185. }
  186. else
  187. {
  188. flipper_http_deinit();
  189. return "Registration failed...\nUpdate your credentials.\nPress BACK to return.";
  190. }
  191. }
  192. static void flip_social_register_switch_to_view(FlipSocialApp *app)
  193. {
  194. flip_social_generic_switch_to_view(app, "Registering...", flip_social_register_fetch, flip_social_register_parse, 1, flip_social_callback_to_register_logged_out, FlipSocialViewLoader);
  195. }
  196. /**
  197. * @brief Navigation callback to go back to the submenu Logged out.
  198. * @param context The context - unused
  199. * @return next view id (FlipSocialViewLoggedOutSubmenu)
  200. */
  201. uint32_t flip_social_callback_to_submenu_logged_out(void *context)
  202. {
  203. UNUSED(context);
  204. return FlipSocialViewLoggedOutSubmenu;
  205. }
  206. /**
  207. * @brief Navigation callback to go back to the submenu Logged in.
  208. * @param context The context - unused
  209. * @return next view id (FlipSocialViewLoggedInSubmenu)
  210. */
  211. uint32_t flip_social_callback_to_submenu_logged_in(void *context)
  212. {
  213. UNUSED(context);
  214. free_about_widget(false);
  215. //
  216. flip_social_free_friends();
  217. flip_social_free_message_users();
  218. flip_feed_info_free();
  219. if (flip_feed_item)
  220. {
  221. free(flip_feed_item);
  222. flip_feed_item = NULL;
  223. }
  224. // free the about widget if it exists
  225. free_about_widget(true);
  226. flip_social_free_explore_dialog();
  227. flip_social_free_friends_dialog();
  228. flip_social_free_messages_dialog();
  229. flip_social_free_compose_dialog();
  230. return FlipSocialViewLoggedInSubmenu;
  231. }
  232. /**
  233. * @brief Navigation callback to bring the user back to the (Logged out) Login screen
  234. * @param context The context - unused
  235. * @return next view id (FlipSocialViewLoggedOutLogin)
  236. */
  237. uint32_t flip_social_callback_to_login_logged_out(void *context)
  238. {
  239. UNUSED(context);
  240. flip_social_sent_login_request = false;
  241. flip_social_login_success = false;
  242. return FlipSocialViewVariableItemList;
  243. }
  244. /**
  245. * @brief Navigation callback to bring the user back to the (Logged out) Register screen
  246. * @param context The context - unused
  247. * @return next view id (FlipSocialViewLoggedOutRegister)
  248. */
  249. uint32_t flip_social_callback_to_register_logged_out(void *context)
  250. {
  251. UNUSED(context);
  252. flip_social_sent_register_request = false;
  253. flip_social_register_success = false;
  254. return FlipSocialViewVariableItemList;
  255. }
  256. /**
  257. * @brief Navigation callback to bring the user back to the (Logged out) Wifi Settings screen
  258. * @param context The context - unused
  259. * @return next view id (FlipSocialViewLoggedOutWifiSettings)
  260. */
  261. uint32_t flip_social_callback_to_wifi_settings_logged_out(void *context)
  262. {
  263. UNUSED(context);
  264. return FlipSocialViewVariableItemList;
  265. }
  266. /**
  267. * @brief Navigation callback to bring the user back to the (Logged in) Wifi Settings screen
  268. * @param context The context - unused
  269. * @return next view id (FlipSocialViewLoggedInSettingsWifi)
  270. */
  271. uint32_t flip_social_callback_to_wifi_settings_logged_in(void *context)
  272. {
  273. UNUSED(context);
  274. return FlipSocialViewVariableItemList;
  275. }
  276. /**
  277. * @brief Navigation callback to bring the user back to the (Logged in) Settings screen
  278. * @param context The context - unused
  279. * @return next view id (FlipSocialViewLoggedInSettingsWifi)
  280. */
  281. uint32_t flip_social_callback_to_settings_logged_in(void *context)
  282. {
  283. UNUSED(context);
  284. return FlipSocialViewSubmenu;
  285. }
  286. /**
  287. * @brief Navigation callback to bring the user back to the (Logged in) Compose screen
  288. * @param context The context - unused
  289. * @return next view id (FlipSocialViewLoggedInCompose)
  290. */
  291. uint32_t flip_social_callback_to_compose_logged_in(void *context)
  292. {
  293. UNUSED(context);
  294. return FlipSocialViewSubmenu;
  295. }
  296. /**
  297. * @brief Navigation callback to bring the user back to the (Logged in) Profile screen
  298. * @param context The context - unused
  299. * @return next view id (FlipSocialViewLoggedInProfile)
  300. */
  301. uint32_t flip_social_callback_to_profile_logged_in(void *context)
  302. {
  303. UNUSED(context);
  304. return FlipSocialViewVariableItemList;
  305. }
  306. /**
  307. * @brief Navigation callback to bring the user back to the Explore submenu
  308. * @param context The context - unused
  309. * @return next view id (FlipSocialViewSubmenu)
  310. */
  311. uint32_t flip_social_callback_to_explore_logged_in(void *context)
  312. {
  313. UNUSED(context);
  314. flip_social_dialog_stop = false;
  315. flip_social_dialog_shown = false;
  316. if (flip_social_explore)
  317. {
  318. flip_social_explore->index = 0;
  319. }
  320. return FlipSocialViewSubmenu;
  321. }
  322. /**
  323. * @brief Navigation callback to bring the user back to the Friends submenu
  324. * @param context The context - unused
  325. * @return next view id (FlipSocialViewLoggedInFriendsSubmenu)
  326. */
  327. uint32_t flip_social_callback_to_friends_logged_in(void *context)
  328. {
  329. UNUSED(context);
  330. flip_social_dialog_stop = false;
  331. flip_social_dialog_shown = false;
  332. flip_social_friends->index = 0;
  333. return FlipSocialViewSubmenu;
  334. }
  335. /**
  336. * @brief Navigation callback to bring the user back to the Messages submenu
  337. * @param context The context - unused
  338. * @return next view id (FlipSocialViewLoggedInMessagesSubmenu)
  339. */
  340. uint32_t flip_social_callback_to_messages_logged_in(void *context)
  341. {
  342. UNUSED(context);
  343. return FlipSocialViewSubmenu;
  344. }
  345. /**
  346. * @brief Navigation callback to bring the user back to the User Choices screen
  347. * @param context The context - unused
  348. * @return next view id (FlipSocialViewLoggedInMessagesUserChoices)
  349. */
  350. uint32_t flip_social_callback_to_messages_user_choices(void *context)
  351. {
  352. UNUSED(context);
  353. return FlipSocialViewSubmenu;
  354. }
  355. /**
  356. * @brief Navigation callback for exiting the application
  357. * @param context The context - unused
  358. * @return next view id (VIEW_NONE to exit the app)
  359. */
  360. uint32_t flip_social_callback_exit_app(void *context)
  361. {
  362. // Exit the application
  363. UNUSED(context);
  364. free_all(true, true);
  365. return VIEW_NONE;
  366. }
  367. static void explore_dialog_callback(DialogExResult result, void *context)
  368. {
  369. furi_assert(context);
  370. FlipSocialApp *app = (FlipSocialApp *)context;
  371. if (result == DialogExResultLeft) // Remove
  372. {
  373. if (flipper_http_init(flipper_http_rx_callback, app_instance))
  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_explore->usernames[flip_social_explore->index]);
  378. auth_headers_alloc();
  379. flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/remove-friend/", auth_headers, remove_payload);
  380. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  381. flip_social_free_explore_dialog();
  382. furi_delay_ms(1000);
  383. flipper_http_deinit();
  384. }
  385. }
  386. else if (result == DialogExResultRight)
  387. {
  388. if (flipper_http_init(flipper_http_rx_callback, app_instance))
  389. {
  390. // add friend
  391. char add_payload[128];
  392. snprintf(add_payload, sizeof(add_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_explore->usernames[flip_social_explore->index]);
  393. auth_headers_alloc();
  394. flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/add-friend/", auth_headers, add_payload);
  395. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  396. flip_social_free_explore_dialog();
  397. furi_delay_ms(1000);
  398. flipper_http_deinit();
  399. }
  400. }
  401. }
  402. static void friends_dialog_callback(DialogExResult result, void *context)
  403. {
  404. furi_assert(context);
  405. FlipSocialApp *app = (FlipSocialApp *)context;
  406. if (result == DialogExResultLeft) // Remove
  407. {
  408. if (flipper_http_init(flipper_http_rx_callback, app_instance))
  409. {
  410. // remove friend
  411. char remove_payload[128];
  412. snprintf(remove_payload, sizeof(remove_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_friends->usernames[flip_social_friends->index]);
  413. auth_headers_alloc();
  414. flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/remove-friend/", auth_headers, remove_payload);
  415. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  416. flip_social_free_friends_dialog();
  417. furi_delay_ms(1000);
  418. flipper_http_deinit();
  419. }
  420. }
  421. }
  422. void messages_dialog_callback(DialogExResult result, void *context)
  423. {
  424. furi_assert(context);
  425. FlipSocialApp *app = (FlipSocialApp *)context;
  426. if (result == DialogExResultLeft) // Previous message
  427. {
  428. if (flip_social_messages->index > 0)
  429. {
  430. flip_social_messages->index--;
  431. dialog_ex_reset(app->dialog_messages);
  432. dialog_ex_set_header(app->dialog_messages, flip_social_messages->usernames[flip_social_messages->index], 0, 0, AlignLeft, AlignTop);
  433. dialog_ex_set_text(app->dialog_messages, updated_user_message(flip_social_messages->messages[flip_social_messages->index]), 0, 10, AlignLeft, AlignTop);
  434. if (flip_social_messages->index != 0)
  435. {
  436. dialog_ex_set_left_button_text(app->dialog_messages, "Prev");
  437. }
  438. dialog_ex_set_right_button_text(app->dialog_messages, "Next");
  439. dialog_ex_set_center_button_text(app->dialog_messages, "Create");
  440. // switch view, free dialog, re-alloc dialog, switch back to dialog
  441. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewWidgetResult);
  442. flip_social_free_messages_dialog();
  443. messages_dialog_alloc(false);
  444. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewMessagesDialog);
  445. }
  446. }
  447. else if (result == DialogExResultRight) // Next message
  448. {
  449. if (flip_social_messages->index < flip_social_messages->count - 1)
  450. {
  451. flip_social_messages->index++;
  452. dialog_ex_reset(app->dialog_messages);
  453. dialog_ex_set_header(app->dialog_messages, flip_social_messages->usernames[flip_social_messages->index], 0, 0, AlignLeft, AlignTop);
  454. dialog_ex_set_text(app->dialog_messages, updated_user_message(flip_social_messages->messages[flip_social_messages->index]), 0, 10, AlignLeft, AlignTop);
  455. dialog_ex_set_left_button_text(app->dialog_messages, "Prev");
  456. if (flip_social_messages->index != flip_social_messages->count - 1)
  457. {
  458. dialog_ex_set_right_button_text(app->dialog_messages, "Next");
  459. }
  460. dialog_ex_set_center_button_text(app->dialog_messages, "Create");
  461. // switch view, free dialog, re-alloc dialog, switch back to dialog
  462. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewWidgetResult);
  463. flip_social_free_messages_dialog();
  464. messages_dialog_alloc(false);
  465. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewMessagesDialog);
  466. }
  467. }
  468. else if (result == DialogExResultCenter) // new message
  469. {
  470. free_text_input();
  471. if (!alloc_text_input(FlipSocialViewLoggedInMessagesNewMessageInput))
  472. {
  473. FURI_LOG_E(TAG, "Failed to allocate text input");
  474. return;
  475. }
  476. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  477. }
  478. }
  479. static void compose_dialog_callback(DialogExResult result, void *context)
  480. {
  481. furi_assert(context);
  482. FlipSocialApp *app = (FlipSocialApp *)context;
  483. if (result == DialogExResultLeft) // Delete
  484. {
  485. // Ensure index is within bounds
  486. if (app_instance->pre_saved_messages.index >= app_instance->pre_saved_messages.count)
  487. {
  488. FURI_LOG_E(TAG, "Invalid index for deletion: %zu", app_instance->pre_saved_messages.index);
  489. return;
  490. }
  491. // Shift messages to remove the selected message
  492. for (size_t i = app_instance->pre_saved_messages.index; i < app_instance->pre_saved_messages.count - 1; i++)
  493. {
  494. strncpy(app_instance->pre_saved_messages.messages[i],
  495. app_instance->pre_saved_messages.messages[i + 1],
  496. MAX_MESSAGE_LENGTH);
  497. }
  498. // Clear the last message after shifting
  499. memset(app_instance->pre_saved_messages.messages[app_instance->pre_saved_messages.count - 1], 0, MAX_MESSAGE_LENGTH);
  500. app_instance->pre_saved_messages.count--;
  501. // Reset and rebuild the submenu
  502. submenu_reset(app_instance->submenu);
  503. submenu_add_item(app_instance->submenu, "Add Pre-Save", FlipSocialSubmenuComposeIndexAddPreSave, flip_social_callback_submenu_choices, app);
  504. for (size_t i = 0; i < app_instance->pre_saved_messages.count; i++)
  505. {
  506. submenu_add_item(app_instance->submenu,
  507. app_instance->pre_saved_messages.messages[i],
  508. FlipSocialSubemnuComposeIndexStartIndex + i,
  509. flip_social_callback_submenu_choices,
  510. app);
  511. }
  512. // Save the updated playlist
  513. save_playlist(&app_instance->pre_saved_messages);
  514. // Switch back to the compose view
  515. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  516. // Free the dialog resources
  517. flip_social_free_compose_dialog();
  518. }
  519. else if (result == DialogExResultRight) // Post
  520. {
  521. // post the message
  522. // send selected_message
  523. if (!flipper_http_init(flipper_http_rx_callback, app_instance))
  524. {
  525. FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
  526. return;
  527. }
  528. if (selected_message && app_instance->login_username_logged_in)
  529. {
  530. if (strlen(selected_message) > MAX_MESSAGE_LENGTH)
  531. {
  532. FURI_LOG_E(TAG, "Message is too long");
  533. flipper_http_deinit();
  534. return;
  535. }
  536. // Send the selected_message
  537. char command[256];
  538. snprintf(command, sizeof(command), "{\"username\":\"%s\",\"content\":\"%s\"}",
  539. app_instance->login_username_logged_in, selected_message);
  540. if (!flipper_http_post_request_with_headers(
  541. "https://www.flipsocial.net/api/feed/post/",
  542. auth_headers,
  543. command))
  544. {
  545. FURI_LOG_E(TAG, "Failed to send HTTP request for feed");
  546. flipper_http_deinit();
  547. return;
  548. }
  549. fhttp.state = RECEIVING;
  550. furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
  551. }
  552. else
  553. {
  554. FURI_LOG_E(TAG, "Message or username is NULL");
  555. flipper_http_deinit();
  556. return;
  557. }
  558. while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
  559. {
  560. furi_delay_ms(100);
  561. }
  562. if (flip_social_load_initial_feed(false, 1))
  563. {
  564. flip_social_free_compose_dialog();
  565. }
  566. else
  567. {
  568. FURI_LOG_E(TAG, "Failed to load the initial feed");
  569. flipper_http_deinit();
  570. }
  571. }
  572. }
  573. void feed_dialog_callback(DialogExResult result, void *context)
  574. {
  575. furi_assert(context);
  576. FlipSocialApp *app = (FlipSocialApp *)context;
  577. if (result == DialogExResultLeft) // Previous message
  578. {
  579. if (flip_feed_info->index > 0)
  580. {
  581. flip_feed_info->index--;
  582. }
  583. // switch view, free dialog, re-alloc dialog, switch back to dialog
  584. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewWidgetResult);
  585. flip_social_free_feed_view();
  586. // load feed item
  587. if (!flip_social_load_feed_post(flip_feed_info->ids[flip_feed_info->index]))
  588. {
  589. FURI_LOG_E(TAG, "Failed to load nexy feed post");
  590. fhttp.state = ISSUE;
  591. return;
  592. }
  593. if (feed_view_alloc())
  594. {
  595. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
  596. }
  597. else
  598. {
  599. FURI_LOG_E(TAG, "Failed to allocate feed dialog");
  600. fhttp.state = ISSUE;
  601. return;
  602. }
  603. }
  604. else if (result == DialogExResultRight) // Next message
  605. {
  606. if (flip_feed_info->index < flip_feed_info->count - 1)
  607. {
  608. flip_feed_info->index++;
  609. }
  610. // switch view, free dialog, re-alloc dialog, switch back to dialog
  611. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewWidgetResult);
  612. flip_social_free_feed_view();
  613. // load feed item
  614. if (!flip_social_load_feed_post(flip_feed_info->ids[flip_feed_info->index]))
  615. {
  616. FURI_LOG_E(TAG, "Failed to load nexy feed post");
  617. fhttp.state = ISSUE;
  618. return;
  619. }
  620. if (feed_view_alloc())
  621. {
  622. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
  623. }
  624. else
  625. {
  626. FURI_LOG_E(TAG, "Failed to allocate feed dialog");
  627. fhttp.state = ISSUE;
  628. return;
  629. }
  630. }
  631. else if (result == DialogExResultCenter) // Flip/Unflip
  632. {
  633. // Moved to above the is_flipped check
  634. if (!flip_feed_item->is_flipped)
  635. {
  636. // increase the flip count
  637. flip_feed_item->flips++;
  638. }
  639. else
  640. {
  641. // decrease the flip count
  642. flip_feed_item->flips--;
  643. }
  644. // change the flip status
  645. flip_feed_item->is_flipped = !flip_feed_item->is_flipped;
  646. // send post request to flip the message
  647. if (app_instance->login_username_logged_in == NULL)
  648. {
  649. FURI_LOG_E(TAG, "Username is NULL");
  650. return;
  651. }
  652. if (!flipper_http_init(flipper_http_rx_callback, app_instance))
  653. {
  654. FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
  655. return;
  656. }
  657. auth_headers_alloc();
  658. char payload[256];
  659. snprintf(payload, sizeof(payload), "{\"username\":\"%s\",\"post_id\":\"%u\"}", app_instance->login_username_logged_in, flip_feed_item->id);
  660. if (flipper_http_post_request_with_headers("https://www.flipsocial.net/api/feed/flip/", auth_headers, payload))
  661. {
  662. // save feed item
  663. char new_save[256];
  664. snprintf(new_save, sizeof(new_save), "{\"id\":%u,\"username\":\"%s\",\"message\":\"%s\",\"flip_count\":%u,\"flipped\":%s}",
  665. flip_feed_item->id, flip_feed_item->username, flip_feed_item->message, flip_feed_item->flips, flip_feed_item->is_flipped ? "true" : "false");
  666. // if (!flip_social_save_post((char *)flip_feed_item->id, new_save))
  667. // {
  668. // FURI_LOG_E(TAG, "Failed to save the feed post");
  669. // fhttp.state = ISSUE;
  670. // return;
  671. // }
  672. }
  673. // switch view, free dialog, re-alloc dialog, switch back to dialog
  674. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewWidgetResult);
  675. flip_social_free_feed_view();
  676. if (feed_view_alloc())
  677. {
  678. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
  679. }
  680. else
  681. {
  682. FURI_LOG_E(TAG, "Failed to allocate feed dialog");
  683. }
  684. furi_delay_ms(1000);
  685. flipper_http_deinit();
  686. }
  687. }
  688. static bool flip_social_get_user_info()
  689. {
  690. if (!flipper_http_init(flipper_http_rx_callback, app_instance))
  691. {
  692. FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
  693. fhttp.state = ISSUE;
  694. return false;
  695. }
  696. char url[256];
  697. snprintf(url, sizeof(url), "https://www.flipsocial.net/api/user/users/%s/extended/", flip_social_explore->usernames[flip_social_explore->index]);
  698. if (!flipper_http_get_request_with_headers(url, auth_headers))
  699. {
  700. FURI_LOG_E(TAG, "Failed to send HTTP request for user info");
  701. fhttp.state = ISSUE;
  702. return false;
  703. }
  704. fhttp.state = RECEIVING;
  705. return true;
  706. }
  707. static bool flip_social_parse_user_info()
  708. {
  709. if (fhttp.last_response == NULL)
  710. {
  711. FURI_LOG_E(TAG, "Response is NULL");
  712. return false;
  713. }
  714. if (!app_instance->explore_user_bio)
  715. {
  716. FURI_LOG_E(TAG, "App instance is NULL");
  717. return false;
  718. }
  719. char *bio = get_json_value("bio", fhttp.last_response);
  720. char *friends = get_json_value("friends", fhttp.last_response);
  721. bool parse_success = false;
  722. if (bio && friends)
  723. {
  724. if (strlen(bio) != 0)
  725. {
  726. snprintf(app_instance->explore_user_bio, MAX_MESSAGE_LENGTH, "%s (%s friends)", bio, friends);
  727. }
  728. else
  729. {
  730. snprintf(app_instance->explore_user_bio, MAX_MESSAGE_LENGTH, "%s friends", friends);
  731. }
  732. free(bio);
  733. free(friends);
  734. parse_success = true;
  735. }
  736. flipper_http_deinit();
  737. return parse_success;
  738. }
  739. /**
  740. * @brief Handle ALL submenu item selections.
  741. * @param context The context - FlipSocialApp object.
  742. * @param index The FlipSocialSubmenuIndex item that was clicked.
  743. * @return void
  744. */
  745. void flip_social_callback_submenu_choices(void *context, uint32_t index)
  746. {
  747. FlipSocialApp *app = (FlipSocialApp *)context;
  748. if (!app)
  749. {
  750. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  751. return;
  752. }
  753. switch (index)
  754. {
  755. case FlipSocialSubmenuLoggedOutIndexLogin:
  756. flip_social_sent_login_request = false;
  757. flip_social_login_success = false;
  758. free_all(true, true);
  759. if (!alloc_variable_item_list(FlipSocialViewLoggedOutLogin))
  760. {
  761. FURI_LOG_E(TAG, "Failed to allocate variable item list");
  762. return;
  763. }
  764. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  765. break;
  766. case FlipSocialSubmenuLoggedOutIndexRegister:
  767. flip_social_sent_register_request = false;
  768. flip_social_register_success = false;
  769. free_all(true, true);
  770. if (!alloc_variable_item_list(FlipSocialViewLoggedOutRegister))
  771. {
  772. FURI_LOG_E(TAG, "Failed to allocate variable item list");
  773. return;
  774. }
  775. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  776. break;
  777. case FlipSocialSubmenuLoggedOutIndexAbout:
  778. if (!about_widget_alloc(false))
  779. {
  780. return;
  781. }
  782. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutAbout);
  783. break;
  784. case FlipSocialSubmenuLoggedOutIndexWifiSettings:
  785. free_all(false, false);
  786. if (!alloc_variable_item_list(FlipSocialViewLoggedOutWifiSettings))
  787. {
  788. FURI_LOG_E(TAG, "Failed to allocate text input");
  789. return;
  790. }
  791. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  792. break;
  793. case FlipSocialSubmenuLoggedInIndexProfile:
  794. free_all(true, true);
  795. if (!alloc_variable_item_list(FlipSocialViewLoggedInProfile))
  796. {
  797. FURI_LOG_E(TAG, "Failed to allocate variable item list");
  798. return;
  799. }
  800. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  801. break;
  802. case FlipSocialSubmenuLoggedInIndexMessages:
  803. free_all(true, true);
  804. if (!alloc_submenu(FlipSocialViewLoggedInMessagesSubmenu))
  805. {
  806. FURI_LOG_E(TAG, "Failed to allocate submenu");
  807. return;
  808. }
  809. flipper_http_loading_task(
  810. flip_social_get_message_users, // get the message users
  811. flip_social_parse_json_message_users, // parse the message users
  812. FlipSocialViewSubmenu, // switch to the messages submenu if successful
  813. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  814. &app->view_dispatcher); // view dispatcher
  815. break;
  816. case FlipSocialSubmenuLoggedInIndexMessagesNewMessage:
  817. // they need to search for the user to send a message
  818. free_text_input();
  819. if (!alloc_text_input(FlipSocialViewLoggedInMessageUsersInput))
  820. {
  821. FURI_LOG_E(TAG, "Failed to allocate text input");
  822. return;
  823. }
  824. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  825. break;
  826. case FlipSocialSubmenuLoggedInIndexFeed:
  827. free_all(true, true);
  828. if (!flip_social_load_initial_feed(true, 1))
  829. {
  830. FURI_LOG_E(TAG, "Failed to load the initial feed");
  831. return;
  832. }
  833. break;
  834. case FlipSocialSubmenuExploreIndex:
  835. free_all(true, true);
  836. if (!alloc_text_input(FlipSocialViewLoggedInExploreInput))
  837. {
  838. FURI_LOG_E(TAG, "Failed to allocate text input");
  839. return;
  840. }
  841. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  842. break;
  843. case FlipSocialSubmenuLoggedInIndexCompose:
  844. free_all(true, true);
  845. if (!alloc_submenu(FlipSocialViewLoggedInCompose))
  846. {
  847. FURI_LOG_E(TAG, "Failed to allocate submenu");
  848. return;
  849. }
  850. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  851. break;
  852. case FlipSocialSubmenuLoggedInIndexSettings:
  853. free_all(true, true);
  854. if (!alloc_submenu(FlipSocialViewLoggedInSettings))
  855. {
  856. FURI_LOG_E(TAG, "Failed to allocate submenu");
  857. return;
  858. }
  859. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  860. break;
  861. case FlipSocialSubmenuLoggedInIndexAbout:
  862. free_all(true, false);
  863. if (!about_widget_alloc(true))
  864. {
  865. FURI_LOG_E(TAG, "Failed to allocate about widget");
  866. return;
  867. }
  868. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsAbout);
  869. break;
  870. case FlipSocialSubmenuLoggedInIndexWifiSettings:
  871. free_all(true, false);
  872. if (!alloc_variable_item_list(FlipSocialViewLoggedInSettingsWifi))
  873. {
  874. FURI_LOG_E(TAG, "Failed to allocate variable item list");
  875. return;
  876. }
  877. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  878. break;
  879. case FlipSocialSubmenuLoggedInIndexUserSettings:
  880. free_all(true, false);
  881. if (!alloc_variable_item_list(FlipSocialViewLoggedInSettingsUser))
  882. {
  883. FURI_LOG_E(TAG, "Failed to allocate variable item list");
  884. return;
  885. }
  886. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  887. break;
  888. case FlipSocialSubmenuLoggedInSignOutButton:
  889. free_all(true, true);
  890. app->is_logged_in = "false";
  891. 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);
  892. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutSubmenu);
  893. break;
  894. case FlipSocialSubmenuComposeIndexAddPreSave:
  895. free_text_input();
  896. if (!alloc_text_input(FlipSocialViewLoggedInComposeAddPreSaveInput))
  897. {
  898. FURI_LOG_E(TAG, "Failed to allocate text input");
  899. return;
  900. }
  901. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  902. break;
  903. default:
  904. // Handle the pre-saved message selection (has a max of 25 items)
  905. if (index >= FlipSocialSubemnuComposeIndexStartIndex && index < FlipSocialSubemnuComposeIndexStartIndex + MAX_PRE_SAVED_MESSAGES)
  906. {
  907. app->pre_saved_messages.index = index - FlipSocialSubemnuComposeIndexStartIndex;
  908. snprintf(selected_message, MAX_MESSAGE_LENGTH, "%s", app->pre_saved_messages.messages[app->pre_saved_messages.index]);
  909. if (!selected_message)
  910. {
  911. FURI_LOG_E(TAG, "Selected message is NULL");
  912. return;
  913. }
  914. flip_social_free_compose_dialog();
  915. if (!app->dialog_compose)
  916. {
  917. if (!easy_flipper_set_dialog_ex(
  918. &app->dialog_compose,
  919. FlipSocialViewComposeDialog,
  920. "New Feed Post",
  921. 0,
  922. 0,
  923. updated_user_message(selected_message),
  924. 0,
  925. 10,
  926. "Delete",
  927. "Post",
  928. NULL,
  929. compose_dialog_callback,
  930. flip_social_callback_to_compose_logged_in,
  931. &app->view_dispatcher,
  932. app))
  933. {
  934. return;
  935. }
  936. }
  937. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewComposeDialog);
  938. }
  939. // Handle the explore selection
  940. else if (index >= FlipSocialSubmenuExploreIndexStartIndex && index < FlipSocialSubmenuExploreIndexStartIndex + MAX_EXPLORE_USERS)
  941. {
  942. if (!flip_social_explore)
  943. {
  944. FURI_LOG_E(TAG, "FlipSocialExplore is NULL");
  945. return;
  946. }
  947. flip_social_explore->index = index - FlipSocialSubmenuExploreIndexStartIndex;
  948. // loading task to get the user info
  949. if (app->explore_user_bio)
  950. {
  951. free(app->explore_user_bio);
  952. app->explore_user_bio = NULL;
  953. }
  954. if (!easy_flipper_set_buffer(&app->explore_user_bio, MAX_MESSAGE_LENGTH))
  955. {
  956. return;
  957. }
  958. if (flipper_http_process_response_async(flip_social_get_user_info, flip_social_parse_user_info))
  959. {
  960. flip_social_free_explore_dialog();
  961. if (!app->dialog_explore)
  962. {
  963. if (!easy_flipper_set_dialog_ex(
  964. &app->dialog_explore,
  965. FlipSocialViewExploreDialog,
  966. flip_social_explore->usernames[flip_social_explore->index],
  967. 0,
  968. 0,
  969. updated_user_message(app->explore_user_bio),
  970. 0,
  971. 10,
  972. "Remove", // remove if user is a friend (future update)
  973. "Add", // add if user is not a friend (future update)
  974. NULL,
  975. explore_dialog_callback,
  976. flip_social_callback_to_explore_logged_in,
  977. &app->view_dispatcher,
  978. app))
  979. {
  980. return;
  981. }
  982. }
  983. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewExploreDialog);
  984. }
  985. else
  986. {
  987. flip_social_free_explore_dialog();
  988. if (!app->dialog_explore)
  989. {
  990. if (!easy_flipper_set_dialog_ex(
  991. &app->dialog_explore,
  992. FlipSocialViewExploreDialog,
  993. flip_social_explore->usernames[flip_social_explore->index],
  994. 0,
  995. 0,
  996. "",
  997. 0,
  998. 10,
  999. "Remove", // remove if user is a friend (future update)
  1000. "Add", // add if user is not a friend (future update)
  1001. NULL,
  1002. explore_dialog_callback,
  1003. flip_social_callback_to_explore_logged_in,
  1004. &app->view_dispatcher,
  1005. app))
  1006. {
  1007. return;
  1008. }
  1009. }
  1010. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewExploreDialog);
  1011. }
  1012. }
  1013. // handle the friends selection
  1014. else if (index >= FlipSocialSubmenuLoggedInIndexFriendsStart && index < FlipSocialSubmenuLoggedInIndexFriendsStart + MAX_FRIENDS)
  1015. {
  1016. if (!flip_social_friends)
  1017. {
  1018. FURI_LOG_E(TAG, "FlipSocialFriends is NULL");
  1019. return;
  1020. }
  1021. flip_social_friends->index = index - FlipSocialSubmenuLoggedInIndexFriendsStart;
  1022. flip_social_free_friends_dialog();
  1023. if (!app->dialog_friends)
  1024. {
  1025. if (!easy_flipper_set_dialog_ex(
  1026. &app->dialog_friends,
  1027. FlipSocialViewFriendsDialog,
  1028. "Friend Options",
  1029. 0,
  1030. 0,
  1031. flip_social_friends->usernames[flip_social_friends->index],
  1032. 0,
  1033. 10,
  1034. "Remove",
  1035. "",
  1036. NULL,
  1037. friends_dialog_callback,
  1038. flip_social_callback_to_friends_logged_in,
  1039. &app->view_dispatcher,
  1040. app))
  1041. {
  1042. return;
  1043. }
  1044. }
  1045. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewFriendsDialog);
  1046. }
  1047. // handle the messages selection
  1048. else if (index >= FlipSocialSubmenuLoggedInIndexMessagesUsersStart && index < FlipSocialSubmenuLoggedInIndexMessagesUsersStart + MAX_MESSAGE_USERS)
  1049. {
  1050. if (!flip_social_message_users)
  1051. {
  1052. FURI_LOG_E(TAG, "FlipSocialMessageUsers is NULL");
  1053. return;
  1054. }
  1055. flip_social_message_users->index = index - FlipSocialSubmenuLoggedInIndexMessagesUsersStart;
  1056. flipper_http_loading_task(
  1057. flip_social_get_messages_with_user, // get the messages with the selected user
  1058. flip_social_parse_json_messages, // parse the messages
  1059. FlipSocialViewMessagesDialog, // switch to the messages process if successful
  1060. FlipSocialViewLoggedInMessagesSubmenu, // switch back to the messages submenu if failed
  1061. &app->view_dispatcher // view dispatcher
  1062. );
  1063. }
  1064. // handle the messages user choices selection
  1065. else if (index >= FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart && index < FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart + MAX_EXPLORE_USERS)
  1066. {
  1067. if (!flip_social_explore)
  1068. {
  1069. FURI_LOG_E(TAG, "FlipSocialExplore is NULL");
  1070. return;
  1071. }
  1072. flip_social_explore->index = index - FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart;
  1073. free_text_input();
  1074. if (!alloc_text_input(FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput))
  1075. {
  1076. FURI_LOG_E(TAG, "Failed to allocate text input");
  1077. return;
  1078. } // switch to the text input view
  1079. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1080. }
  1081. else
  1082. {
  1083. FURI_LOG_E(TAG, "Unknown submenu index");
  1084. }
  1085. break;
  1086. }
  1087. }
  1088. /**
  1089. * @brief Text input callback for when the user finishes entering their SSID on the wifi settings (logged out) screen.
  1090. * @param context The context - FlipSocialApp object.
  1091. * @return void
  1092. */
  1093. void flip_social_logged_out_wifi_settings_ssid_updated(void *context)
  1094. {
  1095. FlipSocialApp *app = (FlipSocialApp *)context;
  1096. if (!app)
  1097. {
  1098. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1099. return;
  1100. }
  1101. // Store the entered name
  1102. strncpy(app->wifi_ssid_logged_out, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  1103. // Store the entered name in the logged in name field
  1104. strncpy(app->wifi_ssid_logged_in, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  1105. strncpy(app->wifi_ssid_logged_in_temp_buffer, app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_out_temp_buffer_size);
  1106. // Ensure null-termination
  1107. app->wifi_ssid_logged_out[app->wifi_ssid_logged_out_temp_buffer_size - 1] = '\0';
  1108. // Update the name item text
  1109. if (app->variable_item_logged_out_wifi_settings_ssid)
  1110. {
  1111. variable_item_set_current_value_text(app->variable_item_logged_out_wifi_settings_ssid, app->wifi_ssid_logged_out);
  1112. }
  1113. // update the wifi settings
  1114. if (strlen(app->wifi_ssid_logged_out) > 0 && strlen(app->wifi_password_logged_out) > 0)
  1115. {
  1116. if (flipper_http_init(flipper_http_rx_callback, app_instance))
  1117. {
  1118. if (!flipper_http_save_wifi(app->wifi_ssid_logged_out, app->wifi_password_logged_out))
  1119. {
  1120. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  1121. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1122. }
  1123. furi_delay_ms(500);
  1124. flipper_http_deinit();
  1125. }
  1126. }
  1127. // Save the settings
  1128. 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);
  1129. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  1130. }
  1131. /**
  1132. * @brief Text input callback for when the user finishes entering their password on the wifi settings (logged out) screen.
  1133. * @param context The context - FlipSocialApp object.
  1134. * @return void
  1135. */
  1136. void flip_social_logged_out_wifi_settings_password_updated(void *context)
  1137. {
  1138. FlipSocialApp *app = (FlipSocialApp *)context;
  1139. if (!app)
  1140. {
  1141. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1142. return;
  1143. }
  1144. // Store the entered WiFi password
  1145. strncpy(app->wifi_password_logged_out, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  1146. // Store the entered WiFi password in the logged in password field
  1147. strncpy(app->wifi_password_logged_in, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  1148. strncpy(app->wifi_password_logged_in_temp_buffer, app->wifi_password_logged_out_temp_buffer, app->wifi_password_logged_out_temp_buffer_size);
  1149. // Ensure null-termination
  1150. app->wifi_password_logged_out[app->wifi_password_logged_out_temp_buffer_size - 1] = '\0';
  1151. // Update the password item text
  1152. if (app->variable_item_logged_out_wifi_settings_password)
  1153. {
  1154. variable_item_set_current_value_text(app->variable_item_logged_out_wifi_settings_password, app->wifi_password_logged_out);
  1155. }
  1156. // update the wifi settings
  1157. if (strlen(app->wifi_ssid_logged_out) > 0 && strlen(app->wifi_password_logged_out) > 0)
  1158. {
  1159. if (flipper_http_init(flipper_http_rx_callback, app_instance))
  1160. {
  1161. if (!flipper_http_save_wifi(app->wifi_ssid_logged_out, app->wifi_password_logged_out))
  1162. {
  1163. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  1164. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1165. }
  1166. furi_delay_ms(500);
  1167. flipper_http_deinit();
  1168. }
  1169. }
  1170. // Save the settings
  1171. 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);
  1172. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  1173. }
  1174. /**
  1175. * @brief Callback when the user selects a menu item in the wifi settings (logged out) screen.
  1176. * @param context The context - FlipSocialApp object.
  1177. * @param index The index of the selected item.
  1178. * @return void
  1179. */
  1180. void flip_social_text_input_logged_out_wifi_settings_item_selected(void *context, uint32_t index)
  1181. {
  1182. FlipSocialApp *app = (FlipSocialApp *)context;
  1183. if (!app)
  1184. {
  1185. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1186. return;
  1187. }
  1188. switch (index)
  1189. {
  1190. case 0: // Input SSID
  1191. // view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsSSIDInput);
  1192. free_text_input();
  1193. if (!alloc_text_input(FlipSocialViewLoggedOutWifiSettingsSSIDInput))
  1194. {
  1195. FURI_LOG_E(TAG, "Failed to allocate text input");
  1196. return;
  1197. }
  1198. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1199. break;
  1200. case 1: // Input Password
  1201. // view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsPasswordInput);
  1202. free_text_input();
  1203. if (!alloc_text_input(FlipSocialViewLoggedOutWifiSettingsPasswordInput))
  1204. {
  1205. FURI_LOG_E(TAG, "Failed to allocate text input");
  1206. return;
  1207. }
  1208. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1209. break;
  1210. default:
  1211. FURI_LOG_E(TAG, "Unknown configuration item index");
  1212. break;
  1213. }
  1214. }
  1215. /**
  1216. * @brief Text input callback for when the user finishes entering their username on the login (logged out) screen.
  1217. * @param context The context - FlipSocialApp object.
  1218. * @return void
  1219. */
  1220. void flip_social_logged_out_login_username_updated(void *context)
  1221. {
  1222. FlipSocialApp *app = (FlipSocialApp *)context;
  1223. if (!app)
  1224. {
  1225. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1226. return;
  1227. }
  1228. // Store the entered name
  1229. strncpy(app->login_username_logged_out, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  1230. // Store the entered name in the logged in username field
  1231. strncpy(app->login_username_logged_in, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  1232. strncpy(app->login_username_logged_in_temp_buffer, app->login_username_logged_out_temp_buffer, app->login_username_logged_out_temp_buffer_size);
  1233. // Ensure null-termination
  1234. app->login_username_logged_out[app->login_username_logged_out_temp_buffer_size - 1] = '\0';
  1235. // Update the name item text
  1236. if (app->variable_item_logged_out_login_username)
  1237. {
  1238. variable_item_set_current_value_text(app->variable_item_logged_out_login_username, app->login_username_logged_out);
  1239. }
  1240. // Save the settings
  1241. 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);
  1242. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  1243. }
  1244. /**
  1245. * @brief Text input callback for when the user finishes entering their password on the login (logged out) screen.
  1246. * @param context The context - FlipSocialApp object.
  1247. * @return void
  1248. */
  1249. void flip_social_logged_out_login_password_updated(void *context)
  1250. {
  1251. FlipSocialApp *app = (FlipSocialApp *)context;
  1252. if (!app)
  1253. {
  1254. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1255. return;
  1256. }
  1257. // Store the entered password
  1258. strncpy(app->login_password_logged_out, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  1259. // Store the entered password in the change password field
  1260. strncpy(app->change_password_logged_in, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  1261. strncpy(app->change_password_logged_in_temp_buffer, app->login_password_logged_out_temp_buffer, app->login_password_logged_out_temp_buffer_size);
  1262. // Ensure null-termination
  1263. app->login_password_logged_out[app->login_password_logged_out_temp_buffer_size - 1] = '\0';
  1264. // Update the password item text
  1265. if (app->variable_item_logged_out_login_password)
  1266. {
  1267. // dont show the password on the screen (version 0.2)
  1268. // variable_item_set_current_value_text(app->variable_item_logged_out_login_password, app->login_password_logged_out);
  1269. }
  1270. // Save the settings
  1271. 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);
  1272. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  1273. }
  1274. /**
  1275. * @brief Callback when the user selects a menu item in the login (logged out) screen.
  1276. * @param context The context - FlipSocialApp object.
  1277. * @param index The index of the selected item.
  1278. * @return void
  1279. */
  1280. void flip_social_text_input_logged_out_login_item_selected(void *context, uint32_t index)
  1281. {
  1282. FlipSocialApp *app = (FlipSocialApp *)context;
  1283. if (!app)
  1284. {
  1285. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1286. return;
  1287. }
  1288. switch (index)
  1289. {
  1290. case 0: // Input Username
  1291. // view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginUsernameInput);
  1292. free_all(false, true);
  1293. if (!alloc_text_input(FlipSocialViewLoggedOutLoginUsernameInput))
  1294. {
  1295. FURI_LOG_E(TAG, "Failed to allocate text input");
  1296. return;
  1297. }
  1298. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1299. break;
  1300. case 1: // Input Password
  1301. // view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginPasswordInput);
  1302. free_all(false, true);
  1303. if (!alloc_text_input(FlipSocialViewLoggedOutLoginPasswordInput))
  1304. {
  1305. FURI_LOG_E(TAG, "Failed to allocate text input");
  1306. return;
  1307. }
  1308. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1309. break;
  1310. case 2: // Login Button
  1311. if (!flipper_http_init(flipper_http_rx_callback, app_instance))
  1312. {
  1313. FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
  1314. return;
  1315. }
  1316. flip_social_login_switch_to_view(app);
  1317. break;
  1318. default:
  1319. FURI_LOG_E(TAG, "Unknown configuration item index");
  1320. break;
  1321. }
  1322. }
  1323. /**
  1324. * @brief Text input callback for when the user finishes entering their username on the register (logged out) screen.
  1325. * @param context The context - FlipSocialApp object.
  1326. * @return void
  1327. */
  1328. void flip_social_logged_out_register_username_updated(void *context)
  1329. {
  1330. FlipSocialApp *app = (FlipSocialApp *)context;
  1331. if (!app)
  1332. {
  1333. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1334. return;
  1335. }
  1336. // Store the entered name
  1337. strncpy(app->register_username_logged_out, app->register_username_logged_out_temp_buffer, app->register_username_logged_out_temp_buffer_size);
  1338. // Ensure null-termination
  1339. app->register_username_logged_out[app->register_username_logged_out_temp_buffer_size - 1] = '\0';
  1340. // Update the name item text
  1341. if (app->variable_item_logged_out_register_username)
  1342. {
  1343. variable_item_set_current_value_text(app->variable_item_logged_out_register_username, app->register_username_logged_out);
  1344. }
  1345. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  1346. }
  1347. /**
  1348. * @brief Text input callback for when the user finishes entering their password on the register (logged out) screen.
  1349. * @param context The context - FlipSocialApp object.
  1350. * @return void
  1351. */
  1352. void flip_social_logged_out_register_password_updated(void *context)
  1353. {
  1354. FlipSocialApp *app = (FlipSocialApp *)context;
  1355. if (!app)
  1356. {
  1357. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1358. return;
  1359. }
  1360. // Store the entered password
  1361. strncpy(app->register_password_logged_out, app->register_password_logged_out_temp_buffer, app->register_password_logged_out_temp_buffer_size);
  1362. // Ensure null-termination
  1363. app->register_password_logged_out[app->register_password_logged_out_temp_buffer_size - 1] = '\0';
  1364. // Update the password item text
  1365. if (app->variable_item_logged_out_register_password)
  1366. {
  1367. variable_item_set_current_value_text(app->variable_item_logged_out_register_password, app->register_password_logged_out);
  1368. }
  1369. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  1370. }
  1371. /**
  1372. * @brief Text input callback for when the user finishes entering their password 2 on the register (logged out) screen.
  1373. * @param context The context - FlipSocialApp object.
  1374. * @return void
  1375. */
  1376. void flip_social_logged_out_register_password_2_updated(void *context)
  1377. {
  1378. FlipSocialApp *app = (FlipSocialApp *)context;
  1379. if (!app)
  1380. {
  1381. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1382. return;
  1383. }
  1384. // Store the entered password
  1385. strncpy(app->register_password_2_logged_out, app->register_password_2_logged_out_temp_buffer, app->register_password_2_logged_out_temp_buffer_size);
  1386. // Ensure null-termination
  1387. app->register_password_2_logged_out[app->register_password_2_logged_out_temp_buffer_size - 1] = '\0';
  1388. // Update the password item text
  1389. if (app->variable_item_logged_out_register_password_2)
  1390. {
  1391. variable_item_set_current_value_text(app->variable_item_logged_out_register_password_2, app->register_password_2_logged_out);
  1392. }
  1393. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  1394. }
  1395. /**
  1396. * @brief Callback when the user selects a menu item in the register (logged out) screen.
  1397. * @param context The context - FlipSocialApp object.
  1398. * @param index The index of the selected item.
  1399. * @return void
  1400. */
  1401. void flip_social_text_input_logged_out_register_item_selected(void *context, uint32_t index)
  1402. {
  1403. FlipSocialApp *app = (FlipSocialApp *)context;
  1404. if (!app)
  1405. {
  1406. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1407. return;
  1408. }
  1409. switch (index)
  1410. {
  1411. case 0: // Input Username
  1412. free_all(false, true);
  1413. if (!alloc_text_input(FlipSocialViewLoggedOutRegisterUsernameInput))
  1414. {
  1415. FURI_LOG_E(TAG, "Failed to allocate text input");
  1416. return;
  1417. }
  1418. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1419. break;
  1420. case 1: // Input Password
  1421. free_all(false, true);
  1422. if (!alloc_text_input(FlipSocialViewLoggedOutRegisterPasswordInput))
  1423. {
  1424. FURI_LOG_E(TAG, "Failed to allocate text input");
  1425. return;
  1426. }
  1427. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1428. break;
  1429. case 2: // Input Password 2
  1430. free_all(false, true);
  1431. if (!alloc_text_input(FlipSocialViewLoggedOutRegisterPassword2Input))
  1432. {
  1433. FURI_LOG_E(TAG, "Failed to allocate text input");
  1434. return;
  1435. }
  1436. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1437. break;
  1438. case 3: // Register button
  1439. if (!flipper_http_init(flipper_http_rx_callback, app_instance))
  1440. {
  1441. FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
  1442. return;
  1443. }
  1444. flip_social_register_switch_to_view(app);
  1445. break;
  1446. default:
  1447. FURI_LOG_E(TAG, "Unknown configuration item index");
  1448. break;
  1449. }
  1450. }
  1451. /**
  1452. * @brief Text input callback for when the user finishes entering their SSID on the wifi settings (logged in) screen.
  1453. * @param context The context - FlipSocialApp object.
  1454. * @return void
  1455. */
  1456. void flip_social_logged_in_wifi_settings_ssid_updated(void *context)
  1457. {
  1458. FlipSocialApp *app = (FlipSocialApp *)context;
  1459. if (!app)
  1460. {
  1461. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1462. return;
  1463. }
  1464. // Store the entered SSID
  1465. strncpy(app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer, app->wifi_ssid_logged_in_temp_buffer_size);
  1466. // Store the entered SSID in the logged out SSID
  1467. strncpy(app->wifi_ssid_logged_out, app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer_size);
  1468. strncpy(app->wifi_ssid_logged_out_temp_buffer, app->wifi_ssid_logged_in, app->wifi_ssid_logged_in_temp_buffer_size);
  1469. // Ensure null-termination
  1470. app->wifi_ssid_logged_in[app->wifi_ssid_logged_in_temp_buffer_size - 1] = '\0';
  1471. // Update the name item text
  1472. if (app->variable_item_logged_in_wifi_settings_ssid)
  1473. {
  1474. variable_item_set_current_value_text(app->variable_item_logged_in_wifi_settings_ssid, app->wifi_ssid_logged_in);
  1475. }
  1476. // Save the settings
  1477. 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);
  1478. // update the wifi settings
  1479. if (strlen(app->wifi_ssid_logged_in) > 0 && strlen(app->wifi_password_logged_in) > 0)
  1480. {
  1481. if (flipper_http_init(flipper_http_rx_callback, app_instance))
  1482. {
  1483. if (!flipper_http_save_wifi(app->wifi_ssid_logged_in, app->wifi_password_logged_in))
  1484. {
  1485. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  1486. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1487. }
  1488. furi_delay_ms(500);
  1489. flipper_http_deinit();
  1490. }
  1491. }
  1492. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  1493. }
  1494. /**
  1495. * @brief Text input callback for when the user finishes entering their password on the wifi settings (logged in) screen.
  1496. * @param context The context - FlipSocialApp object.
  1497. * @return void
  1498. */
  1499. void flip_social_logged_in_wifi_settings_password_updated(void *context)
  1500. {
  1501. FlipSocialApp *app = (FlipSocialApp *)context;
  1502. if (!app)
  1503. {
  1504. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1505. return;
  1506. }
  1507. // Store the entered password
  1508. strncpy(app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer, app->wifi_password_logged_in_temp_buffer_size);
  1509. // Store the entered password in the logged out password
  1510. strncpy(app->login_password_logged_out, app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer_size);
  1511. strncpy(app->login_password_logged_out_temp_buffer, app->wifi_password_logged_in, app->wifi_password_logged_in_temp_buffer_size);
  1512. // Ensure null-termination
  1513. app->wifi_password_logged_in[app->wifi_password_logged_in_temp_buffer_size - 1] = '\0';
  1514. // Update the password item text
  1515. if (app->variable_item_logged_in_wifi_settings_password)
  1516. {
  1517. // dont show the password on the screen (version 0.2)
  1518. // variable_item_set_current_value_text(app->variable_item_logged_in_wifi_settings_password, app->wifi_password_logged_in);
  1519. }
  1520. // Save the settings
  1521. 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);
  1522. // update the wifi settings
  1523. if (strlen(app->wifi_ssid_logged_in) > 0 && strlen(app->wifi_password_logged_in) > 0)
  1524. {
  1525. if (flipper_http_init(flipper_http_rx_callback, app_instance))
  1526. {
  1527. if (!flipper_http_save_wifi(app->wifi_ssid_logged_in, app->wifi_password_logged_in))
  1528. {
  1529. FURI_LOG_E(TAG, "Failed to save wifi settings via UART");
  1530. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1531. }
  1532. furi_delay_ms(500);
  1533. flipper_http_deinit();
  1534. }
  1535. }
  1536. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewVariableItemList);
  1537. }
  1538. /**
  1539. * @brief Callback when the user selects a menu item in the wifi settings (logged in) screen.
  1540. * @param context The context - FlipSocialApp object.
  1541. * @param index The index of the selected item.
  1542. * @return void
  1543. */
  1544. void flip_social_text_input_logged_in_wifi_settings_item_selected(void *context, uint32_t index)
  1545. {
  1546. FlipSocialApp *app = (FlipSocialApp *)context;
  1547. if (!app)
  1548. {
  1549. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1550. return;
  1551. }
  1552. switch (index)
  1553. {
  1554. case 0: // Input SSID
  1555. // view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsSSIDInput);
  1556. free_all(false, false);
  1557. if (!alloc_text_input(FlipSocialViewLoggedInWifiSettingsSSIDInput))
  1558. {
  1559. FURI_LOG_E(TAG, "Failed to allocate text input for SSID");
  1560. return;
  1561. }
  1562. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1563. break;
  1564. case 1: // Input Password
  1565. // view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsPasswordInput);
  1566. free_all(false, false);
  1567. if (!alloc_text_input(FlipSocialViewLoggedInWifiSettingsPasswordInput))
  1568. {
  1569. FURI_LOG_E(TAG, "Failed to allocate text input for Password");
  1570. return;
  1571. }
  1572. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1573. break;
  1574. default:
  1575. FURI_LOG_E(TAG, "Unknown configuration item index");
  1576. break;
  1577. }
  1578. }
  1579. void flip_social_logged_in_user_settings_item_selected(void *context, uint32_t index)
  1580. {
  1581. FlipSocialApp *app = (FlipSocialApp *)context;
  1582. if (!app)
  1583. {
  1584. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1585. return;
  1586. }
  1587. // Switch to the appropriate view
  1588. switch (index)
  1589. {
  1590. case 0: // Feed Type
  1591. break;
  1592. }
  1593. }
  1594. /**
  1595. * @brief Text input callback for when the user finishes entering their message on the compose (logged in) screen for Add Text
  1596. * @param context The context - FlipSocialApp object.
  1597. * @return void
  1598. */
  1599. void flip_social_logged_in_compose_pre_save_updated(void *context)
  1600. {
  1601. FlipSocialApp *app = (FlipSocialApp *)context;
  1602. if (!app)
  1603. {
  1604. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1605. return;
  1606. }
  1607. // Check if the message is empty or if adding the message would exceed MAX_PRE_SAVED_MESSAGES
  1608. if (app->compose_pre_save_logged_in_temp_buffer_size == 0 || app->pre_saved_messages.count >= MAX_PRE_SAVED_MESSAGES)
  1609. {
  1610. FURI_LOG_E(TAG, "Message is empty or would exceed the maximum number of pre-saved messages");
  1611. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  1612. return;
  1613. }
  1614. // Copy the entered message into the next available slot
  1615. strncpy(
  1616. app->pre_saved_messages.messages[app->pre_saved_messages.count],
  1617. app->compose_pre_save_logged_in_temp_buffer,
  1618. MAX_MESSAGE_LENGTH - 1);
  1619. // Ensure null-termination
  1620. app->pre_saved_messages.messages[app->pre_saved_messages.count][MAX_MESSAGE_LENGTH - 1] = '\0';
  1621. // Increment the count
  1622. app->pre_saved_messages.count++;
  1623. // Rebuild the submenu
  1624. submenu_reset(app->submenu);
  1625. submenu_add_item(
  1626. app->submenu,
  1627. "Add Pre-Save",
  1628. FlipSocialSubmenuComposeIndexAddPreSave,
  1629. flip_social_callback_submenu_choices,
  1630. app);
  1631. for (size_t i = 0; i < app->pre_saved_messages.count; i++)
  1632. {
  1633. submenu_add_item(
  1634. app->submenu,
  1635. app->pre_saved_messages.messages[i],
  1636. FlipSocialSubemnuComposeIndexStartIndex + i,
  1637. flip_social_callback_submenu_choices,
  1638. app);
  1639. }
  1640. // Save the updated playlist
  1641. save_playlist(&app->pre_saved_messages);
  1642. // Switch back to the compose view
  1643. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  1644. }
  1645. /**
  1646. * @brief Text input callback for when the user finishes entering their message on the profile (logged in) screen for change password
  1647. * @param context The context - FlipSocialApp object.
  1648. * @return void
  1649. */
  1650. void flip_social_logged_in_profile_change_password_updated(void *context)
  1651. {
  1652. FlipSocialApp *app = (FlipSocialApp *)context;
  1653. if (!app)
  1654. {
  1655. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1656. return;
  1657. }
  1658. // Correct type: old_pass should be a pointer to a string (char *)
  1659. const char *old_password = app->login_password_logged_out;
  1660. // Store the entered message
  1661. strncpy(app->change_password_logged_in, app->change_password_logged_in_temp_buffer, app->change_password_logged_in_temp_buffer_size);
  1662. // store the entered password in the logged out password
  1663. strncpy(app->login_password_logged_out, app->change_password_logged_in, app->login_password_logged_out_temp_buffer_size);
  1664. strncpy(app->login_password_logged_out_temp_buffer, app->change_password_logged_in, app->login_password_logged_out_temp_buffer_size);
  1665. // Ensure null-termination
  1666. app->change_password_logged_in[app->change_password_logged_in_temp_buffer_size - 1] = '\0';
  1667. // Update the message item text
  1668. if (app->variable_item_logged_in_profile_change_password)
  1669. {
  1670. // dont show the password on the screen (version 0.2)
  1671. // variable_item_set_current_value_text(app->variable_item_logged_in_profile_change_password, app->change_password_logged_in);
  1672. }
  1673. // send post request to change password
  1674. if (flipper_http_init(flipper_http_rx_callback, app))
  1675. {
  1676. auth_headers_alloc();
  1677. char payload[256];
  1678. snprintf(payload, sizeof(payload), "{\"username\":\"%s\",\"old_password\":\"%s\",\"new_password\":\"%s\"}", app->login_username_logged_out, old_password, app->change_password_logged_in);
  1679. if (!flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/change-password/", auth_headers, payload))
  1680. {
  1681. FURI_LOG_E(TAG, "Failed to send post request to change password");
  1682. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1683. }
  1684. flipper_http_deinit();
  1685. }
  1686. // Save the settings
  1687. 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);
  1688. // instead of going to a view, just show a success message
  1689. easy_flipper_dialog("Success", "Password updated successfully\n\n\nPress BACK to return :D");
  1690. }
  1691. void flip_social_logged_in_profile_change_bio_updated(void *context)
  1692. {
  1693. FlipSocialApp *app = (FlipSocialApp *)context;
  1694. if (!app)
  1695. {
  1696. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1697. return;
  1698. }
  1699. // Store the entered message
  1700. strncpy(app->change_bio_logged_in, app->change_bio_logged_in_temp_buffer, app->change_bio_logged_in_temp_buffer_size);
  1701. // Ensure null-termination
  1702. app->change_bio_logged_in[app->change_bio_logged_in_temp_buffer_size - 1] = '\0';
  1703. // Update the message item text
  1704. if (app->variable_item_logged_in_profile_change_bio)
  1705. {
  1706. variable_item_set_current_value_text(app->variable_item_logged_in_profile_change_bio, app->change_bio_logged_in);
  1707. }
  1708. // send post request to change bio
  1709. if (flipper_http_init(flipper_http_rx_callback, app))
  1710. {
  1711. auth_headers_alloc();
  1712. char payload[256];
  1713. snprintf(payload, sizeof(payload), "{\"username\":\"%s\",\"bio\":\"%s\"}", app->login_username_logged_out, app->change_bio_logged_in);
  1714. if (!flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/change-bio/", auth_headers, payload))
  1715. {
  1716. FURI_LOG_E(TAG, "Failed to send post request to change bio");
  1717. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1718. }
  1719. furi_delay_ms(500);
  1720. flipper_http_deinit();
  1721. }
  1722. // Save the settings
  1723. 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);
  1724. // instead of going to a view, just show a success message
  1725. easy_flipper_dialog("Success", "Bio updated successfully\n\n\nPress BACK to return :D");
  1726. }
  1727. /**
  1728. * @brief Callback when a user selects a menu item in the profile (logged in) screen.
  1729. * @param context The context - FlipSocialApp object.
  1730. * @param index The index of the selected item.
  1731. * @return void
  1732. */
  1733. void flip_social_text_input_logged_in_profile_item_selected(void *context, uint32_t index)
  1734. {
  1735. FlipSocialApp *app = (FlipSocialApp *)context;
  1736. if (!app)
  1737. {
  1738. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1739. return;
  1740. }
  1741. switch (index)
  1742. {
  1743. case 0: // Change Username
  1744. // do nothing since username cannot be changed
  1745. break;
  1746. case 1: // Change Password
  1747. // view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInChangePasswordInput);
  1748. free_text_input();
  1749. if (!alloc_text_input(FlipSocialViewLoggedInChangePasswordInput))
  1750. {
  1751. FURI_LOG_E(TAG, "Failed to allocate text input for change password");
  1752. return;
  1753. }
  1754. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1755. break;
  1756. case 2: // Change Bio
  1757. // view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInChangeBioInput);
  1758. free_text_input();
  1759. if (!alloc_text_input(FlipSocialViewLoggedInChangeBioInput))
  1760. {
  1761. FURI_LOG_E(TAG, "Failed to allocate text input for change bio");
  1762. return;
  1763. }
  1764. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1765. break;
  1766. case 3: // Friends
  1767. free_all(false, true);
  1768. if (!alloc_submenu(FlipSocialViewLoggedInFriendsSubmenu))
  1769. {
  1770. FURI_LOG_E(TAG, "Failed to allocate submenu for friends");
  1771. return;
  1772. }
  1773. if (!flipper_http_init(flipper_http_rx_callback, app))
  1774. {
  1775. FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
  1776. return;
  1777. }
  1778. flipper_http_loading_task(
  1779. flip_social_get_friends,
  1780. flip_social_parse_json_friends,
  1781. FlipSocialViewSubmenu,
  1782. FlipSocialViewVariableItemList,
  1783. &app->view_dispatcher);
  1784. break;
  1785. default:
  1786. FURI_LOG_E(TAG, "Unknown configuration item index");
  1787. break;
  1788. }
  1789. }
  1790. /**
  1791. * @brief Text input callback for when the user finishes entering their message to send to the selected user choice (user choice messages view)
  1792. * @param context The context - FlipSocialApp object.
  1793. * @return void
  1794. */
  1795. void flip_social_logged_in_messages_user_choice_message_updated(void *context)
  1796. {
  1797. FlipSocialApp *app = (FlipSocialApp *)context;
  1798. if (!app)
  1799. {
  1800. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1801. return;
  1802. }
  1803. // check if the message is empty
  1804. if (app->message_user_choice_logged_in_temp_buffer_size == 0)
  1805. {
  1806. FURI_LOG_E(TAG, "Message is empty");
  1807. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewTextInput);
  1808. return;
  1809. }
  1810. // Store the entered message
  1811. strncpy(app->message_user_choice_logged_in, app->message_user_choice_logged_in_temp_buffer, app->message_user_choice_logged_in_temp_buffer_size);
  1812. // Ensure null-termination
  1813. app->message_user_choice_logged_in[app->message_user_choice_logged_in_temp_buffer_size - 1] = '\0';
  1814. // send post request to send message
  1815. if (!flipper_http_init(flipper_http_rx_callback, app))
  1816. {
  1817. FURI_LOG_E(TAG, "Failed to initialize HTTP");
  1818. return;
  1819. }
  1820. auth_headers_alloc();
  1821. char url[128];
  1822. char payload[256];
  1823. snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
  1824. snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_explore->usernames[flip_social_explore->index], app->message_user_choice_logged_in);
  1825. if (!flipper_http_post_request_with_headers(url, auth_headers, payload)) // start the async request
  1826. {
  1827. FURI_LOG_E(TAG, "Failed to send post request to send message");
  1828. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1829. }
  1830. furi_delay_ms(1000);
  1831. flipper_http_deinit();
  1832. // add user to the top of the list if not already there
  1833. for (int i = 0; i < flip_social_message_users->count; i++)
  1834. {
  1835. if (strcmp(flip_social_message_users->usernames[i], flip_social_explore->usernames[flip_social_explore->index]) == 0)
  1836. {
  1837. // remove the user from the list
  1838. for (int j = i; j < flip_social_message_users->count - 1; j++)
  1839. {
  1840. strncpy(flip_social_message_users->usernames[j], flip_social_message_users->usernames[j + 1], strlen(flip_social_message_users->usernames[j + 1]));
  1841. }
  1842. flip_social_message_users->count--;
  1843. break;
  1844. }
  1845. }
  1846. // add the user to the top of the list
  1847. for (int i = flip_social_message_users->count; i > 0; i--)
  1848. {
  1849. strncpy(flip_social_message_users->usernames[i], flip_social_message_users->usernames[i - 1], strlen(flip_social_message_users->usernames[i - 1]));
  1850. }
  1851. strncpy(flip_social_message_users->usernames[0], flip_social_explore->usernames[flip_social_explore->index], strlen(flip_social_explore->usernames[flip_social_explore->index]));
  1852. flip_social_message_users->count++;
  1853. // redraw submenu
  1854. flip_social_update_messages_submenu();
  1855. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  1856. }
  1857. /**
  1858. * @brief Text input callback for when the user finishes entering their message to the selected user (messages view)
  1859. * @param context The context - FlipSocialApp object.
  1860. * @return void
  1861. */
  1862. void flip_social_logged_in_messages_new_message_updated(void *context)
  1863. {
  1864. FlipSocialApp *app = (FlipSocialApp *)context;
  1865. if (!app)
  1866. {
  1867. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1868. return;
  1869. }
  1870. // check if the message is empty
  1871. if (app->messages_new_message_logged_in_temp_buffer_size == 0)
  1872. {
  1873. FURI_LOG_E(TAG, "Message is empty");
  1874. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageInput);
  1875. return;
  1876. }
  1877. // Store the entered message
  1878. strncpy(app->messages_new_message_logged_in, app->messages_new_message_logged_in_temp_buffer, app->messages_new_message_logged_in_temp_buffer_size);
  1879. // Ensure null-termination
  1880. app->messages_new_message_logged_in[app->messages_new_message_logged_in_temp_buffer_size - 1] = '\0';
  1881. bool send_message_to_user()
  1882. {
  1883. // send post request to send message
  1884. if (!flipper_http_init(flipper_http_rx_callback, app))
  1885. {
  1886. FURI_LOG_E(TAG, "Failed to initialize HTTP");
  1887. return false;
  1888. }
  1889. auth_headers_alloc();
  1890. char url[128];
  1891. char payload[256];
  1892. snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
  1893. snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_message_users->usernames[flip_social_message_users->index], app->messages_new_message_logged_in);
  1894. if (!flipper_http_post_request_with_headers(url, auth_headers, payload))
  1895. {
  1896. FURI_LOG_E(TAG, "Failed to send post request to send message");
  1897. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1898. easy_flipper_dialog("Error", "Failed to send message\n\n\nPress BACK to return :D");
  1899. flipper_http_deinit();
  1900. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  1901. return false;
  1902. }
  1903. fhttp.state = RECEIVING;
  1904. return true;
  1905. }
  1906. bool parse_message_to_user()
  1907. {
  1908. while (fhttp.state != IDLE)
  1909. {
  1910. furi_delay_ms(10);
  1911. }
  1912. flipper_http_deinit();
  1913. return true;
  1914. }
  1915. // well, we got a freeze here, so let's use the loading task to switch views and force refresh
  1916. flipper_http_loading_task(
  1917. send_message_to_user,
  1918. parse_message_to_user,
  1919. FlipSocialViewSubmenu,
  1920. FlipSocialViewLoggedInMessagesNewMessageInput,
  1921. &app->view_dispatcher);
  1922. }
  1923. void flip_social_logged_in_explore_updated(void *context)
  1924. {
  1925. FlipSocialApp *app = (FlipSocialApp *)context;
  1926. if (!app)
  1927. {
  1928. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1929. return;
  1930. }
  1931. // check if the message is empty
  1932. if (app->explore_logged_in_temp_buffer_size == 0)
  1933. {
  1934. FURI_LOG_E(TAG, "Message is empty");
  1935. strncpy(app->explore_logged_in, "a", 2);
  1936. }
  1937. else
  1938. {
  1939. // Store the entered message
  1940. strncpy(app->explore_logged_in, app->explore_logged_in_temp_buffer, app->explore_logged_in_temp_buffer_size);
  1941. }
  1942. // Ensure null-termination
  1943. app->explore_logged_in[app->explore_logged_in_temp_buffer_size - 1] = '\0';
  1944. free_submenu();
  1945. if (!alloc_submenu(FlipSocialViewLoggedInExploreSubmenu))
  1946. {
  1947. FURI_LOG_E(TAG, "Failed to allocate submenu for explore");
  1948. return;
  1949. }
  1950. flipper_http_loading_task(
  1951. flip_social_get_explore, // get the explore users
  1952. flip_social_parse_json_explore, // parse the explore users
  1953. FlipSocialViewSubmenu, // switch to the explore submenu if successful
  1954. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  1955. &app->view_dispatcher); // view dispatcher
  1956. }
  1957. void flip_social_logged_in_message_users_updated(void *context)
  1958. {
  1959. FlipSocialApp *app = (FlipSocialApp *)context;
  1960. if (!app)
  1961. {
  1962. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1963. return;
  1964. }
  1965. // check if the message is empty
  1966. if (!app->message_users_logged_in_temp_buffer || app->message_users_logged_in_temp_buffer_size == 0)
  1967. {
  1968. FURI_LOG_E(TAG, "Message is empty");
  1969. strncpy(app->message_users_logged_in, "a", 2);
  1970. }
  1971. else
  1972. {
  1973. // Store the entered message
  1974. strncpy(app->message_users_logged_in, app->message_users_logged_in_temp_buffer, app->message_users_logged_in_temp_buffer_size);
  1975. }
  1976. // Ensure null-termination
  1977. app->message_users_logged_in[app->message_users_logged_in_temp_buffer_size - 1] = '\0';
  1978. free_submenu();
  1979. if (!alloc_submenu(FlipSocialViewLoggedInExploreSubmenu))
  1980. {
  1981. FURI_LOG_E(TAG, "Failed to allocate submenu for explore");
  1982. return;
  1983. }
  1984. // get users
  1985. flipper_http_loading_task(
  1986. flip_social_get_explore_2, // get the explore users
  1987. flip_social_parse_json_message_user_choices, // parse the explore users
  1988. FlipSocialViewSubmenu, // switch to the explore submenu if successful
  1989. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  1990. &app->view_dispatcher); // view dispatcher
  1991. }
  1992. static void flip_social_widget_set_text(char *message, Widget **widget)
  1993. {
  1994. if (widget == NULL)
  1995. {
  1996. FURI_LOG_E(TAG, "flip_social_set_widget_text - widget is NULL");
  1997. DEV_CRASH();
  1998. return;
  1999. }
  2000. if (message == NULL)
  2001. {
  2002. FURI_LOG_E(TAG, "flip_social_set_widget_text - message is NULL");
  2003. DEV_CRASH();
  2004. return;
  2005. }
  2006. widget_reset(*widget);
  2007. uint32_t message_length = strlen(message); // Length of the message
  2008. uint32_t i = 0; // Index tracker
  2009. uint32_t formatted_index = 0; // Tracker for where we are in the formatted message
  2010. char *formatted_message; // Buffer to hold the final formatted message
  2011. // Allocate buffer with double the message length plus one for safety
  2012. if (!easy_flipper_set_buffer(&formatted_message, message_length * 2 + 1))
  2013. {
  2014. return;
  2015. }
  2016. while (i < message_length)
  2017. {
  2018. uint32_t max_line_length = 31; // Maximum characters per line
  2019. uint32_t remaining_length = message_length - i; // Remaining characters
  2020. uint32_t line_length = (remaining_length < max_line_length) ? remaining_length : max_line_length;
  2021. // Check for newline character within the current segment
  2022. uint32_t newline_pos = i;
  2023. bool found_newline = false;
  2024. for (; newline_pos < i + line_length && newline_pos < message_length; newline_pos++)
  2025. {
  2026. if (message[newline_pos] == '\n')
  2027. {
  2028. found_newline = true;
  2029. break;
  2030. }
  2031. }
  2032. if (found_newline)
  2033. {
  2034. // If newline found, set line_length up to the newline
  2035. line_length = newline_pos - i;
  2036. }
  2037. // Temporary buffer to hold the current line
  2038. char line[32];
  2039. strncpy(line, message + i, line_length);
  2040. line[line_length] = '\0';
  2041. // If newline was found, skip it for the next iteration
  2042. if (found_newline)
  2043. {
  2044. i += line_length + 1; // +1 to skip the '\n' character
  2045. }
  2046. else
  2047. {
  2048. // Check if the line ends in the middle of a word and adjust accordingly
  2049. if (line_length == max_line_length && message[i + line_length] != '\0' && message[i + line_length] != ' ')
  2050. {
  2051. // Find the last space within the current line to avoid breaking a word
  2052. char *last_space = strrchr(line, ' ');
  2053. if (last_space != NULL)
  2054. {
  2055. // Adjust the line_length to avoid cutting the word
  2056. line_length = last_space - line;
  2057. line[line_length] = '\0'; // Null-terminate at the space
  2058. }
  2059. }
  2060. // Move the index forward by the determined line_length
  2061. i += line_length;
  2062. // Skip any spaces at the beginning of the next line
  2063. while (i < message_length && message[i] == ' ')
  2064. {
  2065. i++;
  2066. }
  2067. }
  2068. // Manually copy the fixed line into the formatted_message buffer
  2069. for (uint32_t j = 0; j < line_length; j++)
  2070. {
  2071. formatted_message[formatted_index++] = line[j];
  2072. }
  2073. // Add a newline character for line spacing
  2074. formatted_message[formatted_index++] = '\n';
  2075. }
  2076. // Null-terminate the formatted_message
  2077. formatted_message[formatted_index] = '\0';
  2078. // Add the formatted message to the widget
  2079. widget_add_text_scroll_element(*widget, 0, 0, 128, 64, formatted_message);
  2080. }
  2081. void flip_social_loader_draw_callback(Canvas *canvas, void *model)
  2082. {
  2083. if (!canvas || !model)
  2084. {
  2085. FURI_LOG_E(TAG, "flip_social_loader_draw_callback - canvas or model is NULL");
  2086. return;
  2087. }
  2088. SerialState http_state = fhttp.state;
  2089. DataLoaderModel *data_loader_model = (DataLoaderModel *)model;
  2090. DataState data_state = data_loader_model->data_state;
  2091. char *title = data_loader_model->title;
  2092. canvas_set_font(canvas, FontSecondary);
  2093. if (http_state == INACTIVE)
  2094. {
  2095. canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
  2096. canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
  2097. canvas_draw_str(canvas, 0, 32, "If your board is connected,");
  2098. canvas_draw_str(canvas, 0, 42, "make sure you have flashed");
  2099. canvas_draw_str(canvas, 0, 52, "your WiFi Devboard with the");
  2100. canvas_draw_str(canvas, 0, 62, "latest FlipperHTTP flash.");
  2101. return;
  2102. }
  2103. if (data_state == DataStateError || data_state == DataStateParseError)
  2104. {
  2105. flip_social_request_error_draw(canvas);
  2106. return;
  2107. }
  2108. canvas_draw_str(canvas, 0, 7, title);
  2109. canvas_draw_str(canvas, 0, 17, "Loading...");
  2110. if (data_state == DataStateInitial)
  2111. {
  2112. return;
  2113. }
  2114. if (http_state == SENDING)
  2115. {
  2116. canvas_draw_str(canvas, 0, 27, "Fetching...");
  2117. return;
  2118. }
  2119. if (http_state == RECEIVING || data_state == DataStateRequested)
  2120. {
  2121. canvas_draw_str(canvas, 0, 27, "Receiving...");
  2122. return;
  2123. }
  2124. if (http_state == IDLE && data_state == DataStateReceived)
  2125. {
  2126. canvas_draw_str(canvas, 0, 27, "Processing...");
  2127. return;
  2128. }
  2129. if (http_state == IDLE && data_state == DataStateParsed)
  2130. {
  2131. canvas_draw_str(canvas, 0, 27, "Processed...");
  2132. return;
  2133. }
  2134. }
  2135. static void flip_social_loader_process_callback(void *context)
  2136. {
  2137. if (context == NULL)
  2138. {
  2139. FURI_LOG_E(TAG, "flip_social_loader_process_callback - context is NULL");
  2140. DEV_CRASH();
  2141. return;
  2142. }
  2143. FlipSocialApp *app = (FlipSocialApp *)context;
  2144. View *view = app->view_loader;
  2145. DataState current_data_state;
  2146. with_view_model(view, DataLoaderModel * model, { current_data_state = model->data_state; }, false);
  2147. if (current_data_state == DataStateInitial)
  2148. {
  2149. with_view_model(
  2150. view,
  2151. DataLoaderModel * model,
  2152. {
  2153. model->data_state = DataStateRequested;
  2154. DataLoaderFetch fetch = model->fetcher;
  2155. if (fetch == NULL)
  2156. {
  2157. FURI_LOG_E(TAG, "Model doesn't have Fetch function assigned.");
  2158. model->data_state = DataStateError;
  2159. return;
  2160. }
  2161. // Clear any previous responses
  2162. strncpy(fhttp.last_response, "", 1);
  2163. bool request_status = fetch(model);
  2164. if (!request_status)
  2165. {
  2166. model->data_state = DataStateError;
  2167. }
  2168. },
  2169. true);
  2170. }
  2171. else if (current_data_state == DataStateRequested || current_data_state == DataStateError)
  2172. {
  2173. if (fhttp.state == IDLE && fhttp.last_response != NULL)
  2174. {
  2175. if (strstr(fhttp.last_response, "[PONG]") != NULL)
  2176. {
  2177. FURI_LOG_DEV(TAG, "PONG received.");
  2178. }
  2179. else if (strncmp(fhttp.last_response, "[SUCCESS]", 9) == 0)
  2180. {
  2181. FURI_LOG_DEV(TAG, "SUCCESS received. %s", fhttp.last_response ? fhttp.last_response : "NULL");
  2182. }
  2183. else if (strncmp(fhttp.last_response, "[ERROR]", 9) == 0)
  2184. {
  2185. FURI_LOG_DEV(TAG, "ERROR received. %s", fhttp.last_response ? fhttp.last_response : "NULL");
  2186. }
  2187. else if (strlen(fhttp.last_response) == 0)
  2188. {
  2189. // Still waiting on response
  2190. }
  2191. else
  2192. {
  2193. with_view_model(view, DataLoaderModel * model, { model->data_state = DataStateReceived; }, true);
  2194. }
  2195. }
  2196. else if (fhttp.state == SENDING || fhttp.state == RECEIVING)
  2197. {
  2198. // continue waiting
  2199. }
  2200. else if (fhttp.state == INACTIVE)
  2201. {
  2202. // inactive. try again
  2203. }
  2204. else if (fhttp.state == ISSUE)
  2205. {
  2206. with_view_model(view, DataLoaderModel * model, { model->data_state = DataStateError; }, true);
  2207. }
  2208. else
  2209. {
  2210. FURI_LOG_DEV(TAG, "Unexpected state: %d lastresp: %s", fhttp.state, fhttp.last_response ? fhttp.last_response : "NULL");
  2211. DEV_CRASH();
  2212. }
  2213. }
  2214. else if (current_data_state == DataStateReceived)
  2215. {
  2216. with_view_model(
  2217. view,
  2218. DataLoaderModel * model,
  2219. {
  2220. char *data_text;
  2221. if (model->parser == NULL)
  2222. {
  2223. data_text = NULL;
  2224. FURI_LOG_DEV(TAG, "Parser is NULL");
  2225. DEV_CRASH();
  2226. }
  2227. else
  2228. {
  2229. data_text = model->parser(model);
  2230. }
  2231. FURI_LOG_DEV(TAG, "Parsed data: %s\r\ntext: %s", fhttp.last_response ? fhttp.last_response : "NULL", data_text ? data_text : "NULL");
  2232. model->data_text = data_text;
  2233. if (data_text == NULL)
  2234. {
  2235. model->data_state = DataStateParseError;
  2236. }
  2237. else
  2238. {
  2239. model->data_state = DataStateParsed;
  2240. }
  2241. },
  2242. true);
  2243. }
  2244. else if (current_data_state == DataStateParsed)
  2245. {
  2246. with_view_model(
  2247. view,
  2248. DataLoaderModel * model,
  2249. {
  2250. if (++model->request_index < model->request_count)
  2251. {
  2252. model->data_state = DataStateInitial;
  2253. }
  2254. else
  2255. {
  2256. flip_social_widget_set_text(model->data_text != NULL ? model->data_text : "", &app_instance->widget_result);
  2257. if (model->data_text != NULL)
  2258. {
  2259. free(model->data_text);
  2260. model->data_text = NULL;
  2261. }
  2262. view_set_previous_callback(widget_get_view(app_instance->widget_result), model->back_callback);
  2263. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewWidgetResult);
  2264. }
  2265. },
  2266. true);
  2267. }
  2268. }
  2269. static void flip_social_loader_timer_callback(void *context)
  2270. {
  2271. if (context == NULL)
  2272. {
  2273. FURI_LOG_E(TAG, "flip_social_loader_timer_callback - context is NULL");
  2274. DEV_CRASH();
  2275. return;
  2276. }
  2277. FlipSocialApp *app = (FlipSocialApp *)context;
  2278. view_dispatcher_send_custom_event(app->view_dispatcher, FlipSocialCustomEventProcess);
  2279. }
  2280. static void flip_social_loader_on_enter(void *context)
  2281. {
  2282. if (context == NULL)
  2283. {
  2284. FURI_LOG_E(TAG, "flip_social_loader_on_enter - context is NULL");
  2285. DEV_CRASH();
  2286. return;
  2287. }
  2288. FlipSocialApp *app = (FlipSocialApp *)context;
  2289. View *view = app->view_loader;
  2290. with_view_model(
  2291. view,
  2292. DataLoaderModel * model,
  2293. {
  2294. view_set_previous_callback(view, model->back_callback);
  2295. if (model->timer == NULL)
  2296. {
  2297. model->timer = furi_timer_alloc(flip_social_loader_timer_callback, FuriTimerTypePeriodic, app);
  2298. }
  2299. furi_timer_start(model->timer, 250);
  2300. },
  2301. true);
  2302. }
  2303. static void flip_social_loader_on_exit(void *context)
  2304. {
  2305. if (context == NULL)
  2306. {
  2307. FURI_LOG_E(TAG, "flip_social_loader_on_exit - context is NULL");
  2308. DEV_CRASH();
  2309. return;
  2310. }
  2311. FlipSocialApp *app = (FlipSocialApp *)context;
  2312. View *view = app->view_loader;
  2313. with_view_model(
  2314. view,
  2315. DataLoaderModel * model,
  2316. {
  2317. if (model->timer)
  2318. {
  2319. furi_timer_stop(model->timer);
  2320. }
  2321. },
  2322. false);
  2323. }
  2324. void flip_social_loader_init(View *view)
  2325. {
  2326. if (view == NULL)
  2327. {
  2328. FURI_LOG_E(TAG, "flip_social_loader_init - view is NULL");
  2329. DEV_CRASH();
  2330. return;
  2331. }
  2332. view_allocate_model(view, ViewModelTypeLocking, sizeof(DataLoaderModel));
  2333. view_set_enter_callback(view, flip_social_loader_on_enter);
  2334. view_set_exit_callback(view, flip_social_loader_on_exit);
  2335. }
  2336. void flip_social_loader_free_model(View *view)
  2337. {
  2338. if (view == NULL)
  2339. {
  2340. FURI_LOG_E(TAG, "flip_social_loader_free_model - view is NULL");
  2341. DEV_CRASH();
  2342. return;
  2343. }
  2344. with_view_model(
  2345. view,
  2346. DataLoaderModel * model,
  2347. {
  2348. if (model->timer)
  2349. {
  2350. furi_timer_free(model->timer);
  2351. model->timer = NULL;
  2352. }
  2353. if (model->parser_context)
  2354. {
  2355. free(model->parser_context);
  2356. model->parser_context = NULL;
  2357. }
  2358. },
  2359. false);
  2360. }
  2361. bool flip_social_custom_event_callback(void *context, uint32_t index)
  2362. {
  2363. if (context == NULL)
  2364. {
  2365. FURI_LOG_E(TAG, "flip_social_custom_event_callback - context is NULL");
  2366. DEV_CRASH();
  2367. return false;
  2368. }
  2369. switch (index)
  2370. {
  2371. case FlipSocialCustomEventProcess:
  2372. flip_social_loader_process_callback(context);
  2373. return true;
  2374. default:
  2375. FURI_LOG_DEV(TAG, "flip_social_custom_event_callback. Unknown index: %ld", index);
  2376. return false;
  2377. }
  2378. }
  2379. void flip_social_generic_switch_to_view(FlipSocialApp *app, char *title, DataLoaderFetch fetcher, DataLoaderParser parser, size_t request_count, ViewNavigationCallback back, uint32_t view_id)
  2380. {
  2381. if (app == NULL)
  2382. {
  2383. FURI_LOG_E(TAG, "flip_social_generic_switch_to_view - app is NULL");
  2384. DEV_CRASH();
  2385. return;
  2386. }
  2387. View *view = app->view_loader;
  2388. if (view == NULL)
  2389. {
  2390. FURI_LOG_E(TAG, "flip_social_generic_switch_to_view - view is NULL");
  2391. DEV_CRASH();
  2392. return;
  2393. }
  2394. with_view_model(
  2395. view,
  2396. DataLoaderModel * model,
  2397. {
  2398. model->title = title;
  2399. model->fetcher = fetcher;
  2400. model->parser = parser;
  2401. model->request_index = 0;
  2402. model->request_count = request_count;
  2403. model->back_callback = back;
  2404. model->data_state = DataStateInitial;
  2405. model->data_text = NULL;
  2406. },
  2407. true);
  2408. view_dispatcher_switch_to_view(app->view_dispatcher, view_id);
  2409. }
  2410. static bool flip_social_get_home_notification()
  2411. {
  2412. if (!app_instance)
  2413. {
  2414. FURI_LOG_E(TAG, "app_instance is NULL");
  2415. return false;
  2416. }
  2417. if (!flipper_http_init(flipper_http_rx_callback, app_instance))
  2418. {
  2419. FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
  2420. return false;
  2421. }
  2422. // Create the directory for saving settings
  2423. char directory_path[256];
  2424. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/data");
  2425. // Create the directory
  2426. Storage *storage = furi_record_open(RECORD_STORAGE);
  2427. storage_common_mkdir(storage, directory_path);
  2428. furi_record_close(RECORD_STORAGE);
  2429. auth_headers_alloc();
  2430. snprintf(
  2431. fhttp.file_path,
  2432. sizeof(fhttp.file_path),
  2433. STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/data/notification.json");
  2434. fhttp.save_received_data = true;
  2435. return flipper_http_get_request_with_headers("https://www.flipsocial.net/api/flip-social-notifications/", auth_headers);
  2436. }
  2437. static bool flip_social_parse_home_notification()
  2438. {
  2439. FuriString *notification = flipper_http_load_from_file(fhttp.file_path);
  2440. if (notification == NULL)
  2441. {
  2442. FURI_LOG_E(TAG, "Failed to load notification from file");
  2443. flipper_http_deinit();
  2444. return false;
  2445. }
  2446. flipper_http_deinit();
  2447. // Check if announcement and analytics key exists
  2448. FuriString *announcement_json = get_json_value_furi("announcement", notification);
  2449. FuriString *analytics_json = get_json_value_furi("analytics", notification);
  2450. if (announcement_json == NULL || analytics_json == NULL)
  2451. {
  2452. FURI_LOG_E(TAG, "Failed to get announcement or analytics from notification");
  2453. if (announcement_json)
  2454. {
  2455. furi_string_free(announcement_json);
  2456. }
  2457. if (analytics_json)
  2458. {
  2459. furi_string_free(analytics_json);
  2460. }
  2461. furi_string_free(notification);
  2462. return false;
  2463. }
  2464. // Extract values from JSON
  2465. FuriString *announcement_value = get_json_value_furi("content", announcement_json);
  2466. FuriString *announcement_time = get_json_value_furi("date_created", announcement_json);
  2467. FuriString *analytics_value = get_json_value_furi("count", analytics_json);
  2468. FuriString *analytics_time = get_json_value_furi("time", analytics_json);
  2469. if (!announcement_value || !announcement_time || !analytics_value || !analytics_time)
  2470. {
  2471. FURI_LOG_E(TAG, "Failed to get announcement or analytics value from notification");
  2472. if (announcement_value)
  2473. {
  2474. furi_string_free(announcement_value);
  2475. }
  2476. if (announcement_time)
  2477. {
  2478. furi_string_free(announcement_time);
  2479. }
  2480. if (analytics_value)
  2481. {
  2482. furi_string_free(analytics_value);
  2483. }
  2484. if (analytics_time)
  2485. {
  2486. furi_string_free(analytics_time);
  2487. }
  2488. furi_string_free(announcement_json);
  2489. furi_string_free(analytics_json);
  2490. furi_string_free(notification);
  2491. return false;
  2492. }
  2493. // Load previous announcement and analytics times
  2494. char past_analytics_time[32] = {0};
  2495. char past_announcement_time[32] = {0};
  2496. bool analytics_time_loaded = load_char("analytics_time", past_analytics_time, sizeof(past_analytics_time));
  2497. bool announcement_time_loaded = load_char("announcement_time", past_announcement_time, sizeof(past_announcement_time));
  2498. bool new_announcement = false;
  2499. bool new_analytics = false;
  2500. // Check for new announcement
  2501. if (!announcement_time_loaded || strcmp(furi_string_get_cstr(announcement_time), past_announcement_time) != 0)
  2502. {
  2503. new_announcement = true;
  2504. }
  2505. // Check for new analytics
  2506. if (!analytics_time_loaded || strcmp(furi_string_get_cstr(analytics_time), past_analytics_time) != 0)
  2507. {
  2508. new_analytics = true;
  2509. }
  2510. // If no new announcement and no new analytics, exit early
  2511. if (!new_announcement && !new_analytics)
  2512. {
  2513. FURI_LOG_D(TAG, "No new announcement or analytics");
  2514. furi_string_free(announcement_value);
  2515. furi_string_free(announcement_time);
  2516. furi_string_free(analytics_value);
  2517. furi_string_free(analytics_time);
  2518. furi_string_free(announcement_json);
  2519. furi_string_free(analytics_json);
  2520. furi_string_free(notification);
  2521. return true;
  2522. }
  2523. // Save the new announcement and analytics times if they are new
  2524. if (new_announcement)
  2525. {
  2526. save_char("announcement_time", furi_string_get_cstr(announcement_time));
  2527. }
  2528. if (new_analytics)
  2529. {
  2530. save_char("analytics_time", furi_string_get_cstr(analytics_time));
  2531. }
  2532. // Prepare and show dialogs based on what is new
  2533. if (new_announcement)
  2534. {
  2535. easy_flipper_dialog("Announcement", (char *)furi_string_get_cstr(announcement_value));
  2536. }
  2537. if (new_analytics)
  2538. {
  2539. char analytics_text[128] = {0};
  2540. // Determine the new posts count
  2541. if (atoi(furi_string_get_cstr(analytics_value)) > 0)
  2542. {
  2543. char past_analytics_value[32] = {0};
  2544. int new_posts = 0;
  2545. if (load_char("analytics_value", past_analytics_value, sizeof(past_analytics_value)))
  2546. {
  2547. int past_posts = atoi(past_analytics_value);
  2548. int current_posts = atoi(furi_string_get_cstr(analytics_value));
  2549. new_posts = current_posts - past_posts;
  2550. snprintf(analytics_text, sizeof(analytics_text), "%d new posts", new_posts);
  2551. }
  2552. else
  2553. {
  2554. snprintf(analytics_text, sizeof(analytics_text), "%s feed posts", furi_string_get_cstr(analytics_value));
  2555. }
  2556. save_char("analytics_value", furi_string_get_cstr(analytics_value));
  2557. }
  2558. else
  2559. {
  2560. snprintf(analytics_text, sizeof(analytics_text), "%s feed posts", furi_string_get_cstr(analytics_value));
  2561. }
  2562. easy_flipper_dialog("Notifications", analytics_text);
  2563. }
  2564. // Free allocated resources
  2565. furi_string_free(announcement_value);
  2566. furi_string_free(announcement_time);
  2567. furi_string_free(analytics_value);
  2568. furi_string_free(analytics_time);
  2569. furi_string_free(announcement_json);
  2570. furi_string_free(analytics_json);
  2571. furi_string_free(notification);
  2572. return true;
  2573. }
  2574. // home notification
  2575. bool flip_social_home_notification()
  2576. {
  2577. return flipper_http_process_response_async(flip_social_get_home_notification, flip_social_parse_home_notification);
  2578. }