diff options
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 50 |
1 files changed, 50 insertions, 0 deletions
| @@ -1347,6 +1347,56 @@ int is_muted(snac *snac, const char *actor) | |||
| 1347 | } | 1347 | } |
| 1348 | 1348 | ||
| 1349 | 1349 | ||
| 1350 | /** pinning **/ | ||
| 1351 | |||
| 1352 | xs_str *_pinned_fn(snac *user, const char *id) | ||
| 1353 | { | ||
| 1354 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 1355 | return xs_fmt("%s/pinned/%s", user->basedir, md5); | ||
| 1356 | } | ||
| 1357 | |||
| 1358 | |||
| 1359 | int is_pinned(snac *user, const char *id) | ||
| 1360 | /* returns true if this note is pinned */ | ||
| 1361 | { | ||
| 1362 | xs *fn = _pinned_fn(user, id); | ||
| 1363 | return !!(mtime(fn) != 0.0); | ||
| 1364 | } | ||
| 1365 | |||
| 1366 | |||
| 1367 | int pin(snac *user, const char *id) | ||
| 1368 | /* pins a message */ | ||
| 1369 | { | ||
| 1370 | int ret = 0; | ||
| 1371 | |||
| 1372 | if (xs_startswith(id, user->actor)) { | ||
| 1373 | /* create the subfolder, if it does not exist */ | ||
| 1374 | xs *fn = xs_fmt("%s/pinned/", user->basedir); | ||
| 1375 | mkdirx(fn); | ||
| 1376 | |||
| 1377 | object_user_cache_add(user, id, "pinned"); | ||
| 1378 | |||
| 1379 | ret = 1; | ||
| 1380 | } | ||
| 1381 | |||
| 1382 | return ret; | ||
| 1383 | } | ||
| 1384 | |||
| 1385 | |||
| 1386 | void unpin(snac *user, const char *id) | ||
| 1387 | /* unpin a message */ | ||
| 1388 | { | ||
| 1389 | object_user_cache_del(user, id, "pinned"); | ||
| 1390 | } | ||
| 1391 | |||
| 1392 | |||
| 1393 | xs_list *pinned_list(snac *user) | ||
| 1394 | /* return the lists of pinned posts */ | ||
| 1395 | { | ||
| 1396 | return object_user_cache_list(user, "pinned", XS_ALL); | ||
| 1397 | } | ||
| 1398 | |||
| 1399 | |||
| 1350 | xs_str *_hidden_fn(snac *snac, const char *id) | 1400 | xs_str *_hidden_fn(snac *snac, const char *id) |
| 1351 | { | 1401 | { |
| 1352 | xs *md5 = xs_md5_hex(id, strlen(id)); | 1402 | xs *md5 = xs_md5_hex(id, strlen(id)); |