More old code cleaning.

This commit is contained in:
default 2022-12-02 20:56:51 +01:00
parent 3e2891b100
commit a133427e8d
3 changed files with 4 additions and 61 deletions

View file

@ -399,7 +399,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type)
/* call the object */ /* call the object */
timeline_request(snac, object, snac->actor); timeline_request(snac, object, snac->actor);
if ((a_msg = timeline_find(snac, object)) != NULL) { if (valid_status(object_get(object, &a_msg, NULL))) {
xs *rcpts = xs_list_new(); xs *rcpts = xs_list_new();
msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object); msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object);
@ -592,7 +592,7 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char
/* demand this thing */ /* demand this thing */
timeline_request(snac, in_reply_to, NULL); timeline_request(snac, in_reply_to, NULL);
if ((p_msg = timeline_find(snac, in_reply_to)) != NULL) { if (valid_status(object_get(in_reply_to, &p_msg, NULL))) {
/* add this author as recipient */ /* add this author as recipient */
char *a, *v; char *a, *v;
@ -892,7 +892,7 @@ int process_message(snac *snac, char *msg, char *req)
timeline_request(snac, object, actor); timeline_request(snac, object, actor);
if ((a_msg = timeline_find(snac, object)) != NULL) { if (valid_status(object_get(object, &a_msg, NULL))) {
char *who = xs_dict_get(a_msg, "attributedTo"); char *who = xs_dict_get(a_msg, "attributedTo");
if (who && !is_muted(snac, who)) { if (who && !is_muted(snac, who)) {

57
data.c
View file

@ -738,56 +738,11 @@ d_char *follower_list(snac *snac)
double timeline_mtime(snac *snac) double timeline_mtime(snac *snac)
{ {
xs *fn = xs_fmt("%s/timeline", snac->basedir); xs *fn = xs_fmt("%s/private.idx", snac->basedir);
return mtime(fn); return mtime(fn);
} }
d_char *_timeline_find_fn(snac *snac, char *id)
/* returns the file name of a timeline entry by its id */
{
xs *md5 = xs_md5_hex(id, strlen(id));
xs *spec = xs_fmt("%s/timeline/" "*-%s.json", snac->basedir, md5);
xs *list = NULL;
d_char *fn = NULL;
int l;
list = xs_glob(spec, 0, 0);
l = xs_list_len(list);
/* if there is something, get the first one */
if (l > 0) {
fn = xs_str_new(xs_list_get(list, 0));
if (l > 1)
snac_log(snac, xs_fmt("**ALERT** _timeline_find_fn %d > 1", l));
}
return fn;
}
d_char *timeline_find(snac *snac, char *id)
/* gets a message from the timeline by id */
{
xs *fn = _timeline_find_fn(snac, id);
d_char *msg = NULL;
if (fn != NULL) {
FILE *f;
if ((f = fopen(fn, "r")) != NULL) {
xs *j = xs_readall(f);
msg = xs_json_loads(j);
fclose(f);
}
}
return msg;
}
int timeline_del(snac *snac, char *id) int timeline_del(snac *snac, char *id)
/* deletes a message from the timeline */ /* deletes a message from the timeline */
{ {
@ -800,16 +755,6 @@ int timeline_del(snac *snac, char *id)
} }
d_char *_timeline_new_fn(snac *snac, char *id)
/* creates a new filename */
{
xs *ntid = tid(0);
xs *md5 = xs_md5_hex(id, strlen(id));
return xs_fmt("%s/timeline/%s-%s.json", snac->basedir, ntid, md5);
}
void timeline_update_indexes(snac *snac, const char *id) void timeline_update_indexes(snac *snac, const char *id)
/* updates the indexes */ /* updates the indexes */
{ {

2
snac.h
View file

@ -76,8 +76,6 @@ int follower_check(snac *snac, const char *actor);
d_char *follower_list(snac *snac); d_char *follower_list(snac *snac);
double timeline_mtime(snac *snac); double timeline_mtime(snac *snac);
d_char *_timeline_find_fn(snac *snac, char *id);
d_char *timeline_find(snac *snac, char *id);
int timeline_del(snac *snac, char *id); int timeline_del(snac *snac, char *id);
d_char *timeline_list(snac *snac, const char *idx_name, int max); d_char *timeline_list(snac *snac, const char *idx_name, int max);
int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer);