flip_social_callback.c 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772
  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. // send post request to send message
  1882. if (!flipper_http_init(flipper_http_rx_callback, app))
  1883. {
  1884. FURI_LOG_E(TAG, "Failed to initialize HTTP");
  1885. return;
  1886. }
  1887. auth_headers_alloc();
  1888. char url[128];
  1889. char payload[256];
  1890. snprintf(url, sizeof(url), "https://www.flipsocial.net/api/messages/%s/post/", app->login_username_logged_in);
  1891. snprintf(payload, sizeof(payload), "{\"receiver\":\"%s\",\"content\":\"%s\"}", flip_social_message_users->usernames[flip_social_message_users->index], app->messages_new_message_logged_in);
  1892. if (!flipper_http_post_request_with_headers(url, auth_headers, payload))
  1893. {
  1894. FURI_LOG_E(TAG, "Failed to send post request to send message");
  1895. FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
  1896. }
  1897. furi_delay_ms(1000);
  1898. flipper_http_deinit();
  1899. view_dispatcher_switch_to_view(app->view_dispatcher, FlipSocialViewSubmenu);
  1900. }
  1901. void flip_social_logged_in_explore_updated(void *context)
  1902. {
  1903. FlipSocialApp *app = (FlipSocialApp *)context;
  1904. if (!app)
  1905. {
  1906. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1907. return;
  1908. }
  1909. // check if the message is empty
  1910. if (app->explore_logged_in_temp_buffer_size == 0)
  1911. {
  1912. FURI_LOG_E(TAG, "Message is empty");
  1913. strncpy(app->explore_logged_in, "a", 2);
  1914. }
  1915. else
  1916. {
  1917. // Store the entered message
  1918. strncpy(app->explore_logged_in, app->explore_logged_in_temp_buffer, app->explore_logged_in_temp_buffer_size);
  1919. }
  1920. // Ensure null-termination
  1921. app->explore_logged_in[app->explore_logged_in_temp_buffer_size - 1] = '\0';
  1922. free_submenu();
  1923. if (!alloc_submenu(FlipSocialViewLoggedInExploreSubmenu))
  1924. {
  1925. FURI_LOG_E(TAG, "Failed to allocate submenu for explore");
  1926. return;
  1927. }
  1928. flipper_http_loading_task(
  1929. flip_social_get_explore, // get the explore users
  1930. flip_social_parse_json_explore, // parse the explore users
  1931. FlipSocialViewSubmenu, // switch to the explore submenu if successful
  1932. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  1933. &app->view_dispatcher); // view dispatcher
  1934. }
  1935. void flip_social_logged_in_message_users_updated(void *context)
  1936. {
  1937. FlipSocialApp *app = (FlipSocialApp *)context;
  1938. if (!app)
  1939. {
  1940. FURI_LOG_E(TAG, "FlipSocialApp is NULL");
  1941. return;
  1942. }
  1943. // check if the message is empty
  1944. if (!app->message_users_logged_in_temp_buffer || app->message_users_logged_in_temp_buffer_size == 0)
  1945. {
  1946. FURI_LOG_E(TAG, "Message is empty");
  1947. strncpy(app->message_users_logged_in, "a", 2);
  1948. }
  1949. else
  1950. {
  1951. // Store the entered message
  1952. strncpy(app->message_users_logged_in, app->message_users_logged_in_temp_buffer, app->message_users_logged_in_temp_buffer_size);
  1953. }
  1954. // Ensure null-termination
  1955. app->message_users_logged_in[app->message_users_logged_in_temp_buffer_size - 1] = '\0';
  1956. free_submenu();
  1957. if (!alloc_submenu(FlipSocialViewLoggedInExploreSubmenu))
  1958. {
  1959. FURI_LOG_E(TAG, "Failed to allocate submenu for explore");
  1960. return;
  1961. }
  1962. // get users
  1963. flipper_http_loading_task(
  1964. flip_social_get_explore_2, // get the explore users
  1965. flip_social_parse_json_message_user_choices, // parse the explore users
  1966. FlipSocialViewSubmenu, // switch to the explore submenu if successful
  1967. FlipSocialViewLoggedInSubmenu, // switch back to the main submenu if failed
  1968. &app->view_dispatcher); // view dispatcher
  1969. }
  1970. static void flip_social_widget_set_text(char *message, Widget **widget)
  1971. {
  1972. if (widget == NULL)
  1973. {
  1974. FURI_LOG_E(TAG, "flip_social_set_widget_text - widget is NULL");
  1975. DEV_CRASH();
  1976. return;
  1977. }
  1978. if (message == NULL)
  1979. {
  1980. FURI_LOG_E(TAG, "flip_social_set_widget_text - message is NULL");
  1981. DEV_CRASH();
  1982. return;
  1983. }
  1984. widget_reset(*widget);
  1985. uint32_t message_length = strlen(message); // Length of the message
  1986. uint32_t i = 0; // Index tracker
  1987. uint32_t formatted_index = 0; // Tracker for where we are in the formatted message
  1988. char *formatted_message; // Buffer to hold the final formatted message
  1989. // Allocate buffer with double the message length plus one for safety
  1990. if (!easy_flipper_set_buffer(&formatted_message, message_length * 2 + 1))
  1991. {
  1992. return;
  1993. }
  1994. while (i < message_length)
  1995. {
  1996. uint32_t max_line_length = 31; // Maximum characters per line
  1997. uint32_t remaining_length = message_length - i; // Remaining characters
  1998. uint32_t line_length = (remaining_length < max_line_length) ? remaining_length : max_line_length;
  1999. // Check for newline character within the current segment
  2000. uint32_t newline_pos = i;
  2001. bool found_newline = false;
  2002. for (; newline_pos < i + line_length && newline_pos < message_length; newline_pos++)
  2003. {
  2004. if (message[newline_pos] == '\n')
  2005. {
  2006. found_newline = true;
  2007. break;
  2008. }
  2009. }
  2010. if (found_newline)
  2011. {
  2012. // If newline found, set line_length up to the newline
  2013. line_length = newline_pos - i;
  2014. }
  2015. // Temporary buffer to hold the current line
  2016. char line[32];
  2017. strncpy(line, message + i, line_length);
  2018. line[line_length] = '\0';
  2019. // If newline was found, skip it for the next iteration
  2020. if (found_newline)
  2021. {
  2022. i += line_length + 1; // +1 to skip the '\n' character
  2023. }
  2024. else
  2025. {
  2026. // Check if the line ends in the middle of a word and adjust accordingly
  2027. if (line_length == max_line_length && message[i + line_length] != '\0' && message[i + line_length] != ' ')
  2028. {
  2029. // Find the last space within the current line to avoid breaking a word
  2030. char *last_space = strrchr(line, ' ');
  2031. if (last_space != NULL)
  2032. {
  2033. // Adjust the line_length to avoid cutting the word
  2034. line_length = last_space - line;
  2035. line[line_length] = '\0'; // Null-terminate at the space
  2036. }
  2037. }
  2038. // Move the index forward by the determined line_length
  2039. i += line_length;
  2040. // Skip any spaces at the beginning of the next line
  2041. while (i < message_length && message[i] == ' ')
  2042. {
  2043. i++;
  2044. }
  2045. }
  2046. // Manually copy the fixed line into the formatted_message buffer
  2047. for (uint32_t j = 0; j < line_length; j++)
  2048. {
  2049. formatted_message[formatted_index++] = line[j];
  2050. }
  2051. // Add a newline character for line spacing
  2052. formatted_message[formatted_index++] = '\n';
  2053. }
  2054. // Null-terminate the formatted_message
  2055. formatted_message[formatted_index] = '\0';
  2056. // Add the formatted message to the widget
  2057. widget_add_text_scroll_element(*widget, 0, 0, 128, 64, formatted_message);
  2058. }
  2059. void flip_social_loader_draw_callback(Canvas *canvas, void *model)
  2060. {
  2061. if (!canvas || !model)
  2062. {
  2063. FURI_LOG_E(TAG, "flip_social_loader_draw_callback - canvas or model is NULL");
  2064. return;
  2065. }
  2066. SerialState http_state = fhttp.state;
  2067. DataLoaderModel *data_loader_model = (DataLoaderModel *)model;
  2068. DataState data_state = data_loader_model->data_state;
  2069. char *title = data_loader_model->title;
  2070. canvas_set_font(canvas, FontSecondary);
  2071. if (http_state == INACTIVE)
  2072. {
  2073. canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
  2074. canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
  2075. canvas_draw_str(canvas, 0, 32, "If your board is connected,");
  2076. canvas_draw_str(canvas, 0, 42, "make sure you have flashed");
  2077. canvas_draw_str(canvas, 0, 52, "your WiFi Devboard with the");
  2078. canvas_draw_str(canvas, 0, 62, "latest FlipperHTTP flash.");
  2079. return;
  2080. }
  2081. if (data_state == DataStateError || data_state == DataStateParseError)
  2082. {
  2083. flip_social_request_error_draw(canvas);
  2084. return;
  2085. }
  2086. canvas_draw_str(canvas, 0, 7, title);
  2087. canvas_draw_str(canvas, 0, 17, "Loading...");
  2088. if (data_state == DataStateInitial)
  2089. {
  2090. return;
  2091. }
  2092. if (http_state == SENDING)
  2093. {
  2094. canvas_draw_str(canvas, 0, 27, "Fetching...");
  2095. return;
  2096. }
  2097. if (http_state == RECEIVING || data_state == DataStateRequested)
  2098. {
  2099. canvas_draw_str(canvas, 0, 27, "Receiving...");
  2100. return;
  2101. }
  2102. if (http_state == IDLE && data_state == DataStateReceived)
  2103. {
  2104. canvas_draw_str(canvas, 0, 27, "Processing...");
  2105. return;
  2106. }
  2107. if (http_state == IDLE && data_state == DataStateParsed)
  2108. {
  2109. canvas_draw_str(canvas, 0, 27, "Processed...");
  2110. return;
  2111. }
  2112. }
  2113. static void flip_social_loader_process_callback(void *context)
  2114. {
  2115. if (context == NULL)
  2116. {
  2117. FURI_LOG_E(TAG, "flip_social_loader_process_callback - context is NULL");
  2118. DEV_CRASH();
  2119. return;
  2120. }
  2121. FlipSocialApp *app = (FlipSocialApp *)context;
  2122. View *view = app->view_loader;
  2123. DataState current_data_state;
  2124. with_view_model(view, DataLoaderModel * model, { current_data_state = model->data_state; }, false);
  2125. if (current_data_state == DataStateInitial)
  2126. {
  2127. with_view_model(
  2128. view,
  2129. DataLoaderModel * model,
  2130. {
  2131. model->data_state = DataStateRequested;
  2132. DataLoaderFetch fetch = model->fetcher;
  2133. if (fetch == NULL)
  2134. {
  2135. FURI_LOG_E(TAG, "Model doesn't have Fetch function assigned.");
  2136. model->data_state = DataStateError;
  2137. return;
  2138. }
  2139. // Clear any previous responses
  2140. strncpy(fhttp.last_response, "", 1);
  2141. bool request_status = fetch(model);
  2142. if (!request_status)
  2143. {
  2144. model->data_state = DataStateError;
  2145. }
  2146. },
  2147. true);
  2148. }
  2149. else if (current_data_state == DataStateRequested || current_data_state == DataStateError)
  2150. {
  2151. if (fhttp.state == IDLE && fhttp.last_response != NULL)
  2152. {
  2153. if (strstr(fhttp.last_response, "[PONG]") != NULL)
  2154. {
  2155. FURI_LOG_DEV(TAG, "PONG received.");
  2156. }
  2157. else if (strncmp(fhttp.last_response, "[SUCCESS]", 9) == 0)
  2158. {
  2159. FURI_LOG_DEV(TAG, "SUCCESS received. %s", fhttp.last_response ? fhttp.last_response : "NULL");
  2160. }
  2161. else if (strncmp(fhttp.last_response, "[ERROR]", 9) == 0)
  2162. {
  2163. FURI_LOG_DEV(TAG, "ERROR received. %s", fhttp.last_response ? fhttp.last_response : "NULL");
  2164. }
  2165. else if (strlen(fhttp.last_response) == 0)
  2166. {
  2167. // Still waiting on response
  2168. }
  2169. else
  2170. {
  2171. with_view_model(view, DataLoaderModel * model, { model->data_state = DataStateReceived; }, true);
  2172. }
  2173. }
  2174. else if (fhttp.state == SENDING || fhttp.state == RECEIVING)
  2175. {
  2176. // continue waiting
  2177. }
  2178. else if (fhttp.state == INACTIVE)
  2179. {
  2180. // inactive. try again
  2181. }
  2182. else if (fhttp.state == ISSUE)
  2183. {
  2184. with_view_model(view, DataLoaderModel * model, { model->data_state = DataStateError; }, true);
  2185. }
  2186. else
  2187. {
  2188. FURI_LOG_DEV(TAG, "Unexpected state: %d lastresp: %s", fhttp.state, fhttp.last_response ? fhttp.last_response : "NULL");
  2189. DEV_CRASH();
  2190. }
  2191. }
  2192. else if (current_data_state == DataStateReceived)
  2193. {
  2194. with_view_model(
  2195. view,
  2196. DataLoaderModel * model,
  2197. {
  2198. char *data_text;
  2199. if (model->parser == NULL)
  2200. {
  2201. data_text = NULL;
  2202. FURI_LOG_DEV(TAG, "Parser is NULL");
  2203. DEV_CRASH();
  2204. }
  2205. else
  2206. {
  2207. data_text = model->parser(model);
  2208. }
  2209. FURI_LOG_DEV(TAG, "Parsed data: %s\r\ntext: %s", fhttp.last_response ? fhttp.last_response : "NULL", data_text ? data_text : "NULL");
  2210. model->data_text = data_text;
  2211. if (data_text == NULL)
  2212. {
  2213. model->data_state = DataStateParseError;
  2214. }
  2215. else
  2216. {
  2217. model->data_state = DataStateParsed;
  2218. }
  2219. },
  2220. true);
  2221. }
  2222. else if (current_data_state == DataStateParsed)
  2223. {
  2224. with_view_model(
  2225. view,
  2226. DataLoaderModel * model,
  2227. {
  2228. if (++model->request_index < model->request_count)
  2229. {
  2230. model->data_state = DataStateInitial;
  2231. }
  2232. else
  2233. {
  2234. flip_social_widget_set_text(model->data_text != NULL ? model->data_text : "", &app_instance->widget_result);
  2235. if (model->data_text != NULL)
  2236. {
  2237. free(model->data_text);
  2238. model->data_text = NULL;
  2239. }
  2240. view_set_previous_callback(widget_get_view(app_instance->widget_result), model->back_callback);
  2241. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipSocialViewWidgetResult);
  2242. }
  2243. },
  2244. true);
  2245. }
  2246. }
  2247. static void flip_social_loader_timer_callback(void *context)
  2248. {
  2249. if (context == NULL)
  2250. {
  2251. FURI_LOG_E(TAG, "flip_social_loader_timer_callback - context is NULL");
  2252. DEV_CRASH();
  2253. return;
  2254. }
  2255. FlipSocialApp *app = (FlipSocialApp *)context;
  2256. view_dispatcher_send_custom_event(app->view_dispatcher, FlipSocialCustomEventProcess);
  2257. }
  2258. static void flip_social_loader_on_enter(void *context)
  2259. {
  2260. if (context == NULL)
  2261. {
  2262. FURI_LOG_E(TAG, "flip_social_loader_on_enter - context is NULL");
  2263. DEV_CRASH();
  2264. return;
  2265. }
  2266. FlipSocialApp *app = (FlipSocialApp *)context;
  2267. View *view = app->view_loader;
  2268. with_view_model(
  2269. view,
  2270. DataLoaderModel * model,
  2271. {
  2272. view_set_previous_callback(view, model->back_callback);
  2273. if (model->timer == NULL)
  2274. {
  2275. model->timer = furi_timer_alloc(flip_social_loader_timer_callback, FuriTimerTypePeriodic, app);
  2276. }
  2277. furi_timer_start(model->timer, 250);
  2278. },
  2279. true);
  2280. }
  2281. static void flip_social_loader_on_exit(void *context)
  2282. {
  2283. if (context == NULL)
  2284. {
  2285. FURI_LOG_E(TAG, "flip_social_loader_on_exit - context is NULL");
  2286. DEV_CRASH();
  2287. return;
  2288. }
  2289. FlipSocialApp *app = (FlipSocialApp *)context;
  2290. View *view = app->view_loader;
  2291. with_view_model(
  2292. view,
  2293. DataLoaderModel * model,
  2294. {
  2295. if (model->timer)
  2296. {
  2297. furi_timer_stop(model->timer);
  2298. }
  2299. },
  2300. false);
  2301. }
  2302. void flip_social_loader_init(View *view)
  2303. {
  2304. if (view == NULL)
  2305. {
  2306. FURI_LOG_E(TAG, "flip_social_loader_init - view is NULL");
  2307. DEV_CRASH();
  2308. return;
  2309. }
  2310. view_allocate_model(view, ViewModelTypeLocking, sizeof(DataLoaderModel));
  2311. view_set_enter_callback(view, flip_social_loader_on_enter);
  2312. view_set_exit_callback(view, flip_social_loader_on_exit);
  2313. }
  2314. void flip_social_loader_free_model(View *view)
  2315. {
  2316. if (view == NULL)
  2317. {
  2318. FURI_LOG_E(TAG, "flip_social_loader_free_model - view is NULL");
  2319. DEV_CRASH();
  2320. return;
  2321. }
  2322. with_view_model(
  2323. view,
  2324. DataLoaderModel * model,
  2325. {
  2326. if (model->timer)
  2327. {
  2328. furi_timer_free(model->timer);
  2329. model->timer = NULL;
  2330. }
  2331. if (model->parser_context)
  2332. {
  2333. free(model->parser_context);
  2334. model->parser_context = NULL;
  2335. }
  2336. },
  2337. false);
  2338. }
  2339. bool flip_social_custom_event_callback(void *context, uint32_t index)
  2340. {
  2341. if (context == NULL)
  2342. {
  2343. FURI_LOG_E(TAG, "flip_social_custom_event_callback - context is NULL");
  2344. DEV_CRASH();
  2345. return false;
  2346. }
  2347. switch (index)
  2348. {
  2349. case FlipSocialCustomEventProcess:
  2350. flip_social_loader_process_callback(context);
  2351. return true;
  2352. default:
  2353. FURI_LOG_DEV(TAG, "flip_social_custom_event_callback. Unknown index: %ld", index);
  2354. return false;
  2355. }
  2356. }
  2357. 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)
  2358. {
  2359. if (app == NULL)
  2360. {
  2361. FURI_LOG_E(TAG, "flip_social_generic_switch_to_view - app is NULL");
  2362. DEV_CRASH();
  2363. return;
  2364. }
  2365. View *view = app->view_loader;
  2366. if (view == NULL)
  2367. {
  2368. FURI_LOG_E(TAG, "flip_social_generic_switch_to_view - view is NULL");
  2369. DEV_CRASH();
  2370. return;
  2371. }
  2372. with_view_model(
  2373. view,
  2374. DataLoaderModel * model,
  2375. {
  2376. model->title = title;
  2377. model->fetcher = fetcher;
  2378. model->parser = parser;
  2379. model->request_index = 0;
  2380. model->request_count = request_count;
  2381. model->back_callback = back;
  2382. model->data_state = DataStateInitial;
  2383. model->data_text = NULL;
  2384. },
  2385. true);
  2386. view_dispatcher_switch_to_view(app->view_dispatcher, view_id);
  2387. }
  2388. static bool flip_social_get_home_notification()
  2389. {
  2390. if (!app_instance)
  2391. {
  2392. FURI_LOG_E(TAG, "app_instance is NULL");
  2393. return false;
  2394. }
  2395. if (!flipper_http_init(flipper_http_rx_callback, app_instance))
  2396. {
  2397. FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP");
  2398. return false;
  2399. }
  2400. // Create the directory for saving settings
  2401. char directory_path[256];
  2402. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/data");
  2403. // Create the directory
  2404. Storage *storage = furi_record_open(RECORD_STORAGE);
  2405. storage_common_mkdir(storage, directory_path);
  2406. furi_record_close(RECORD_STORAGE);
  2407. auth_headers_alloc();
  2408. snprintf(
  2409. fhttp.file_path,
  2410. sizeof(fhttp.file_path),
  2411. STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/data/notification.json");
  2412. fhttp.save_received_data = true;
  2413. return flipper_http_get_request_with_headers("https://www.flipsocial.net/api/flip-social-notifications/", auth_headers);
  2414. }
  2415. static bool flip_social_parse_home_notification()
  2416. {
  2417. FuriString *notification = flipper_http_load_from_file(fhttp.file_path);
  2418. if (notification == NULL)
  2419. {
  2420. FURI_LOG_E(TAG, "Failed to load notification from file");
  2421. flipper_http_deinit();
  2422. return false;
  2423. }
  2424. flipper_http_deinit();
  2425. // Check if announcement and analytics key exists
  2426. FuriString *announcement_json = get_json_value_furi("announcement", notification);
  2427. FuriString *analytics_json = get_json_value_furi("analytics", notification);
  2428. if (announcement_json == NULL || analytics_json == NULL)
  2429. {
  2430. FURI_LOG_E(TAG, "Failed to get announcement or analytics from notification");
  2431. if (announcement_json)
  2432. {
  2433. furi_string_free(announcement_json);
  2434. }
  2435. if (analytics_json)
  2436. {
  2437. furi_string_free(analytics_json);
  2438. }
  2439. furi_string_free(notification);
  2440. return false;
  2441. }
  2442. // Extract values from JSON
  2443. FuriString *announcement_value = get_json_value_furi("content", announcement_json);
  2444. FuriString *announcement_time = get_json_value_furi("date_created", announcement_json);
  2445. FuriString *analytics_value = get_json_value_furi("count", analytics_json);
  2446. FuriString *analytics_time = get_json_value_furi("time", analytics_json);
  2447. if (!announcement_value || !announcement_time || !analytics_value || !analytics_time)
  2448. {
  2449. FURI_LOG_E(TAG, "Failed to get announcement or analytics value from notification");
  2450. if (announcement_value)
  2451. {
  2452. furi_string_free(announcement_value);
  2453. }
  2454. if (announcement_time)
  2455. {
  2456. furi_string_free(announcement_time);
  2457. }
  2458. if (analytics_value)
  2459. {
  2460. furi_string_free(analytics_value);
  2461. }
  2462. if (analytics_time)
  2463. {
  2464. furi_string_free(analytics_time);
  2465. }
  2466. furi_string_free(announcement_json);
  2467. furi_string_free(analytics_json);
  2468. furi_string_free(notification);
  2469. return false;
  2470. }
  2471. // Load previous announcement and analytics times
  2472. char past_analytics_time[32] = {0};
  2473. char past_announcement_time[32] = {0};
  2474. bool analytics_time_loaded = load_char("analytics_time", past_analytics_time, sizeof(past_analytics_time));
  2475. bool announcement_time_loaded = load_char("announcement_time", past_announcement_time, sizeof(past_announcement_time));
  2476. bool new_announcement = false;
  2477. bool new_analytics = false;
  2478. // Check for new announcement
  2479. if (!announcement_time_loaded || strcmp(furi_string_get_cstr(announcement_time), past_announcement_time) != 0)
  2480. {
  2481. new_announcement = true;
  2482. }
  2483. // Check for new analytics
  2484. if (!analytics_time_loaded || strcmp(furi_string_get_cstr(analytics_time), past_analytics_time) != 0)
  2485. {
  2486. new_analytics = true;
  2487. }
  2488. // If no new announcement and no new analytics, exit early
  2489. if (!new_announcement && !new_analytics)
  2490. {
  2491. FURI_LOG_D(TAG, "No new announcement or analytics");
  2492. furi_string_free(announcement_value);
  2493. furi_string_free(announcement_time);
  2494. furi_string_free(analytics_value);
  2495. furi_string_free(analytics_time);
  2496. furi_string_free(announcement_json);
  2497. furi_string_free(analytics_json);
  2498. furi_string_free(notification);
  2499. return true;
  2500. }
  2501. // Save the new announcement and analytics times if they are new
  2502. if (new_announcement)
  2503. {
  2504. save_char("announcement_time", furi_string_get_cstr(announcement_time));
  2505. }
  2506. if (new_analytics)
  2507. {
  2508. save_char("analytics_time", furi_string_get_cstr(analytics_time));
  2509. }
  2510. // Prepare and show dialogs based on what is new
  2511. if (new_announcement)
  2512. {
  2513. easy_flipper_dialog("Announcement", (char *)furi_string_get_cstr(announcement_value));
  2514. }
  2515. if (new_analytics)
  2516. {
  2517. char analytics_text[128] = {0};
  2518. // Determine the new posts count
  2519. if (atoi(furi_string_get_cstr(analytics_value)) > 0)
  2520. {
  2521. char past_analytics_value[32] = {0};
  2522. int new_posts = 0;
  2523. if (load_char("analytics_value", past_analytics_value, sizeof(past_analytics_value)))
  2524. {
  2525. int past_posts = atoi(past_analytics_value);
  2526. int current_posts = atoi(furi_string_get_cstr(analytics_value));
  2527. new_posts = current_posts - past_posts;
  2528. snprintf(analytics_text, sizeof(analytics_text), "%d new posts", new_posts);
  2529. }
  2530. else
  2531. {
  2532. snprintf(analytics_text, sizeof(analytics_text), "%s feed posts", furi_string_get_cstr(analytics_value));
  2533. }
  2534. save_char("analytics_value", furi_string_get_cstr(analytics_value));
  2535. }
  2536. else
  2537. {
  2538. snprintf(analytics_text, sizeof(analytics_text), "%s feed posts", furi_string_get_cstr(analytics_value));
  2539. }
  2540. easy_flipper_dialog("Notifications", analytics_text);
  2541. }
  2542. // Free allocated resources
  2543. furi_string_free(announcement_value);
  2544. furi_string_free(announcement_time);
  2545. furi_string_free(analytics_value);
  2546. furi_string_free(analytics_time);
  2547. furi_string_free(announcement_json);
  2548. furi_string_free(analytics_json);
  2549. furi_string_free(notification);
  2550. return true;
  2551. }
  2552. // home notification
  2553. bool flip_social_home_notification()
  2554. {
  2555. return flipper_http_process_response_async(flip_social_get_home_notification, flip_social_parse_home_notification);
  2556. }