diff options
| -rw-r--r-- | data.c | 60 | ||||
| -rw-r--r-- | snac.h | 3 |
2 files changed, 63 insertions, 0 deletions
| @@ -267,3 +267,63 @@ d_char *follower_list(snac *snac) | |||
| 267 | 267 | ||
| 268 | return list; | 268 | return list; |
| 269 | } | 269 | } |
| 270 | |||
| 271 | |||
| 272 | d_char *_timeline_fn(snac *snac, char *id) | ||
| 273 | /* returns the file name of a timeline entry by its id */ | ||
| 274 | { | ||
| 275 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 276 | xs *spec = xs_fmt("%s/timeline/" "*-%s.json", snac->basedir, md5); | ||
| 277 | glob_t globbuf; | ||
| 278 | d_char *fn = NULL; | ||
| 279 | |||
| 280 | if (glob(spec, 0, NULL, &globbuf) == 0 && globbuf.gl_matchc) { | ||
| 281 | /* get just the first file */ | ||
| 282 | fn = xs_str_new(globbuf.gl_pathv[0]); | ||
| 283 | } | ||
| 284 | |||
| 285 | globfree(&globbuf); | ||
| 286 | |||
| 287 | return fn; | ||
| 288 | } | ||
| 289 | |||
| 290 | |||
| 291 | d_char *timeline_get(snac *snac, char *id) | ||
| 292 | /* gets a message from the timeline */ | ||
| 293 | { | ||
| 294 | xs *fn = _timeline_fn(snac, id); | ||
| 295 | xs *msg = NULL; | ||
| 296 | |||
| 297 | if (fn != NULL) { | ||
| 298 | FILE *f; | ||
| 299 | |||
| 300 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 301 | xs *j = xs_readall(f); | ||
| 302 | |||
| 303 | msg = xs_json_loads(j); | ||
| 304 | fclose(f); | ||
| 305 | } | ||
| 306 | } | ||
| 307 | |||
| 308 | return msg; | ||
| 309 | } | ||
| 310 | |||
| 311 | |||
| 312 | void timeline_del(snac *snac, char *id) | ||
| 313 | /* deletes a message from the timeline */ | ||
| 314 | { | ||
| 315 | xs *fn = _timeline_fn(snac, id); | ||
| 316 | |||
| 317 | if (fn != NULL) { | ||
| 318 | xs *lfn = NULL; | ||
| 319 | |||
| 320 | unlink(fn); | ||
| 321 | snac_debug(snac, 1, xs_fmt("timeline_del %s", id)); | ||
| 322 | |||
| 323 | /* try to delete also from the local timeline */ | ||
| 324 | lfn = xs_replace(fn, "/timeline/", "/local/"); | ||
| 325 | |||
| 326 | if (unlink(lfn) != -1) | ||
| 327 | snac_debug(snac, 1, xs_fmt("timeline_del (local) %s", id)); | ||
| 328 | } | ||
| 329 | } | ||
| @@ -44,3 +44,6 @@ int follower_add(snac *snac, char *actor, char *msg); | |||
| 44 | int follower_del(snac *snac, char *actor); | 44 | int follower_del(snac *snac, char *actor); |
| 45 | int follower_check(snac *snac, char *actor); | 45 | int follower_check(snac *snac, char *actor); |
| 46 | d_char *follower_list(snac *snac); | 46 | d_char *follower_list(snac *snac); |
| 47 | |||
| 48 | d_char *timeline_get(snac *snac, char *id); | ||
| 49 | void timeline_del(snac *snac, char *id); | ||