diff options
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 160 |
1 files changed, 156 insertions, 4 deletions
| @@ -1158,6 +1158,97 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 1158 | st = xs_dict_append(st, "tags", htl); | 1158 | st = xs_dict_append(st, "tags", htl); |
| 1159 | st = xs_dict_append(st, "emojis", eml); | 1159 | st = xs_dict_append(st, "emojis", eml); |
| 1160 | } | 1160 | } |
| 1161 | { | ||
| 1162 | xs *rl = object_get_emoji_reacts(id); | ||
| 1163 | xs *frl = xs_list_new(); /* final */ | ||
| 1164 | xs *sfrl = xs_dict_new(); /* seen */ | ||
| 1165 | int c = 0; | ||
| 1166 | const char *v; | ||
| 1167 | |||
| 1168 | xs_dict *msg = NULL; | ||
| 1169 | while (xs_list_next(rl, &v, &c)) { | ||
| 1170 | if (valid_status(object_get_by_md5(v, &msg))) { | ||
| 1171 | const char *content = xs_dict_get(msg, "content"); | ||
| 1172 | const char *actor = xs_dict_get(msg, "actor"); | ||
| 1173 | const xs_list *contentl = xs_dict_get(sfrl, content); | ||
| 1174 | /* NOTE: idk when there are no actor, but i encountered that bug. | ||
| 1175 | * Probably because of one of my previous attempts. | ||
| 1176 | * Keeping this just in case, can remove later */ | ||
| 1177 | const char *me = actor && strcmp(actor, snac->actor) == 0 ? | ||
| 1178 | xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE); | ||
| 1179 | int count = 1; | ||
| 1180 | |||
| 1181 | if (contentl) { | ||
| 1182 | count = atoi(xs_list_get(contentl, 0)) + 1; | ||
| 1183 | if (strncmp(xs_list_get(contentl, 1), xs_stock(XSTYPE_TRUE), 1) == 0) | ||
| 1184 | me = xs_stock(XSTYPE_TRUE); | ||
| 1185 | } | ||
| 1186 | |||
| 1187 | xs *fl = xs_list_new(); | ||
| 1188 | fl = xs_list_append(fl, xs_fmt("%d", count), me); | ||
| 1189 | sfrl = xs_dict_append(sfrl, content, fl); | ||
| 1190 | } | ||
| 1191 | } | ||
| 1192 | |||
| 1193 | c = 0; | ||
| 1194 | |||
| 1195 | while (xs_list_next(rl, &v, &c)) { | ||
| 1196 | if (valid_status(object_get_by_md5(v, &msg))) { | ||
| 1197 | xs *d1 = xs_dict_new(); | ||
| 1198 | |||
| 1199 | const xs_dict *icon = xs_dict_get(xs_list_get(xs_dict_get(msg, "tag"), 0), "icon"); | ||
| 1200 | const char *o_url = xs_dict_get(icon, "url"); | ||
| 1201 | const char *name = xs_dict_get(msg, "content"); | ||
| 1202 | const char *actor = xs_dict_get(msg, "actor"); | ||
| 1203 | |||
| 1204 | xs *nm = xs_dup(name); | ||
| 1205 | xs *url = NULL; | ||
| 1206 | |||
| 1207 | if (!xs_is_null(o_url)) { | ||
| 1208 | if (actor && snac && !strcmp(actor, snac->actor)) | ||
| 1209 | url = make_url(o_url, NULL, 1); | ||
| 1210 | else | ||
| 1211 | url = xs_dup(o_url); | ||
| 1212 | } | ||
| 1213 | |||
| 1214 | xs *accounts = xs_list_new(); | ||
| 1215 | if (actor) { | ||
| 1216 | xs *d2 = xs_dict_new(); | ||
| 1217 | object_get(actor, &d2); | ||
| 1218 | xs *e_acct = mastoapi_account(snac, d2); | ||
| 1219 | accounts = xs_list_append(accounts, e_acct); | ||
| 1220 | } | ||
| 1221 | |||
| 1222 | const xs_list *item = xs_dict_get(sfrl, nm); | ||
| 1223 | const xs_str *nb = xs_list_get(item, 0); | ||
| 1224 | const xs_val *me = xs_list_get(item, 1); | ||
| 1225 | if (item == NULL) | ||
| 1226 | continue; | ||
| 1227 | |||
| 1228 | if (nm && strcmp(nm, "")) { | ||
| 1229 | if (url && strcmp(url, "")) { | ||
| 1230 | d1 = xs_dict_append(d1, "name", nm); | ||
| 1231 | d1 = xs_dict_append(d1, "shortcode", nm); | ||
| 1232 | d1 = xs_dict_append(d1, "accounts", accounts); | ||
| 1233 | d1 = xs_dict_append(d1, "me", me); | ||
| 1234 | d1 = xs_dict_append(d1, "url", url); | ||
| 1235 | d1 = xs_dict_append(d1, "static_url", url); | ||
| 1236 | d1 = xs_dict_append(d1, "visible_in_picker", xs_stock(XSTYPE_TRUE)); | ||
| 1237 | d1 = xs_dict_append(d1, "count", nb); | ||
| 1238 | } else { | ||
| 1239 | d1 = xs_dict_append(d1, "name", nm); | ||
| 1240 | d1 = xs_dict_append(d1, "count", nb); | ||
| 1241 | d1 = xs_dict_append(d1, "me", me); | ||
| 1242 | d1 = xs_dict_append(d1, "visible_in_picker", xs_stock(XSTYPE_TRUE)); | ||
| 1243 | } | ||
| 1244 | sfrl = xs_dict_del(sfrl, nm); | ||
| 1245 | frl = xs_list_append(frl, d1); | ||
| 1246 | } | ||
| 1247 | } | ||
| 1248 | } | ||
| 1249 | |||
| 1250 | st = xs_dict_append(st, "reactions", frl); | ||
| 1251 | } | ||
| 1161 | 1252 | ||
| 1162 | xs_free(idx); | 1253 | xs_free(idx); |
| 1163 | xs_free(ixc); | 1254 | xs_free(ixc); |
| @@ -2202,15 +2293,24 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 2202 | if (noti == NULL) | 2293 | if (noti == NULL) |
| 2203 | continue; | 2294 | continue; |
| 2204 | 2295 | ||
| 2296 | const xs_dict *tag = xs_list_get(xs_dict_get_path(noti, "msg.tag"), 0); | ||
| 2297 | |||
| 2205 | const char *type = xs_dict_get(noti, "type"); | 2298 | const char *type = xs_dict_get(noti, "type"); |
| 2206 | const char *utype = xs_dict_get(noti, "utype"); | 2299 | const char *utype = xs_dict_get(noti, "utype"); |
| 2207 | const char *objid = xs_dict_get(noti, "objid"); | 2300 | const char *objid = xs_dict_get(noti, "objid"); |
| 2208 | const char *id = xs_dict_get(noti, "id"); | 2301 | const char *id = xs_dict_get(noti, "id"); |
| 2209 | const char *actid = xs_dict_get(noti, "actor"); | 2302 | const char *actid = xs_dict_get(noti, "actor"); |
| 2303 | |||
| 2304 | int isEmoji = 0; | ||
| 2305 | |||
| 2210 | xs *fid = xs_replace(id, ".", ""); | 2306 | xs *fid = xs_replace(id, ".", ""); |
| 2211 | xs *actor = NULL; | 2307 | xs *actor = NULL; |
| 2212 | xs *entry = NULL; | 2308 | xs *entry = NULL; |
| 2213 | 2309 | ||
| 2310 | if (tag) { | ||
| 2311 | isEmoji = strcmp(xs_dict_get(tag, "type"), "Emoji") ? 0 : 1; | ||
| 2312 | } | ||
| 2313 | |||
| 2214 | if (!valid_status(actor_get(actid, &actor))) | 2314 | if (!valid_status(actor_get(actid, &actor))) |
| 2215 | continue; | 2315 | continue; |
| 2216 | 2316 | ||
| @@ -2234,9 +2334,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 2234 | } | 2334 | } |
| 2235 | 2335 | ||
| 2236 | /* convert the type */ | 2336 | /* convert the type */ |
| 2237 | if (strcmp(type, "Like") == 0 || strcmp(type, "EmojiReact") == 0) | 2337 | if (strcmp(type, "Like") == 0 && !isEmoji) |
| 2238 | type = "favourite"; | 2338 | type = "favourite"; |
| 2239 | else | 2339 | else |
| 2340 | if (isEmoji || strcmp(type, "EmojiReact") == 0) | ||
| 2341 | type = "reaction"; | ||
| 2342 | else | ||
| 2240 | if (strcmp(type, "Announce") == 0) | 2343 | if (strcmp(type, "Announce") == 0) |
| 2241 | type = "reblog"; | 2344 | type = "reblog"; |
| 2242 | else | 2345 | else |
| @@ -2277,8 +2380,29 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 2277 | if (strcmp(type, "follow") != 0 && !xs_is_null(objid)) { | 2380 | if (strcmp(type, "follow") != 0 && !xs_is_null(objid)) { |
| 2278 | xs *st = mastoapi_status(&snac1, entry); | 2381 | xs *st = mastoapi_status(&snac1, entry); |
| 2279 | 2382 | ||
| 2280 | if (st) | 2383 | if (st) { |
| 2281 | mn = xs_dict_append(mn, "status", st); | 2384 | mn = xs_dict_append(mn, "status", st); |
| 2385 | |||
| 2386 | if (strcmp(type, "reaction") == 0 && !xs_is_null(objid)) { | ||
| 2387 | const char *eid = NULL; | ||
| 2388 | const char *url = NULL; | ||
| 2389 | int utf = 0; | ||
| 2390 | |||
| 2391 | const xs_dict *tag = xs_list_get(xs_dict_get_path(noti, "msg.tag"), 0); | ||
| 2392 | const char *content = xs_dict_get_path(noti, "msg.content"); | ||
| 2393 | |||
| 2394 | url = xs_dict_get(xs_dict_get(tag, "icon"), "url"); | ||
| 2395 | eid = xs_dict_get(tag, "name"); | ||
| 2396 | |||
| 2397 | if (eid && url) { | ||
| 2398 | mn = xs_dict_append(mn, "emoji", eid); | ||
| 2399 | mn = xs_dict_append(mn, "emoji_url", url); | ||
| 2400 | } | ||
| 2401 | |||
| 2402 | if (xs_is_emoji((utf = xs_utf8_dec(&content)))) | ||
| 2403 | mn = xs_dict_append(mn, "name", xs_fmt("&#%d;", utf)); | ||
| 2404 | } | ||
| 2405 | } | ||
| 2282 | } | 2406 | } |
| 2283 | 2407 | ||
| 2284 | out = xs_list_append(out, mn); | 2408 | out = xs_list_append(out, mn); |
| @@ -2594,6 +2718,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 2594 | "\"max_expiration\":2629746," | 2718 | "\"max_expiration\":2629746," |
| 2595 | "\"max_options\":8,\"min_expiration\":300}"); | 2719 | "\"max_options\":8,\"min_expiration\":300}"); |
| 2596 | cfg = xs_dict_append(cfg, "polls", d14); | 2720 | cfg = xs_dict_append(cfg, "polls", d14); |
| 2721 | |||
| 2722 | |||
| 2723 | xs *d15 = xs_json_loads("{\"max_reactions\":50}"); | ||
| 2724 | cfg = xs_dict_append(cfg, "reactions", d15); | ||
| 2725 | |||
| 2597 | } | 2726 | } |
| 2598 | 2727 | ||
| 2599 | ins = xs_dict_append(ins, "configuration", cfg); | 2728 | ins = xs_dict_append(ins, "configuration", cfg); |
| @@ -3219,7 +3348,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 3219 | 3348 | ||
| 3220 | if (n_msg != NULL) { | 3349 | if (n_msg != NULL) { |
| 3221 | enqueue_message(&snac, n_msg); | 3350 | enqueue_message(&snac, n_msg); |
| 3222 | timeline_admire(&snac, xs_dict_get(n_msg, "object"), snac.actor, 1); | 3351 | timeline_admire(&snac, xs_dict_get(n_msg, "object"), snac.actor, 1, msg); |
| 3223 | 3352 | ||
| 3224 | out = mastoapi_status(&snac, msg); | 3353 | out = mastoapi_status(&snac, msg); |
| 3225 | } | 3354 | } |
| @@ -3235,12 +3364,35 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 3235 | } | 3364 | } |
| 3236 | } | 3365 | } |
| 3237 | else | 3366 | else |
| 3367 | if (strcmp(op, "react") == 0) { /** **/ | ||
| 3368 | const char *eid = xs_list_get(l, 5); | ||
| 3369 | xs *n_msg = msg_emoji_init(&snac, id, eid); | ||
| 3370 | if (n_msg) | ||
| 3371 | out = mastoapi_status(&snac, n_msg); | ||
| 3372 | } | ||
| 3373 | else | ||
| 3374 | if (strcmp(op, "unreact") == 0) { /** **/ | ||
| 3375 | const char *eid = xs_list_get(l, 5); | ||
| 3376 | xs *content = xs_fmt("%s", eid); | ||
| 3377 | |||
| 3378 | if (eid) { | ||
| 3379 | xs *n_msg = msg_emoji_unreact(&snac, id, content); | ||
| 3380 | |||
| 3381 | if (n_msg != NULL) { | ||
| 3382 | enqueue_message(&snac, n_msg); | ||
| 3383 | |||
| 3384 | out = mastoapi_status(&snac, msg); | ||
| 3385 | } | ||
| 3386 | } | ||
| 3387 | } | ||
| 3388 | |||
| 3389 | else | ||
| 3238 | if (strcmp(op, "reblog") == 0) { /** **/ | 3390 | if (strcmp(op, "reblog") == 0) { /** **/ |
| 3239 | xs *n_msg = msg_admiration(&snac, id, "Announce"); | 3391 | xs *n_msg = msg_admiration(&snac, id, "Announce"); |
| 3240 | 3392 | ||
| 3241 | if (n_msg != NULL) { | 3393 | if (n_msg != NULL) { |
| 3242 | enqueue_message(&snac, n_msg); | 3394 | enqueue_message(&snac, n_msg); |
| 3243 | timeline_admire(&snac, xs_dict_get(n_msg, "object"), snac.actor, 0); | 3395 | timeline_admire(&snac, xs_dict_get(n_msg, "object"), snac.actor, 0, msg); |
| 3244 | 3396 | ||
| 3245 | out = mastoapi_status(&snac, msg); | 3397 | out = mastoapi_status(&snac, msg); |
| 3246 | } | 3398 | } |