Fix next recurring appointment

Recurring appointments do not show up in the notification bar as next
appointment. This was partly corrected by 2084f35 (Fix notification of
recurrent appointments, 2017-02-09) and 5aa7a09 (Fix another error in
the notification code, 2017-02-11).

The search function recur_apoint_starts_before() had a wrong second
argument, but is really of no use: the start time of a recurring
appointment is the start time of the very first occurrence (in the
past). A comparison against the item in the notify_app structure tells
nothing of the start time of the current day; at most it eliminates some
future recurring appointments. The function can be dropped, and the
entire recurring appointment list looked through.

The proper start time is found in the main search loop (and called
real_recur_start_time) and must be compared against the item in the
notify_app structure.

But because recur_apoint_find_occurrence() is limited to a particular
day (second argument), two searches are necessary to cover 24 hours.

Unrelated cleanups: removed function return value; changed long to
time_t.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2018-07-15 10:30:41 +02:00 committed by Lukas Fleischer
parent f2ca5980e9
commit 8cbd456640
3 changed files with 18 additions and 27 deletions

View File

@ -231,8 +231,7 @@ static void next_arg(void)
next_app.got_app = 0; next_app.got_app = 0;
next_app.txt = NULL; next_app.txt = NULL;
next_app = *recur_apoint_check_next(&next_app, current_time, recur_apoint_check_next(&next_app, current_time, get_today());
get_today());
next_app = *apoint_check_next(&next_app, current_time); next_app = *apoint_check_next(&next_app, current_time);
if (next_app.got_app) { if (next_app.got_app) {

View File

@ -1049,8 +1049,7 @@ void recur_apoint_add_exc(struct recur_apoint *, long);
void recur_event_erase(struct recur_event *); void recur_event_erase(struct recur_event *);
void recur_apoint_erase(struct recur_apoint *); void recur_apoint_erase(struct recur_apoint *);
void recur_exc_scan(llist_t *, FILE *); void recur_exc_scan(llist_t *, FILE *);
struct notify_app *recur_apoint_check_next(struct notify_app *, long, void recur_apoint_check_next(struct notify_app *, time_t, time_t);
long);
void recur_apoint_switch_notify(struct recur_apoint *); void recur_apoint_switch_notify(struct recur_apoint *);
void recur_event_paste_item(struct recur_event *, long); void recur_event_paste_item(struct recur_event *, long);
void recur_apoint_paste_item(struct recur_apoint *, long); void recur_apoint_paste_item(struct recur_apoint *, long);

View File

@ -922,36 +922,31 @@ void recur_exc_scan(llist_t * lexc, FILE * data_file)
} }
} }
static int recur_apoint_starts_before(struct recur_apoint *rapt, long *time)
{
return rapt->start < *time;
}
/* /*
* Look in the appointment list if we have an item which starts before the item * Look in the appointment list if we have an item which starts after start and
* stored in the notify_app structure (which is the next item to be notified). * before the item stored in the notify_app structure (which is the next item
* to be notified). Note, the search may change the notify_app structure.
*/ */
struct notify_app *recur_apoint_check_next(struct notify_app *app, void recur_apoint_check_next(struct notify_app *app, time_t start, time_t day)
long start, long day)
{ {
llist_item_t *i; llist_item_t *i;
time_t real_recur_start_time; time_t real_recur_start_time;
LLIST_TS_LOCK(&recur_alist_p); LLIST_TS_LOCK(&recur_alist_p);
/* LLIST_TS_FOREACH(&recur_alist_p, i) {
* Iterate over all recurrent items starting before the current "next"
* appointment. We cannot filter by start time because a recurrent item
* can actually start (several days) before the current "next" item and
* still have an occurrence which is the next item to be notified.
*/
LLIST_TS_FIND_FOREACH(&recur_alist_p, &app->time,
recur_apoint_starts_before, i) {
struct recur_apoint *rapt = LLIST_TS_GET_DATA(i); struct recur_apoint *rapt = LLIST_TS_GET_DATA(i);
/* /* Tomorrow? */
* Check whether the recurrent appointment contains an if (recur_apoint_find_occurrence
* occurrence which is the next item to be notified. (rapt, day + DAYINSEC, &real_recur_start_time)
*/ && real_recur_start_time > start
&& real_recur_start_time < app->time) {
app->time = real_recur_start_time;
app->txt = mem_strdup(rapt->mesg);
app->state = rapt->state;
app->got_app = 1;
}
/* Today? */
if (recur_apoint_find_occurrence if (recur_apoint_find_occurrence
(rapt, day, &real_recur_start_time) (rapt, day, &real_recur_start_time)
&& real_recur_start_time > start && real_recur_start_time > start
@ -963,8 +958,6 @@ struct notify_app *recur_apoint_check_next(struct notify_app *app,
} }
} }
LLIST_TS_UNLOCK(&recur_alist_p); LLIST_TS_UNLOCK(&recur_alist_p);
return app;
} }
/* Switch recurrent item notification state. */ /* Switch recurrent item notification state. */