Commit 7b78ced4 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(saved_by_recipient): Code cleanup.

(find_comment_limit_and_age): New static function.
(saved_by_keep_commented): New static function.
(saved): Call saved_by_keep_commented.
parent 98c6f726
/*
* $Id: text-garb.c,v 0.50 2003/08/11 09:38:52 ceder Exp $
* $Id: text-garb.c,v 0.51 2003/08/11 10:55:28 ceder Exp $
* Copyright (C) 1991-1995, 1997-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -128,7 +128,7 @@ saved_by_recipient(Text_stat *text_s,
{
unsigned short nmisc;
Misc_info *misc;
double limit;
double limit = 0;
Bool in_rec_group = FALSE;
for (nmisc = text_s->no_of_misc, misc = text_s->misc_items;
......@@ -140,15 +140,16 @@ saved_by_recipient(Text_stat *text_s,
case recpt:
case cc_recpt:
case bcc_recpt:
in_rec_group = TRUE;
if (cached_conf_exists(misc->datum.recipient))
{
limit = (day_to_sec
* cached_get_garb_nice(misc->datum.recipient));
if (age < limit)
return TRUE;
in_rec_group = TRUE;
}
else
in_rec_group = FALSE;
break;
case comm_to:
......@@ -232,6 +233,137 @@ saved_by_comment(Text_stat *text_s)
return FALSE;
}
static Bool
find_comment_limit_and_age(Text_no text_no,
Text_stat *text_s,
Text_no parent,
double *comment_age,
double *limit)
{
unsigned short nmisc;
Misc_info *misc;
Bool in_comm_group = FALSE;
Bool has_comments = FALSE;
double tmp;
if (text_s == NULL)
text_s = cached_get_text_stat(text_no);
if (text_s == NULL)
{
*comment_age = 0;
*limit = 0;
return FALSE;
}
*comment_age = ldifftime(current_time.tv_sec, text_s->creation_time);
*limit = default_save;
for (nmisc = text_s->no_of_misc, misc = text_s->misc_items;
nmisc > 0;
--nmisc, ++misc)
{
switch (misc->type)
{
case recpt:
case cc_recpt:
case bcc_recpt:
in_comm_group = FALSE;
if (cached_conf_exists(misc->datum.recipient))
{
tmp = day_to_sec * cached_get_keep_commented(
misc->datum.recipient);
if (tmp > *limit)
*limit = tmp;
}
break;
case comm_to:
case footn_to:
in_comm_group = (misc->datum.text_link == parent);
break;
case comm_in:
case footn_in:
in_comm_group = FALSE;
has_comments = TRUE;
break;
case loc_no:
case rec_time:
case sent_by:
break;
case sent_at:
if (in_comm_group)
*comment_age = ldifftime(current_time.tv_sec,
misc->datum.sent_at);
break;
#ifndef COMPILE_CHECKS
default:
#endif
case unknown_info:
restart_kom("find_comment_limit_and_age(): Illegal misc-item.\n");
}
}
return has_comments;
}
static Bool
saved_by_keep_commented(Text_no text_no,
Text_stat *text_s)
{
unsigned short nmisc;
Misc_info *misc;
double comment_age;
double parent_limit;
double limit;
if (!find_comment_limit_and_age(text_no, text_s, 0,
&comment_age, &parent_limit))
return FALSE;
for (nmisc = text_s->no_of_misc, misc = text_s->misc_items;
nmisc > 0;
--nmisc, ++misc)
{
switch (misc->type)
{
case comm_in:
case footn_in:
find_comment_limit_and_age(misc->datum.text_link, NULL, text_no,
&comment_age, &limit);
if (limit < parent_limit)
limit = parent_limit;
if (comment_age < limit)
return TRUE;
break;
case recpt:
case cc_recpt:
case bcc_recpt:
case comm_to:
case footn_to:
case loc_no:
case rec_time:
case sent_by:
case sent_at:
break;
#ifndef COMPILE_CHECKS
default:
#endif
case unknown_info:
restart_kom("saved_by_recipient(): Illegal misc-item.\n");
}
}
return FALSE;
}
static Bool
saved(Text_no text_no,
Text_stat *text_s)
......@@ -254,6 +386,9 @@ saved(Text_no text_no,
if (saved_by_comment(text_s))
return TRUE;
if (saved_by_keep_commented(text_no, text_s))
return TRUE;
return FALSE;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment