html.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938
  1. /* snac - A simple, minimalistic ActivityPub instance */
  2. /* copyright (c) 2022 - 2023 grunfink / MIT license */
  3. #include "xs.h"
  4. #include "xs_io.h"
  5. #include "xs_json.h"
  6. #include "xs_regex.h"
  7. #include "xs_set.h"
  8. #include "xs_openssl.h"
  9. #include "xs_time.h"
  10. #include "xs_mime.h"
  11. #include "snac.h"
  12. int login(snac *snac, const xs_dict *headers)
  13. /* tries a login */
  14. {
  15. int logged_in = 0;
  16. const char *auth = xs_dict_get(headers, "authorization");
  17. if (auth && xs_startswith(auth, "Basic ")) {
  18. int sz;
  19. xs *s1 = xs_crop_i(xs_dup(auth), 6, 0);
  20. xs *s2 = xs_base64_dec(s1, &sz);
  21. xs *l1 = xs_split_n(s2, ":", 1);
  22. if (xs_list_len(l1) == 2) {
  23. logged_in = check_password(
  24. xs_list_get(l1, 0), xs_list_get(l1, 1),
  25. xs_dict_get(snac->config, "passwd"));
  26. }
  27. }
  28. if (logged_in)
  29. lastlog_write(snac, "web");
  30. return logged_in;
  31. }
  32. xs_str *actor_name(xs_dict *actor)
  33. /* gets the actor name */
  34. {
  35. xs_list *p;
  36. char *v;
  37. xs_str *name;
  38. if (xs_is_null((v = xs_dict_get(actor, "name"))) || *v == '\0') {
  39. if (xs_is_null(v = xs_dict_get(actor, "preferredUsername")) || *v == '\0') {
  40. v = "anonymous";
  41. }
  42. }
  43. name = xs_dup(v);
  44. /* replace the :shortnames: */
  45. if (!xs_is_null(p = xs_dict_get(actor, "tag"))) {
  46. /* iterate the tags */
  47. while (xs_list_iter(&p, &v)) {
  48. char *t = xs_dict_get(v, "type");
  49. if (t && strcmp(t, "Emoji") == 0) {
  50. char *n = xs_dict_get(v, "name");
  51. char *i = xs_dict_get(v, "icon");
  52. if (n && i) {
  53. char *u = xs_dict_get(i, "url");
  54. xs *img = xs_fmt("<img src=\"%s\" style=\"height: 1em\" loading=\"lazy\"/>", u);
  55. name = xs_replace_i(name, n, img);
  56. }
  57. }
  58. }
  59. }
  60. return name;
  61. }
  62. xs_str *html_actor_icon(xs_str *os, char *actor,
  63. const char *date, const char *udate, const char *url, int priv)
  64. {
  65. xs *s = xs_str_new(NULL);
  66. xs *avatar = NULL;
  67. char *v;
  68. xs *name = actor_name(actor);
  69. /* get the avatar */
  70. if ((v = xs_dict_get(actor, "icon")) != NULL &&
  71. (v = xs_dict_get(v, "url")) != NULL) {
  72. avatar = xs_dup(v);
  73. }
  74. if (avatar == NULL)
  75. avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64());
  76. {
  77. xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" src=\"%s\" alt=\"\" "
  78. "loading=\"lazy\"/>\n", avatar);
  79. s = xs_str_cat(s, s1);
  80. }
  81. {
  82. xs *s1 = xs_fmt("<a href=\"%s\" class=\"p-author h-card snac-author\">%s</a>",
  83. xs_dict_get(actor, "id"), name);
  84. s = xs_str_cat(s, s1);
  85. }
  86. if (!xs_is_null(url)) {
  87. xs *s1 = xs_fmt(" <a href=\"%s\">»</a>", url);
  88. s = xs_str_cat(s, s1);
  89. }
  90. if (priv)
  91. s = xs_str_cat(s, " <span title=\"private\">&#128274;</span>");
  92. if (xs_is_null(date)) {
  93. s = xs_str_cat(s, "<br>\n&nbsp;\n");
  94. }
  95. else {
  96. xs *date_label = xs_crop_i(xs_dup(date), 0, 10);
  97. xs *date_title = xs_dup(date);
  98. if (!xs_is_null(udate)) {
  99. xs *sd = xs_crop_i(xs_dup(udate), 0, 10);
  100. date_label = xs_str_cat(date_label, " / ");
  101. date_label = xs_str_cat(date_label, sd);
  102. date_title = xs_str_cat(date_title, " / ");
  103. date_title = xs_str_cat(date_title, udate);
  104. }
  105. xs *s1 = xs_fmt(
  106. "<br>\n<time class=\"dt-published snac-pubdate\" title=\"%s\">%s</time>\n",
  107. date_title, date_label);
  108. s = xs_str_cat(s, s1);
  109. }
  110. return xs_str_cat(os, s);
  111. }
  112. xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg)
  113. {
  114. char *actor_id;
  115. xs *actor = NULL;
  116. if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
  117. actor_id = xs_dict_get(msg, "actor");
  118. if (actor_id && valid_status(actor_get(snac, actor_id, &actor))) {
  119. char *date = NULL;
  120. char *udate = NULL;
  121. char *url = NULL;
  122. int priv = 0;
  123. if (strcmp(xs_dict_get(msg, "type"), "Note") == 0)
  124. url = xs_dict_get(msg, "id");
  125. priv = !is_msg_public(snac, msg);
  126. date = xs_dict_get(msg, "published");
  127. udate = xs_dict_get(msg, "updated");
  128. os = html_actor_icon(os, actor, date, udate, url, priv);
  129. }
  130. return os;
  131. }
  132. d_char *html_user_header(snac *snac, d_char *s, int local)
  133. /* creates the HTML header */
  134. {
  135. char *p, *v;
  136. s = xs_str_cat(s, "<!DOCTYPE html>\n<html>\n<head>\n");
  137. s = xs_str_cat(s, "<meta name=\"viewport\" "
  138. "content=\"width=device-width, initial-scale=1\"/>\n");
  139. s = xs_str_cat(s, "<meta name=\"generator\" "
  140. "content=\"" USER_AGENT "\"/>\n");
  141. /* add server CSS */
  142. p = xs_dict_get(srv_config, "cssurls");
  143. while (xs_list_iter(&p, &v)) {
  144. xs *s1 = xs_fmt("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\"/>\n", v);
  145. s = xs_str_cat(s, s1);
  146. }
  147. /* add the user CSS */
  148. {
  149. xs *css = NULL;
  150. int size;
  151. if (valid_status(static_get(snac, "style.css", &css, &size))) {
  152. xs *s1 = xs_fmt("<style>%s</style>\n", css);
  153. s = xs_str_cat(s, s1);
  154. }
  155. }
  156. {
  157. xs *s1 = xs_fmt("<title>%s (@%s@%s)</title>\n",
  158. xs_dict_get(snac->config, "name"),
  159. snac->uid,
  160. xs_dict_get(srv_config, "host"));
  161. s = xs_str_cat(s, s1);
  162. }
  163. xs *avatar = xs_dup(xs_dict_get(snac->config, "avatar"));
  164. if (avatar == NULL || *avatar == '\0') {
  165. xs_free(avatar);
  166. avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64());
  167. }
  168. {
  169. xs *s_bio = xs_dup(xs_dict_get(snac->config, "bio"));
  170. int n;
  171. /* shorten the bio */
  172. for (n = 0; s_bio[n] && s_bio[n] != '&' &&
  173. s_bio[n] != '\r' && s_bio[n] != '\n' && n < 128; n++);
  174. s_bio[n] = '\0';
  175. xs *s_avatar = xs_dup(avatar);
  176. /* don't inline an empty avatar: create a real link */
  177. if (xs_startswith(s_avatar, "data:")) {
  178. xs_free(s_avatar);
  179. s_avatar = xs_fmt("%s/susie.png", srv_baseurl);
  180. }
  181. /* og properties */
  182. xs *s1 = xs_fmt(
  183. "<meta property=\"og:site_name\" content=\"%s\"/>\n"
  184. "<meta property=\"og:title\" content=\"%s (@%s@%s)\"/>\n"
  185. "<meta property=\"og:description\" content=\"%s\"/>\n"
  186. "<meta property=\"og:image\" content=\"%s\"/>\n"
  187. "<meta property=\"og:image:width\" content=\"300\"/>\n"
  188. "<meta property=\"og:image:height\" content=\"300\"/>\n",
  189. xs_dict_get(srv_config, "host"),
  190. xs_dict_get(snac->config, "name"),
  191. snac->uid,
  192. xs_dict_get(srv_config, "host"),
  193. s_bio,
  194. s_avatar);
  195. s = xs_str_cat(s, s1);
  196. }
  197. {
  198. xs *s1 = xs_fmt("<link rel=\"alternate\" type=\"application/rss+xml\" "
  199. "title=\"RSS\" href=\"%s.rss\" />\n", snac->actor);
  200. s = xs_str_cat(s, s1);
  201. }
  202. s = xs_str_cat(s, "</head>\n<body>\n");
  203. /* top nav */
  204. s = xs_str_cat(s, "<nav class=\"snac-top-nav\">");
  205. {
  206. xs *s1;
  207. s1 = xs_fmt("<img src=\"%s\" class=\"snac-avatar\" alt=\"\"/>&nbsp;", avatar);
  208. s = xs_str_cat(s, s1);
  209. }
  210. {
  211. xs *s1;
  212. if (local)
  213. s1 = xs_fmt(
  214. "<a href=\"%s.rss\">%s</a> - "
  215. "<a href=\"%s/admin\" rel=\"nofollow\">%s</a></nav>\n",
  216. snac->actor, L("RSS"),
  217. snac->actor, L("private"));
  218. else {
  219. xs *n_list = notify_list(snac, 1);
  220. int n_len = xs_list_len(n_list);
  221. xs *n_str = NULL;
  222. /* show the number of new notifications, if there are any */
  223. if (n_len)
  224. n_str = xs_fmt("<sup style=\"background-color: red; "
  225. "color: white;\"> %d </sup> ", n_len);
  226. else
  227. n_str = xs_str_new("");
  228. s1 = xs_fmt(
  229. "<a href=\"%s\">%s</a> - "
  230. "<a href=\"%s/admin\">%s</a> - "
  231. "<a href=\"%s/notifications\">%s</a>%s - "
  232. "<a href=\"%s/people\">%s</a></nav>\n",
  233. snac->actor, L("public"),
  234. snac->actor, L("private"),
  235. snac->actor, L("notifications"), n_str,
  236. snac->actor, L("people"));
  237. }
  238. s = xs_str_cat(s, s1);
  239. }
  240. /* user info */
  241. {
  242. char *_tmpl =
  243. "<div class=\"h-card snac-top-user\">\n"
  244. "<p class=\"p-name snac-top-user-name\">%s</p>\n"
  245. "<p class=\"snac-top-user-id\">@%s@%s</p>\n";
  246. xs *s1 = xs_fmt(_tmpl,
  247. xs_dict_get(snac->config, "name"),
  248. xs_dict_get(snac->config, "uid"), xs_dict_get(srv_config, "host")
  249. );
  250. s = xs_str_cat(s, s1);
  251. if (local) {
  252. xs *bio = not_really_markdown(xs_dict_get(snac->config, "bio"), NULL);
  253. xs *s1 = xs_fmt("<div class=\"p-note snac-top-user-bio\">%s</div>\n", bio);
  254. s = xs_str_cat(s, s1);
  255. }
  256. s = xs_str_cat(s, "</div>\n");
  257. }
  258. return s;
  259. }
  260. d_char *html_top_controls(snac *snac, d_char *s)
  261. /* generates the top controls */
  262. {
  263. char *_tmpl =
  264. "<div class=\"snac-top-controls\">\n"
  265. "<div class=\"snac-note\">\n"
  266. "<form method=\"post\" action=\"%s/admin/note\" enctype=\"multipart/form-data\">\n"
  267. "<textarea class=\"snac-textarea\" name=\"content\" "
  268. "rows=\"8\" wrap=\"virtual\" required=\"required\"></textarea>\n"
  269. "<input type=\"hidden\" name=\"in_reply_to\" value=\"\">\n"
  270. "<p>%s: <input type=\"checkbox\" name=\"sensitive\">\n"
  271. "<p>%s: <input type=\"checkbox\" name=\"mentioned_only\">\n"
  272. "<p>%s: <input type=\"file\" name=\"attach\">\n"
  273. "<p>%s: <input type=\"text\" name=\"alt_text\">\n"
  274. "<p><input type=\"submit\" class=\"button\" value=\"%s\">\n"
  275. "</form><p>\n"
  276. "</div>\n"
  277. "<div class=\"snac-top-controls-more\">\n"
  278. "<details><summary>%s</summary>\n"
  279. "<form method=\"post\" action=\"%s/admin/action\">\n"
  280. "<input type=\"text\" name=\"actor\" required=\"required\">\n"
  281. "<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n"
  282. "</form><p>\n"
  283. "<form method=\"post\" action=\"%s/admin/action\">\n"
  284. "<input type=\"text\" name=\"id\" required=\"required\">\n"
  285. "<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n"
  286. "</form><p>\n"
  287. "<details><summary>%s</summary>\n"
  288. "<div class=\"snac-user-setup\">\n"
  289. "<form method=\"post\" action=\"%s/admin/user-setup\" enctype=\"multipart/form-data\">\n"
  290. "<p>%s:<br>\n"
  291. "<input type=\"text\" name=\"name\" value=\"%s\"></p>\n"
  292. "<p>%s: <input type=\"file\" name=\"avatar_file\"></p>\n"
  293. "<p>%s:<br>\n"
  294. "<textarea name=\"bio\" cols=\"40\" rows=\"4\">%s</textarea></p>\n"
  295. "<p><input type=\"checkbox\" name=\"cw\" id=\"cw\" %s>\n"
  296. "<label for=\"cw\">%s</label></p>\n"
  297. "<p>%s:<br>\n"
  298. "<input type=\"text\" name=\"email\" value=\"%s\"></p>\n"
  299. "<p>%s:<br>\n"
  300. "<input type=\"text\" name=\"telegram_bot\" placeholder=\"Bot API key\" value=\"%s\"> "
  301. "<input type=\"text\" name=\"telegram_chat_id\" placeholder=\"Chat id\" value=\"%s\"></p>\n"
  302. "<p>%s:<br>\n"
  303. "<input type=\"number\" name=\"purge_days\" value=\"%s\"></p>\n"
  304. "<p><input type=\"checkbox\" name=\"drop_dm_from_unknown\" id=\"drop_dm_from_unknown\" %s>\n"
  305. "<label for=\"drop_dm_from_unknown\">%s</label></p>\n"
  306. "<p>%s:<br>\n"
  307. "<input type=\"password\" name=\"passwd1\" value=\"\"></p>\n"
  308. "<p>%s:<br>\n"
  309. "<input type=\"password\" name=\"passwd2\" value=\"\"></p>\n"
  310. "<input type=\"submit\" class=\"button\" value=\"%s\">\n"
  311. "</form>\n"
  312. "</div>\n"
  313. "</details>\n"
  314. "</details>\n"
  315. "</div>\n"
  316. "</div>\n";
  317. const char *email = "[disabled by admin]";
  318. if (xs_type(xs_dict_get(srv_config, "disable_email_notifications")) != XSTYPE_TRUE) {
  319. email = xs_dict_get(snac->config_o, "email");
  320. if (xs_is_null(email)) {
  321. email = xs_dict_get(snac->config, "email");
  322. if (xs_is_null(email))
  323. email = "";
  324. }
  325. }
  326. char *cw = xs_dict_get(snac->config, "cw");
  327. if (xs_is_null(cw))
  328. cw = "";
  329. char *telegram_bot = xs_dict_get(snac->config, "telegram_bot");
  330. if (xs_is_null(telegram_bot))
  331. telegram_bot = "";
  332. char *telegram_chat_id = xs_dict_get(snac->config, "telegram_chat_id");
  333. if (xs_is_null(telegram_chat_id))
  334. telegram_chat_id = "";
  335. const char *purge_days = xs_dict_get(snac->config, "purge_days");
  336. if (!xs_is_null(purge_days) && xs_type(purge_days) == XSTYPE_NUMBER)
  337. purge_days = xs_number_str(purge_days);
  338. else
  339. purge_days = "0";
  340. const char *d_dm_f_u = xs_dict_get(snac->config, "drop_dm_from_unknown");
  341. xs *s1 = xs_fmt(_tmpl,
  342. snac->actor,
  343. L("Sensitive content"),
  344. L("Only for mentioned people"),
  345. L("Image"),
  346. L("Image description"),
  347. L("Post"),
  348. L("More options..."),
  349. snac->actor,
  350. L("Follow"), L("(by URL or user@host)"),
  351. snac->actor,
  352. L("Boost"), L("(by URL)"),
  353. L("User setup..."),
  354. snac->actor,
  355. L("User name"),
  356. xs_dict_get(snac->config, "name"),
  357. L("Avatar"),
  358. L("Bio"),
  359. xs_dict_get(snac->config, "bio"),
  360. strcmp(cw, "open") == 0 ? "checked" : "",
  361. L("Always show sensitive content"),
  362. L("Email address for notifications"),
  363. email,
  364. L("Telegram notifications (bot key and chat id)"),
  365. telegram_bot,
  366. telegram_chat_id,
  367. L("Maximum days to keep posts (0: server settings)"),
  368. purge_days,
  369. xs_type(d_dm_f_u) == XSTYPE_TRUE ? "checked" : "",
  370. L("Drop direct messages from people you don't follow"),
  371. L("Password (only to change it)"),
  372. L("Repeat Password"),
  373. L("Update user info")
  374. );
  375. s = xs_str_cat(s, s1);
  376. return s;
  377. }
  378. d_char *html_button(d_char *s, char *clss, char *label)
  379. {
  380. xs *s1 = xs_fmt(
  381. "<input type=\"submit\" name=\"action\" "
  382. "class=\"snac-btn-%s\" value=\"%s\">\n",
  383. clss, label);
  384. return xs_str_cat(s, s1);
  385. }
  386. xs_str *build_mentions(snac *snac, const xs_dict *msg)
  387. /* returns a string with the mentions in msg */
  388. {
  389. xs_str *s = xs_str_new(NULL);
  390. char *list = xs_dict_get(msg, "tag");
  391. char *v;
  392. while (xs_list_iter(&list, &v)) {
  393. char *type = xs_dict_get(v, "type");
  394. char *href = xs_dict_get(v, "href");
  395. char *name = xs_dict_get(v, "name");
  396. if (type && strcmp(type, "Mention") == 0 &&
  397. href && strcmp(href, snac->actor) != 0 && name) {
  398. xs *s1 = NULL;
  399. if (name[0] != '@') {
  400. s1 = xs_fmt("@%s", name);
  401. name = s1;
  402. }
  403. xs *l = xs_split(name, "@");
  404. /* is it a name without a host? */
  405. if (xs_list_len(l) < 3) {
  406. /* split the href and pick the host name LIKE AN ANIMAL */
  407. /* would be better to query the webfinger but *won't do that* here */
  408. xs *l2 = xs_split(href, "/");
  409. if (xs_list_len(l2) >= 3) {
  410. xs *s1 = xs_fmt("%s@%s ", name, xs_list_get(l2, 2));
  411. s = xs_str_cat(s, s1);
  412. }
  413. }
  414. else {
  415. s = xs_str_cat(s, name);
  416. s = xs_str_cat(s, " ");
  417. }
  418. }
  419. }
  420. if (*s) {
  421. xs *s1 = s;
  422. s = xs_fmt("\n\n\nCC: %s", s1);
  423. }
  424. return s;
  425. }
  426. xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const char *md5)
  427. {
  428. char *id = xs_dict_get(msg, "id");
  429. char *actor = xs_dict_get(msg, "attributedTo");
  430. xs *likes = object_likes(id);
  431. xs *boosts = object_announces(id);
  432. xs *s = xs_str_new(NULL);
  433. s = xs_str_cat(s, "<div class=\"snac-controls\">\n");
  434. {
  435. xs *s1 = xs_fmt(
  436. "<form method=\"post\" action=\"%s/admin/action\">\n"
  437. "<input type=\"hidden\" name=\"id\" value=\"%s\">\n"
  438. "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n"
  439. "<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n"
  440. "\n",
  441. snac->actor, id, actor, md5
  442. );
  443. s = xs_str_cat(s, s1);
  444. }
  445. if (xs_list_in(likes, snac->md5) == -1) {
  446. /* not already liked; add button */
  447. s = html_button(s, "like", L("Like"));
  448. }
  449. if (is_msg_public(snac, msg)) {
  450. if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) {
  451. /* not already boosted or us; add button */
  452. s = html_button(s, "boost", L("Boost"));
  453. }
  454. }
  455. if (strcmp(actor, snac->actor) != 0) {
  456. /* controls for other actors than this one */
  457. if (following_check(snac, actor)) {
  458. s = html_button(s, "unfollow", L("Unfollow"));
  459. }
  460. else {
  461. s = html_button(s, "follow", L("Follow"));
  462. }
  463. s = html_button(s, "mute", L("MUTE"));
  464. }
  465. s = html_button(s, "delete", L("Delete"));
  466. s = html_button(s, "hide", L("Hide"));
  467. s = xs_str_cat(s, "</form>\n");
  468. char *prev_src = xs_dict_get(msg, "sourceContent");
  469. if (!xs_is_null(prev_src) && strcmp(actor, snac->actor) == 0) {
  470. /* post can be edited */
  471. xs *s1 = xs_fmt(
  472. "<p><details><summary>%s</summary>\n"
  473. "<p><div class=\"snac-note\" id=\"%s_edit\">\n"
  474. "<form method=\"post\" action=\"%s/admin/note\" "
  475. "enctype=\"multipart/form-data\" id=\"%s_edit_form\">\n"
  476. "<textarea class=\"snac-textarea\" name=\"content\" "
  477. "rows=\"4\" wrap=\"virtual\" required=\"required\">%s</textarea>\n"
  478. "<input type=\"hidden\" name=\"edit_id\" value=\"%s\">\n"
  479. "<p>%s: <input type=\"checkbox\" name=\"sensitive\">\n"
  480. "<p>%s: <input type=\"checkbox\" name=\"mentioned_only\">\n"
  481. "<p>%s: <input type=\"file\" name=\"attach\">\n"
  482. "<p>%s: <input type=\"text\" name=\"alt_text\">\n"
  483. "<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n"
  484. "<p><input type=\"submit\" class=\"button\" value=\"%s\">\n"
  485. "</form><p></div>\n"
  486. "</details><p>"
  487. "\n",
  488. L("Edit..."),
  489. md5,
  490. snac->actor, md5,
  491. prev_src,
  492. id,
  493. L("Sensitive content"),
  494. L("Only for mentioned people"),
  495. L("Image"),
  496. L("Image description"),
  497. md5,
  498. L("Post")
  499. );
  500. s = xs_str_cat(s, s1);
  501. }
  502. {
  503. /* the post textarea */
  504. xs *ct = build_mentions(snac, msg);
  505. xs *s1 = xs_fmt(
  506. "<p><details><summary>%s</summary>\n"
  507. "<p><div class=\"snac-note\" id=\"%s_reply\">\n"
  508. "<form method=\"post\" action=\"%s/admin/note\" "
  509. "enctype=\"multipart/form-data\" id=\"%s_reply_form\">\n"
  510. "<textarea class=\"snac-textarea\" name=\"content\" "
  511. "rows=\"4\" wrap=\"virtual\" required=\"required\">%s</textarea>\n"
  512. "<input type=\"hidden\" name=\"in_reply_to\" value=\"%s\">\n"
  513. "<p>%s: <input type=\"checkbox\" name=\"sensitive\">\n"
  514. "<p>%s: <input type=\"checkbox\" name=\"mentioned_only\">\n"
  515. "<p>%s: <input type=\"file\" name=\"attach\">\n"
  516. "<p>%s: <input type=\"text\" name=\"alt_text\">\n"
  517. "<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n"
  518. "<p><input type=\"submit\" class=\"button\" value=\"%s\">\n"
  519. "</form><p></div>\n"
  520. "</details><p>"
  521. "\n",
  522. L("Reply..."),
  523. md5,
  524. snac->actor, md5,
  525. ct,
  526. id,
  527. L("Sensitive content"),
  528. L("Only for mentioned people"),
  529. L("Image"),
  530. L("Image description"),
  531. md5,
  532. L("Post")
  533. );
  534. s = xs_str_cat(s, s1);
  535. }
  536. s = xs_str_cat(s, "</div>\n");
  537. return xs_str_cat(os, s);
  538. }
  539. xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
  540. int level, const char *md5, int hide_children)
  541. {
  542. char *id = xs_dict_get(msg, "id");
  543. char *type = xs_dict_get(msg, "type");
  544. char *actor;
  545. int sensitive = 0;
  546. char *v;
  547. xs *boosts = NULL;
  548. /* do not show non-public messages in the public timeline */
  549. if (local && !is_msg_public(snac, msg))
  550. return os;
  551. xs *s = xs_str_new(NULL);
  552. /* top wrap */
  553. if (is_hidden(snac, id))
  554. s = xs_str_cat(s, "<div style=\"display: none\">\n");
  555. else
  556. s = xs_str_cat(s, "<div>\n");
  557. {
  558. xs *s1 = xs_fmt("<a name=\"%s_entry\"></a>\n", md5);
  559. s = xs_str_cat(s, s1);
  560. }
  561. if (strcmp(type, "Follow") == 0) {
  562. s = xs_str_cat(s, "<div class=\"snac-post\">\n");
  563. xs *s1 = xs_fmt("<div class=\"snac-origin\">%s</div>\n", L("follows you"));
  564. s = xs_str_cat(s, s1);
  565. s = html_msg_icon(snac, s, msg);
  566. s = xs_str_cat(s, "</div>\n");
  567. return xs_str_cat(os, s);
  568. }
  569. else
  570. if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0) {
  571. /* skip oddities */
  572. return os;
  573. }
  574. /* bring the main actor */
  575. if ((actor = xs_dict_get(msg, "attributedTo")) == NULL)
  576. return os;
  577. /* ignore muted morons immediately */
  578. if (is_muted(snac, actor))
  579. return os;
  580. if (strcmp(actor, snac->actor) != 0 && !valid_status(actor_get(snac, actor, NULL)))
  581. return os;
  582. /* if this is our post, add the score */
  583. if (xs_startswith(id, snac->actor)) {
  584. int n_likes = object_likes_len(id);
  585. int n_boosts = object_announces_len(id);
  586. /* alternate emojis: %d &#128077; %d &#128257; */
  587. xs *s1 = xs_fmt(
  588. "<div class=\"snac-score\">%d &#9733; %d &#8634;</div>\n",
  589. n_likes, n_boosts);
  590. s = xs_str_cat(s, s1);
  591. }
  592. if (level == 0)
  593. s = xs_str_cat(s, "<div class=\"snac-post\">\n");
  594. else
  595. s = xs_str_cat(s, "<div class=\"snac-child\">\n");
  596. if (boosts == NULL)
  597. boosts = object_announces(id);
  598. if (xs_list_len(boosts)) {
  599. /* if somebody boosted this, show as origin */
  600. char *p = xs_list_get(boosts, -1);
  601. xs *actor_r = NULL;
  602. if (xs_list_in(boosts, snac->md5) != -1) {
  603. /* we boosted this */
  604. xs *s1 = xs_fmt(
  605. "<div class=\"snac-origin\">"
  606. "<a href=\"%s\">%s</a> %s</a></div>",
  607. snac->actor, xs_dict_get(snac->config, "name"), L("boosted")
  608. );
  609. s = xs_str_cat(s, s1);
  610. }
  611. else
  612. if (valid_status(object_get_by_md5(p, &actor_r))) {
  613. xs *name = actor_name(actor_r);
  614. if (!xs_is_null(name)) {
  615. xs *s1 = xs_fmt(
  616. "<div class=\"snac-origin\">"
  617. "<a href=\"%s\">%s</a> %s</div>\n",
  618. xs_dict_get(actor_r, "id"),
  619. name,
  620. L("boosted")
  621. );
  622. s = xs_str_cat(s, s1);
  623. }
  624. }
  625. }
  626. else
  627. if (strcmp(type, "Note") == 0) {
  628. if (level == 0) {
  629. /* is the parent not here? */
  630. char *parent = xs_dict_get(msg, "inReplyTo");
  631. if (!xs_is_null(parent) && *parent && !timeline_here(snac, parent)) {
  632. xs *s1 = xs_fmt(
  633. "<div class=\"snac-origin\">%s "
  634. "<a href=\"%s\">»</a></div>\n",
  635. L("in reply to"), parent
  636. );
  637. s = xs_str_cat(s, s1);
  638. }
  639. }
  640. }
  641. s = html_msg_icon(snac, s, msg);
  642. /* add the content */
  643. s = xs_str_cat(s, "<div class=\"e-content snac-content\">\n");
  644. /* is it sensitive? */
  645. if (!xs_is_null(v = xs_dict_get(msg, "sensitive")) && xs_type(v) == XSTYPE_TRUE) {
  646. if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0')
  647. v = "...";
  648. /* only show it when not in the public timeline and the config setting is "open" */
  649. char *cw = xs_dict_get(snac->config, "cw");
  650. if (xs_is_null(cw) || local)
  651. cw = "";
  652. xs *s1 = xs_fmt("<details %s><summary>%s [%s]</summary>\n", cw, v, L("SENSITIVE CONTENT"));
  653. s = xs_str_cat(s, s1);
  654. sensitive = 1;
  655. }
  656. #if 0
  657. {
  658. xs *md5 = xs_md5_hex(id, strlen(id));
  659. xs *s1 = xs_fmt("<p><code>%s</code></p>\n", md5);
  660. s = xs_str_cat(s, s1);
  661. }
  662. #endif
  663. {
  664. xs *c = sanitize(xs_dict_get(msg, "content"));
  665. char *p, *v;
  666. /* do some tweaks to the content */
  667. c = xs_replace_i(c, "\r", "");
  668. while (xs_endswith(c, "<br><br>"))
  669. c = xs_crop_i(c, 0, -4);
  670. c = xs_replace_i(c, "<br><br>", "<p>");
  671. if (!xs_startswith(c, "<p>")) {
  672. xs *s1 = c;
  673. c = xs_fmt("<p>%s</p>", s1);
  674. }
  675. /* replace the :shortnames: */
  676. if (!xs_is_null(p = xs_dict_get(msg, "tag"))) {
  677. /* iterate the tags */
  678. while (xs_list_iter(&p, &v)) {
  679. char *t = xs_dict_get(v, "type");
  680. if (t && strcmp(t, "Emoji") == 0) {
  681. char *n = xs_dict_get(v, "name");
  682. char *i = xs_dict_get(v, "icon");
  683. if (n && i) {
  684. char *u = xs_dict_get(i, "url");
  685. xs *img = xs_fmt("<img src=\"%s\" style=\"height: 1em\" "
  686. "loading=\"lazy\"/>", u);
  687. c = xs_replace_i(c, n, img);
  688. }
  689. }
  690. }
  691. }
  692. if (strcmp(type, "Question") == 0) {
  693. xs_list *oo = xs_dict_get(msg, "oneOf");
  694. xs_list *ao = xs_dict_get(msg, "anyOf");
  695. xs_list *p;
  696. xs_dict *v;
  697. p = oo != NULL ? oo : ao;
  698. if (!xs_is_null(xs_dict_get(msg, "closed"))) {
  699. /* closed poll */
  700. c = xs_str_cat(c, "<table>\n");
  701. while (xs_list_iter(&p, &v)) {
  702. const char *name = xs_dict_get(v, "name");
  703. const xs_dict *replies = xs_dict_get(v, "replies");
  704. if (name && replies) {
  705. int nr = xs_number_get(xs_dict_get(replies, "totalItems"));
  706. xs *l = xs_fmt("<tr><td>%s:</td><td>%d</td></tr>\n", name, nr);
  707. c = xs_str_cat(c, l);
  708. }
  709. }
  710. c = xs_str_cat(c, "</table>\n");
  711. }
  712. else {
  713. /* poll still active */
  714. }
  715. }
  716. s = xs_str_cat(s, c);
  717. }
  718. s = xs_str_cat(s, "\n");
  719. /* add the attachments */
  720. char *attach;
  721. if ((attach = xs_dict_get(msg, "attachment")) != NULL) {
  722. char *v;
  723. while (xs_list_iter(&attach, &v)) {
  724. char *t = xs_dict_get(v, "mediaType");
  725. if (xs_is_null(t))
  726. continue;
  727. if (xs_startswith(t, "image/")) {
  728. char *url = xs_dict_get(v, "url");
  729. char *name = xs_dict_get(v, "name");
  730. if (url != NULL) {
  731. xs *s1 = xs_fmt("<p><img src=\"%s\" alt=\"%s\" loading=\"lazy\"/></p>\n",
  732. url, xs_is_null(name) ? "" : name);
  733. s = xs_str_cat(s, s1);
  734. }
  735. }
  736. else
  737. if (xs_startswith(t, "video/")) {
  738. char *url = xs_dict_get(v, "url");
  739. if (url != NULL) {
  740. xs *s1 = xs_fmt("<p><object data=\"%s\"></object></p>\n", url);
  741. s = xs_str_cat(s, s1);
  742. }
  743. }
  744. }
  745. }
  746. if (sensitive)
  747. s = xs_str_cat(s, "</details><p>\n");
  748. s = xs_str_cat(s, "</div>\n");
  749. /** controls **/
  750. if (!local)
  751. s = html_entry_controls(snac, s, msg, md5);
  752. /** children **/
  753. if (!hide_children) {
  754. xs *children = object_children(id);
  755. int left = xs_list_len(children);
  756. if (left) {
  757. char *p, *cmd5;
  758. int older_open = 0;
  759. xs *ss = xs_str_new(NULL);
  760. int n_children = 0;
  761. ss = xs_str_cat(ss, "<details open><summary>...</summary><p>\n");
  762. if (level < 4)
  763. ss = xs_str_cat(ss, "<div class=\"snac-children\">\n");
  764. else
  765. ss = xs_str_cat(ss, "<div>\n");
  766. if (left > 3) {
  767. xs *s1 = xs_fmt("<details><summary>%s</summary>\n", L("Older..."));
  768. ss = xs_str_cat(ss, s1);
  769. older_open = 1;
  770. }
  771. p = children;
  772. while (xs_list_iter(&p, &cmd5)) {
  773. xs *chd = NULL;
  774. timeline_get_by_md5(snac, cmd5, &chd);
  775. if (older_open && left <= 3) {
  776. ss = xs_str_cat(ss, "</details>\n");
  777. older_open = 0;
  778. }
  779. if (chd != NULL) {
  780. ss = html_entry(snac, ss, chd, local, level + 1, cmd5, hide_children);
  781. n_children++;
  782. }
  783. else
  784. snac_debug(snac, 2, xs_fmt("cannot read from timeline child %s", cmd5));
  785. left--;
  786. }
  787. if (older_open)
  788. ss = xs_str_cat(ss, "</details>\n");
  789. ss = xs_str_cat(ss, "</div>\n");
  790. ss = xs_str_cat(ss, "</details>\n");
  791. if (n_children)
  792. s = xs_str_cat(s, ss);
  793. }
  794. }
  795. s = xs_str_cat(s, "</div>\n</div>\n");
  796. return xs_str_cat(os, s);
  797. }
  798. xs_str *html_user_footer(xs_str *s)
  799. {
  800. xs *s1 = xs_fmt(
  801. "<div class=\"snac-footer\">\n"
  802. "<a href=\"%s\">%s</a> - "
  803. "powered by <a href=\"%s\""
  804. "<abbr title=\"Social Networks Are Crap\">snac</abbr></div></a>\n",
  805. srv_baseurl,
  806. L("about this site"),
  807. WHAT_IS_SNAC_URL
  808. );
  809. return xs_str_cat(s, s1);
  810. }
  811. xs_str *html_timeline(snac *snac, const xs_list *list, int local, int skip, int show, int show_more)
  812. /* returns the HTML for the timeline */
  813. {
  814. xs_str *s = xs_str_new(NULL);
  815. xs_list *p = (xs_list *)list;
  816. char *v;
  817. double t = ftime();
  818. s = html_user_header(snac, s, local);
  819. if (!local)
  820. s = html_top_controls(snac, s);
  821. s = xs_str_cat(s, "<a name=\"snac-posts\"></a>\n");
  822. s = xs_str_cat(s, "<div class=\"snac-posts\">\n");
  823. while (xs_list_iter(&p, &v)) {
  824. xs *msg = NULL;
  825. if (!valid_status(timeline_get_by_md5(snac, v, &msg)))
  826. continue;
  827. s = html_entry(snac, s, msg, local, 0, v, 0);
  828. }
  829. s = xs_str_cat(s, "</div>\n");
  830. if (local) {
  831. xs *s1 = xs_fmt(
  832. "<div class=\"snac-history\">\n"
  833. "<p class=\"snac-history-title\">%s</p><ul>\n",
  834. L("History")
  835. );
  836. s = xs_str_cat(s, s1);
  837. xs *list = history_list(snac);
  838. char *p, *v;
  839. p = list;
  840. while (xs_list_iter(&p, &v)) {
  841. xs *fn = xs_replace(v, ".html", "");
  842. xs *s1 = xs_fmt(
  843. "<li><a href=\"%s/h/%s\">%s</a></li>\n",
  844. snac->actor, v, fn);
  845. s = xs_str_cat(s, s1);
  846. }
  847. s = xs_str_cat(s, "</ul></div>\n");
  848. }
  849. {
  850. xs *s1 = xs_fmt("<!-- %lf seconds -->\n", ftime() - t);
  851. s = xs_str_cat(s, s1);
  852. }
  853. if (show_more) {
  854. xs *s1 = xs_fmt(
  855. "<p>"
  856. "<a href=\"%s%s?skip=%d&show=%d\" name=\"snac-more\">%s</a>"
  857. "</p>\n", snac->actor, local ? "" : "/admin", skip + show, show, L("Load more..."));
  858. s = xs_str_cat(s, s1);
  859. }
  860. s = html_user_footer(s);
  861. s = xs_str_cat(s, "</body>\n</html>\n");
  862. return s;
  863. }
  864. d_char *html_people_list(snac *snac, d_char *os, d_char *list, const char *header, const char *t)
  865. {
  866. xs *s = xs_str_new(NULL);
  867. xs *h = xs_fmt("<h2>%s</h2>\n", header);
  868. char *p, *actor_id;
  869. s = xs_str_cat(s, h);
  870. p = list;
  871. while (xs_list_iter(&p, &actor_id)) {
  872. xs *md5 = xs_md5_hex(actor_id, strlen(actor_id));
  873. xs *actor = NULL;
  874. if (valid_status(actor_get(snac, actor_id, &actor))) {
  875. s = xs_str_cat(s, "<div class=\"snac-post\">\n");
  876. s = html_actor_icon(s, actor, xs_dict_get(actor, "published"), NULL, NULL, 0);
  877. /* content (user bio) */
  878. char *c = xs_dict_get(actor, "summary");
  879. if (!xs_is_null(c)) {
  880. s = xs_str_cat(s, "<div class=\"snac-content\">\n");
  881. xs *sc = sanitize(c);
  882. if (xs_startswith(sc, "<p>"))
  883. s = xs_str_cat(s, sc);
  884. else {
  885. xs *s1 = xs_fmt("<p>%s</p>", sc);
  886. s = xs_str_cat(s, s1);
  887. }
  888. s = xs_str_cat(s, "</div>\n");
  889. }
  890. /* buttons */
  891. s = xs_str_cat(s, "<div class=\"snac-controls\">\n");
  892. xs *s1 = xs_fmt(
  893. "<p><form method=\"post\" action=\"%s/admin/action\">\n"
  894. "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n"
  895. "<input type=\"hidden\" name=\"actor-form\" value=\"yes\">\n",
  896. snac->actor, actor_id
  897. );
  898. s = xs_str_cat(s, s1);
  899. if (following_check(snac, actor_id))
  900. s = html_button(s, "unfollow", L("Unfollow"));
  901. else {
  902. s = html_button(s, "follow", L("Follow"));
  903. if (follower_check(snac, actor_id))
  904. s = html_button(s, "delete", L("Delete"));
  905. }
  906. if (is_muted(snac, actor_id))
  907. s = html_button(s, "unmute", L("Unmute"));
  908. else
  909. s = html_button(s, "mute", L("MUTE"));
  910. s = xs_str_cat(s, "</form>\n");
  911. /* the post textarea */
  912. xs *s2 = xs_fmt(
  913. "<p><details><summary>%s</summary>\n"
  914. "<p><div class=\"snac-note\" id=\"%s_%s_dm\">\n"
  915. "<form method=\"post\" action=\"%s/admin/note\" "
  916. "enctype=\"multipart/form-data\" id=\"%s_reply_form\">\n"
  917. "<textarea class=\"snac-textarea\" name=\"content\" "
  918. "rows=\"4\" wrap=\"virtual\" required=\"required\"></textarea>\n"
  919. "<input type=\"hidden\" name=\"to\" value=\"%s\">\n"
  920. "<p><input type=\"file\" name=\"attach\">\n"
  921. "<p><input type=\"submit\" class=\"button\" value=\"%s\">\n"
  922. "</form><p></div>\n"
  923. "</details><p>\n",
  924. L("Direct Message..."),
  925. md5, t,
  926. snac->actor, md5,
  927. actor_id,
  928. L("Post")
  929. );
  930. s = xs_str_cat(s, s2);
  931. s = xs_str_cat(s, "</div>\n");
  932. s = xs_str_cat(s, "</div>\n");
  933. }
  934. }
  935. return xs_str_cat(os, s);
  936. }
  937. d_char *html_people(snac *snac)
  938. {
  939. d_char *s = xs_str_new(NULL);
  940. xs *wing = following_list(snac);
  941. xs *wers = follower_list(snac);
  942. s = html_user_header(snac, s, 0);
  943. s = html_people_list(snac, s, wing, L("People you follow"), "i");
  944. s = html_people_list(snac, s, wers, L("People that follows you"), "e");
  945. s = html_user_footer(s);
  946. s = xs_str_cat(s, "</body>\n</html>\n");
  947. return s;
  948. }
  949. xs_str *html_notifications(snac *snac)
  950. {
  951. xs_str *s = xs_str_new(NULL);
  952. xs *n_list = notify_list(snac, 0);
  953. xs *n_time = notify_check_time(snac, 0);
  954. xs_list *p = n_list;
  955. xs_str *v;
  956. enum { NHDR_NONE, NHDR_NEW, NHDR_OLD } stage = NHDR_NONE;
  957. s = html_user_header(snac, s, 0);
  958. xs *s1 = xs_fmt(
  959. "<form method=\"post\" action=\"%s/admin/clear-notifications\" id=\"clear\">\n"
  960. "<input type=\"submit\" class=\"snac-btn-like\" value=\"%s\">\n"
  961. "</form><p>", snac->actor, L("Clear all"));
  962. s = xs_str_cat(s, s1);
  963. while (xs_list_iter(&p, &v)) {
  964. xs *noti = notify_get(snac, v);
  965. if (noti == NULL)
  966. continue;
  967. xs *obj = NULL;
  968. const char *type = xs_dict_get(noti, "type");
  969. const char *id = xs_dict_get(noti, "objid");
  970. if (!valid_status(object_get(id, &obj)))
  971. continue;
  972. if (is_hidden(snac, id))
  973. continue;
  974. const char *actor_id = xs_dict_get(noti, "actor");
  975. xs *actor = NULL;
  976. if (!valid_status(actor_get(snac, actor_id, &actor)))
  977. continue;
  978. xs *a_name = actor_name(actor);
  979. if (strcmp(v, n_time) > 0) {
  980. /* unseen notification */
  981. if (stage == NHDR_NONE) {
  982. xs *s1 = xs_fmt("<h2>%s</h2>\n", L("New"));
  983. s = xs_str_cat(s, s1);
  984. stage = NHDR_NEW;
  985. }
  986. }
  987. else {
  988. /* already seen notification */
  989. if (stage != NHDR_OLD) {
  990. xs *s1 = xs_fmt("<h2>%s</h2>\n", L("Already seen"));
  991. s = xs_str_cat(s, s1);
  992. stage = NHDR_OLD;
  993. }
  994. }
  995. s = xs_str_cat(s, "<div>\n");
  996. xs *s1 = xs_fmt("<p><b>%s by <a href=\"%s\">%s</a></b>:</p>\n",
  997. strcmp(type, "Create") == 0 ? "Mention" : type, actor_id, a_name);
  998. s = xs_str_cat(s, s1);
  999. if (strcmp(type, "Follow") == 0) {
  1000. s = xs_str_cat(s, "<div class=\"snac-post\">\n");
  1001. s = html_msg_icon(snac, s, obj);
  1002. s = xs_str_cat(s, "</div>\n");
  1003. }
  1004. else {
  1005. xs *md5 = xs_md5_hex(id, strlen(id));
  1006. s = html_entry(snac, s, obj, 0, 0, md5, 1);
  1007. }
  1008. s = xs_str_cat(s, "</div>\n");
  1009. }
  1010. if (stage == NHDR_NONE) {
  1011. xs *s1 = xs_fmt("<h2>%s</h2>\n", L("None"));
  1012. s = xs_str_cat(s, s1);
  1013. }
  1014. s = html_user_footer(s);
  1015. s = xs_str_cat(s, "</body>\n</html>\n");
  1016. /* set the check time to now */
  1017. xs *dummy = notify_check_time(snac, 1);
  1018. dummy = xs_free(dummy);
  1019. timeline_touch(snac);
  1020. return s;
  1021. }
  1022. int html_get_handler(const xs_dict *req, const char *q_path,
  1023. char **body, int *b_size, char **ctype)
  1024. {
  1025. char *accept = xs_dict_get(req, "accept");
  1026. int status = 404;
  1027. snac snac;
  1028. xs *uid = NULL;
  1029. char *p_path;
  1030. int cache = 1;
  1031. int save = 1;
  1032. char *v;
  1033. xs *l = xs_split_n(q_path, "/", 2);
  1034. v = xs_list_get(l, 1);
  1035. if (xs_is_null(v)) {
  1036. srv_log(xs_fmt("html_get_handler bad query '%s'", q_path));
  1037. return 404;
  1038. }
  1039. uid = xs_dup(v);
  1040. /* rss extension? */
  1041. if (xs_endswith(uid, ".rss")) {
  1042. uid = xs_crop_i(uid, 0, -4);
  1043. p_path = ".rss";
  1044. }
  1045. else
  1046. p_path = xs_list_get(l, 2);
  1047. if (!uid || !user_open(&snac, uid)) {
  1048. /* invalid user */
  1049. srv_debug(1, xs_fmt("html_get_handler bad user %s", uid));
  1050. return 404;
  1051. }
  1052. /* return the RSS if requested by Accept header */
  1053. if (accept != NULL) {
  1054. if (xs_str_in(accept, "text/xml") != -1 ||
  1055. xs_str_in(accept, "application/rss+xml") != -1)
  1056. p_path = ".rss";
  1057. }
  1058. /* check if server config variable 'disable_cache' is set */
  1059. if ((v = xs_dict_get(srv_config, "disable_cache")) && xs_type(v) == XSTYPE_TRUE)
  1060. cache = 0;
  1061. int skip = 0;
  1062. int show = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries"));
  1063. char *q_vars = xs_dict_get(req, "q_vars");
  1064. if ((v = xs_dict_get(q_vars, "skip")) != NULL)
  1065. skip = atoi(v), cache = 0, save = 0;
  1066. if ((v = xs_dict_get(q_vars, "show")) != NULL)
  1067. show = atoi(v), cache = 0, save = 0;
  1068. if (p_path == NULL) { /** public timeline **/
  1069. xs *h = xs_str_localtime(0, "%Y-%m.html");
  1070. if (cache && history_mtime(&snac, h) > timeline_mtime(&snac)) {
  1071. snac_debug(&snac, 1, xs_fmt("serving cached local timeline"));
  1072. *body = history_get(&snac, h);
  1073. *b_size = strlen(*body);
  1074. status = 200;
  1075. }
  1076. else {
  1077. xs *list = timeline_list(&snac, "public", skip, show);
  1078. xs *next = timeline_list(&snac, "public", skip + show, 1);
  1079. *body = html_timeline(&snac, list, 1, skip, show, xs_list_len(next));
  1080. *b_size = strlen(*body);
  1081. status = 200;
  1082. if (save)
  1083. history_add(&snac, h, *body, *b_size);
  1084. }
  1085. }
  1086. else
  1087. if (strcmp(p_path, "admin") == 0) { /** private timeline **/
  1088. if (!login(&snac, req))
  1089. status = 401;
  1090. else {
  1091. if (cache && history_mtime(&snac, "timeline.html_") > timeline_mtime(&snac)) {
  1092. snac_debug(&snac, 1, xs_fmt("serving cached timeline"));
  1093. *body = history_get(&snac, "timeline.html_");
  1094. *b_size = strlen(*body);
  1095. status = 200;
  1096. }
  1097. else {
  1098. snac_debug(&snac, 1, xs_fmt("building timeline"));
  1099. xs *list = timeline_list(&snac, "private", skip, show);
  1100. xs *next = timeline_list(&snac, "private", skip + show, 1);
  1101. *body = html_timeline(&snac, list, 0, skip, show, xs_list_len(next));
  1102. *b_size = strlen(*body);
  1103. status = 200;
  1104. if (save)
  1105. history_add(&snac, "timeline.html_", *body, *b_size);
  1106. }
  1107. }
  1108. }
  1109. else
  1110. if (strcmp(p_path, "people") == 0) { /** the list of people **/
  1111. if (!login(&snac, req))
  1112. status = 401;
  1113. else {
  1114. *body = html_people(&snac);
  1115. *b_size = strlen(*body);
  1116. status = 200;
  1117. }
  1118. }
  1119. else
  1120. if (strcmp(p_path, "notifications") == 0) { /** the list of notifications **/
  1121. if (!login(&snac, req))
  1122. status = 401;
  1123. else {
  1124. *body = html_notifications(&snac);
  1125. *b_size = strlen(*body);
  1126. status = 200;
  1127. }
  1128. }
  1129. else
  1130. if (xs_startswith(p_path, "p/")) { /** a timeline with just one entry **/
  1131. xs *id = xs_fmt("%s/%s", snac.actor, p_path);
  1132. xs *msg = NULL;
  1133. if (valid_status(object_get(id, &msg))) {
  1134. xs *md5 = xs_md5_hex(id, strlen(id));
  1135. xs *list = xs_list_new();
  1136. list = xs_list_append(list, md5);
  1137. *body = html_timeline(&snac, list, 1, 0, 0, 0);
  1138. *b_size = strlen(*body);
  1139. status = 200;
  1140. }
  1141. }
  1142. else
  1143. if (xs_startswith(p_path, "s/")) { /** a static file **/
  1144. xs *l = xs_split(p_path, "/");
  1145. char *id = xs_list_get(l, 1);
  1146. int sz;
  1147. if (valid_status(static_get(&snac, id, body, &sz))) {
  1148. *b_size = sz;
  1149. *ctype = xs_mime_by_ext(id);
  1150. status = 200;
  1151. }
  1152. }
  1153. else
  1154. if (xs_startswith(p_path, "h/")) { /** an entry from the history **/
  1155. xs *l = xs_split(p_path, "/");
  1156. char *id = xs_list_get(l, 1);
  1157. if ((*body = history_get(&snac, id)) != NULL) {
  1158. *b_size = strlen(*body);
  1159. status = 200;
  1160. }
  1161. }
  1162. else
  1163. if (strcmp(p_path, ".rss") == 0) { /** public timeline in RSS format **/
  1164. d_char *rss;
  1165. xs *elems = timeline_simple_list(&snac, "public", 0, 20);
  1166. xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL);
  1167. char *p, *v;
  1168. /* escape tags */
  1169. bio = xs_replace_i(bio, "<", "&lt;");
  1170. bio = xs_replace_i(bio, ">", "&gt;");
  1171. rss = xs_fmt(
  1172. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1173. "<rss version=\"0.91\">\n"
  1174. "<channel>\n"
  1175. "<title>%s (@%s@%s)</title>\n"
  1176. "<language>en</language>\n"
  1177. "<link>%s.rss</link>\n"
  1178. "<description>%s</description>\n",
  1179. xs_dict_get(snac.config, "name"),
  1180. snac.uid,
  1181. xs_dict_get(srv_config, "host"),
  1182. snac.actor,
  1183. bio
  1184. );
  1185. p = elems;
  1186. while (xs_list_iter(&p, &v)) {
  1187. xs *msg = NULL;
  1188. if (!valid_status(timeline_get_by_md5(&snac, v, &msg)))
  1189. continue;
  1190. char *id = xs_dict_get(msg, "id");
  1191. if (!xs_startswith(id, snac.actor))
  1192. continue;
  1193. xs *content = sanitize(xs_dict_get(msg, "content"));
  1194. xs *title = xs_str_new(NULL);
  1195. int i;
  1196. /* escape tags */
  1197. content = xs_replace_i(content, "<", "&lt;");
  1198. content = xs_replace_i(content, ">", "&gt;");
  1199. for (i = 0; content[i] && content[i] != '<' && content[i] != '&' && i < 40; i++)
  1200. title = xs_append_m(title, &content[i], 1);
  1201. xs *s = xs_fmt(
  1202. "<item>\n"
  1203. "<title>%s...</title>\n"
  1204. "<link>%s</link>\n"
  1205. "<description>%s</description>\n"
  1206. "</item>\n",
  1207. title, id, content
  1208. );
  1209. rss = xs_str_cat(rss, s);
  1210. }
  1211. rss = xs_str_cat(rss, "</channel>\n</rss>\n");
  1212. *body = rss;
  1213. *b_size = strlen(rss);
  1214. *ctype = "application/rss+xml; charset=utf-8";
  1215. status = 200;
  1216. snac_debug(&snac, 1, xs_fmt("serving RSS"));
  1217. }
  1218. else
  1219. status = 404;
  1220. user_free(&snac);
  1221. if (valid_status(status) && *ctype == NULL) {
  1222. *ctype = "text/html; charset=utf-8";
  1223. }
  1224. return status;
  1225. }
  1226. int html_post_handler(const xs_dict *req, const char *q_path,
  1227. char *payload, int p_size,
  1228. char **body, int *b_size, char **ctype)
  1229. {
  1230. (void)p_size;
  1231. (void)ctype;
  1232. int status = 0;
  1233. snac snac;
  1234. char *uid, *p_path;
  1235. xs_dict *p_vars;
  1236. xs *l = xs_split_n(q_path, "/", 2);
  1237. uid = xs_list_get(l, 1);
  1238. if (!uid || !user_open(&snac, uid)) {
  1239. /* invalid user */
  1240. srv_debug(1, xs_fmt("html_post_handler bad user %s", uid));
  1241. return 404;
  1242. }
  1243. p_path = xs_list_get(l, 2);
  1244. /* all posts must be authenticated */
  1245. if (!login(&snac, req)) {
  1246. user_free(&snac);
  1247. return 401;
  1248. }
  1249. p_vars = xs_dict_get(req, "p_vars");
  1250. #if 0
  1251. {
  1252. xs *j1 = xs_json_dumps_pp(p_vars, 4);
  1253. printf("%s\n", j1);
  1254. }
  1255. #endif
  1256. if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/
  1257. /* post note */
  1258. xs_str *content = xs_dict_get(p_vars, "content");
  1259. xs_str *in_reply_to = xs_dict_get(p_vars, "in_reply_to");
  1260. xs_str *attach_url = xs_dict_get(p_vars, "attach_url");
  1261. xs_list *attach_file = xs_dict_get(p_vars, "attach");
  1262. xs_str *to = xs_dict_get(p_vars, "to");
  1263. xs_str *sensitive = xs_dict_get(p_vars, "sensitive");
  1264. xs_str *edit_id = xs_dict_get(p_vars, "edit_id");
  1265. xs_str *alt_text = xs_dict_get(p_vars, "alt_text");
  1266. int priv = !xs_is_null(xs_dict_get(p_vars, "mentioned_only"));
  1267. xs *attach_list = xs_list_new();
  1268. /* default alt text */
  1269. if (xs_is_null(alt_text))
  1270. alt_text = "";
  1271. /* is attach_url set? */
  1272. if (!xs_is_null(attach_url) && *attach_url != '\0') {
  1273. xs *l = xs_list_new();
  1274. l = xs_list_append(l, attach_url);
  1275. l = xs_list_append(l, alt_text);
  1276. attach_list = xs_list_append(attach_list, l);
  1277. }
  1278. /* is attach_file set? */
  1279. if (!xs_is_null(attach_file) && xs_type(attach_file) == XSTYPE_LIST) {
  1280. char *fn = xs_list_get(attach_file, 0);
  1281. if (*fn != '\0') {
  1282. char *ext = strrchr(fn, '.');
  1283. xs *hash = xs_md5_hex(fn, strlen(fn));
  1284. xs *id = xs_fmt("%s%s", hash, ext);
  1285. xs *url = xs_fmt("%s/s/%s", snac.actor, id);
  1286. int fo = xs_number_get(xs_list_get(attach_file, 1));
  1287. int fs = xs_number_get(xs_list_get(attach_file, 2));
  1288. /* store */
  1289. static_put(&snac, id, payload + fo, fs);
  1290. xs *l = xs_list_new();
  1291. l = xs_list_append(l, url);
  1292. l = xs_list_append(l, alt_text);
  1293. attach_list = xs_list_append(attach_list, l);
  1294. }
  1295. }
  1296. if (content != NULL) {
  1297. xs *msg = NULL;
  1298. xs *c_msg = NULL;
  1299. xs *content_2 = xs_replace(content, "\r", "");
  1300. msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv);
  1301. if (sensitive != NULL) {
  1302. xs *t = xs_val_new(XSTYPE_TRUE);
  1303. msg = xs_dict_set(msg, "sensitive", t);
  1304. msg = xs_dict_set(msg, "summary", "...");
  1305. }
  1306. if (xs_is_null(edit_id)) {
  1307. /* new message */
  1308. c_msg = msg_create(&snac, msg);
  1309. timeline_add(&snac, xs_dict_get(msg, "id"), msg);
  1310. }
  1311. else {
  1312. /* an edition of a previous message */
  1313. xs *p_msg = NULL;
  1314. if (valid_status(object_get(edit_id, &p_msg))) {
  1315. /* copy relevant fields from previous version */
  1316. char *fields[] = { "id", "context", "url", "published",
  1317. "to", "inReplyTo", NULL };
  1318. int n;
  1319. for (n = 0; fields[n]; n++) {
  1320. char *v = xs_dict_get(p_msg, fields[n]);
  1321. msg = xs_dict_set(msg, fields[n], v);
  1322. }
  1323. /* set the updated field */
  1324. xs *updated = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ");
  1325. msg = xs_dict_set(msg, "updated", updated);
  1326. /* overwrite object, not updating the indexes */
  1327. object_add_ow(edit_id, msg);
  1328. /* update message */
  1329. c_msg = msg_update(&snac, msg);
  1330. }
  1331. else
  1332. snac_log(&snac, xs_fmt("cannot get object '%s' for editing", edit_id));
  1333. }
  1334. if (c_msg != NULL)
  1335. enqueue_message(&snac, c_msg);
  1336. history_del(&snac, "timeline.html_");
  1337. }
  1338. status = 303;
  1339. }
  1340. else
  1341. if (p_path && strcmp(p_path, "admin/action") == 0) { /** **/
  1342. /* action on an entry */
  1343. char *id = xs_dict_get(p_vars, "id");
  1344. char *actor = xs_dict_get(p_vars, "actor");
  1345. char *action = xs_dict_get(p_vars, "action");
  1346. if (action == NULL)
  1347. return 404;
  1348. snac_debug(&snac, 1, xs_fmt("web action '%s' received", action));
  1349. status = 303;
  1350. if (strcmp(action, L("Like")) == 0) { /** **/
  1351. xs *msg = msg_admiration(&snac, id, "Like");
  1352. if (msg != NULL) {
  1353. enqueue_message(&snac, msg);
  1354. timeline_admire(&snac, xs_dict_get(msg, "object"), snac.actor, 1);
  1355. }
  1356. }
  1357. else
  1358. if (strcmp(action, L("Boost")) == 0) { /** **/
  1359. xs *msg = msg_admiration(&snac, id, "Announce");
  1360. if (msg != NULL) {
  1361. enqueue_message(&snac, msg);
  1362. timeline_admire(&snac, xs_dict_get(msg, "object"), snac.actor, 0);
  1363. }
  1364. }
  1365. else
  1366. if (strcmp(action, L("MUTE")) == 0) { /** **/
  1367. mute(&snac, actor);
  1368. }
  1369. else
  1370. if (strcmp(action, L("Unmute")) == 0) { /** **/
  1371. unmute(&snac, actor);
  1372. }
  1373. else
  1374. if (strcmp(action, L("Hide")) == 0) { /** **/
  1375. hide(&snac, id);
  1376. }
  1377. else
  1378. if (strcmp(action, L("Follow")) == 0) { /** **/
  1379. xs *msg = msg_follow(&snac, actor);
  1380. if (msg != NULL) {
  1381. /* reload the actor from the message, in may be different */
  1382. actor = xs_dict_get(msg, "object");
  1383. following_add(&snac, actor, msg);
  1384. enqueue_output_by_actor(&snac, msg, actor, 0);
  1385. }
  1386. }
  1387. else
  1388. if (strcmp(action, L("Unfollow")) == 0) { /** **/
  1389. /* get the following object */
  1390. xs *object = NULL;
  1391. if (valid_status(following_get(&snac, actor, &object))) {
  1392. xs *msg = msg_undo(&snac, xs_dict_get(object, "object"));
  1393. following_del(&snac, actor);
  1394. enqueue_output_by_actor(&snac, msg, actor, 0);
  1395. snac_log(&snac, xs_fmt("unfollowed actor %s", actor));
  1396. }
  1397. else
  1398. snac_log(&snac, xs_fmt("actor is not being followed %s", actor));
  1399. }
  1400. else
  1401. if (strcmp(action, L("Delete")) == 0) { /** **/
  1402. char *actor_form = xs_dict_get(p_vars, "actor-form");
  1403. if (actor_form != NULL) {
  1404. /* delete follower */
  1405. if (valid_status(follower_del(&snac, actor)))
  1406. snac_log(&snac, xs_fmt("deleted follower %s", actor));
  1407. else
  1408. snac_log(&snac, xs_fmt("error deleting follower %s", actor));
  1409. }
  1410. else {
  1411. /* delete an entry */
  1412. if (xs_startswith(id, snac.actor)) {
  1413. /* it's a post by us: generate a delete */
  1414. xs *msg = msg_delete(&snac, id);
  1415. enqueue_message(&snac, msg);
  1416. snac_log(&snac, xs_fmt("posted tombstone for %s", id));
  1417. }
  1418. timeline_del(&snac, id);
  1419. snac_log(&snac, xs_fmt("deleted entry %s", id));
  1420. }
  1421. }
  1422. else
  1423. status = 404;
  1424. /* delete the cached timeline */
  1425. if (status == 303)
  1426. history_del(&snac, "timeline.html_");
  1427. }
  1428. else
  1429. if (p_path && strcmp(p_path, "admin/user-setup") == 0) { /** **/
  1430. /* change of user data */
  1431. char *v;
  1432. char *p1, *p2;
  1433. xs *byes = xs_val_new(XSTYPE_TRUE);
  1434. xs *bno = xs_val_new(XSTYPE_FALSE);
  1435. if ((v = xs_dict_get(p_vars, "name")) != NULL)
  1436. snac.config = xs_dict_set(snac.config, "name", v);
  1437. if ((v = xs_dict_get(p_vars, "avatar")) != NULL)
  1438. snac.config = xs_dict_set(snac.config, "avatar", v);
  1439. if ((v = xs_dict_get(p_vars, "bio")) != NULL)
  1440. snac.config = xs_dict_set(snac.config, "bio", v);
  1441. if ((v = xs_dict_get(p_vars, "cw")) != NULL &&
  1442. strcmp(v, "on") == 0) {
  1443. snac.config = xs_dict_set(snac.config, "cw", "open");
  1444. } else { /* if the checkbox is not set, the parameter is missing */
  1445. snac.config = xs_dict_set(snac.config, "cw", "");
  1446. }
  1447. if ((v = xs_dict_get(p_vars, "email")) != NULL)
  1448. snac.config = xs_dict_set(snac.config, "email", v);
  1449. if ((v = xs_dict_get(p_vars, "telegram_bot")) != NULL)
  1450. snac.config = xs_dict_set(snac.config, "telegram_bot", v);
  1451. if ((v = xs_dict_get(p_vars, "telegram_chat_id")) != NULL)
  1452. snac.config = xs_dict_set(snac.config, "telegram_chat_id", v);
  1453. if ((v = xs_dict_get(p_vars, "purge_days")) != NULL) {
  1454. xs *days = xs_number_new(atof(v));
  1455. snac.config = xs_dict_set(snac.config, "purge_days", days);
  1456. }
  1457. if ((v = xs_dict_get(p_vars, "drop_dm_from_unknown")) != NULL && strcmp(v, "on") == 0)
  1458. snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", byes);
  1459. else
  1460. snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", bno);
  1461. /* avatar upload */
  1462. xs_list *avatar_file = xs_dict_get(p_vars, "avatar_file");
  1463. if (!xs_is_null(avatar_file) && xs_type(avatar_file) == XSTYPE_LIST) {
  1464. char *fn = xs_list_get(avatar_file, 0);
  1465. if (*fn != '\0') {
  1466. char *ext = strrchr(fn, '.');
  1467. xs *id = xs_fmt("avatar%s", ext);
  1468. xs *url = xs_fmt("%s/s/%s", snac.actor, id);
  1469. int fo = xs_number_get(xs_list_get(avatar_file, 1));
  1470. int fs = xs_number_get(xs_list_get(avatar_file, 2));
  1471. /* store */
  1472. static_put(&snac, id, payload + fo, fs);
  1473. snac.config = xs_dict_set(snac.config, "avatar", url);
  1474. }
  1475. }
  1476. /* password change? */
  1477. if ((p1 = xs_dict_get(p_vars, "passwd1")) != NULL &&
  1478. (p2 = xs_dict_get(p_vars, "passwd2")) != NULL &&
  1479. *p1 && strcmp(p1, p2) == 0) {
  1480. xs *pw = hash_password(snac.uid, p1, NULL);
  1481. snac.config = xs_dict_set(snac.config, "passwd", pw);
  1482. }
  1483. xs *fn = xs_fmt("%s/user.json", snac.basedir);
  1484. xs *bfn = xs_fmt("%s.bak", fn);
  1485. FILE *f;
  1486. rename(fn, bfn);
  1487. if ((f = fopen(fn, "w")) != NULL) {
  1488. xs *j = xs_json_dumps_pp(snac.config, 4);
  1489. fwrite(j, strlen(j), 1, f);
  1490. fclose(f);
  1491. }
  1492. else
  1493. rename(bfn, fn);
  1494. history_del(&snac, "timeline.html_");
  1495. xs *a_msg = msg_actor(&snac);
  1496. xs *u_msg = msg_update(&snac, a_msg);
  1497. enqueue_message(&snac, u_msg);
  1498. status = 303;
  1499. }
  1500. else
  1501. if (p_path && strcmp(p_path, "admin/clear-notifications") == 0) { /** **/
  1502. notify_clear(&snac);
  1503. timeline_touch(&snac);
  1504. status = 303;
  1505. }
  1506. if (status == 303) {
  1507. char *redir = xs_dict_get(p_vars, "redir");
  1508. if (xs_is_null(redir))
  1509. redir = "snac-posts";
  1510. *body = xs_fmt("%s/admin#%s", snac.actor, redir);
  1511. *b_size = strlen(*body);
  1512. }
  1513. user_free(&snac);
  1514. return status;
  1515. }