diff options
author | June McEnroe <june@causal.agency> | 2020-07-11 18:07:33 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-11 18:07:33 -0400 |
commit | 5d857422687068526d6477073ef83630ffcf0c1e (patch) | |
tree | 0ccc0a277ca4166bdd0d007bf7bee1f6a4393bab /events.c | |
parent | Handle KCGI_EXIT and call khttp_fcgi_free (diff) | |
download | scooper-5d857422687068526d6477073ef83630ffcf0c1e.tar.gz scooper-5d857422687068526d6477073ef83630ffcf0c1e.zip |
Clean up page handlers
Diffstat (limited to 'events.c')
-rw-r--r-- | events.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/events.c b/events.c index 5e332a3..679a8af 100644 --- a/events.c +++ b/events.c @@ -37,9 +37,9 @@ const char *EventsAfterQuery = SQL( JOIN names USING (name) WHERE contexts.network = :network AND contexts.name = :context - AND coalesce(contexts.query = :query, true) + AND contexts.query <= NOT :public AND events.time >= strftime('%s', :time) - ORDER BY events.time + ORDER BY events.time, events.event LIMIT :limit; ); @@ -59,14 +59,13 @@ const char *EventsBeforeQuery = SQL( JOIN names USING (name) WHERE contexts.network = :network AND contexts.name = :context - AND coalesce(contexts.query = :query, true) + AND contexts.query <= NOT :public AND events.time < strftime('%s', :time) ORDER BY events.time DESC LIMIT :limit ) - SELECT * - FROM before - ORDER BY time; + SELECT * FROM before + ORDER BY time, event; ); enum kcgi_err pageEvents(struct kreq *req) { @@ -111,31 +110,28 @@ enum kcgi_err pageEvents(struct kreq *req) { sqlite3_stmt *events = stmt.eventsAfter; if (req->fieldmap[Before]) events = stmt.eventsBefore; + sqlite3_reset(events); dbBindText(events, ":network", scope.network); dbBindText(events, ":context", scope.context); - if (pagePublic) dbBindInt(events, ":query", false); dbBindText(events, ":time", time); + dbBindInt(events, ":public", pagePublic); dbBindInt(events, ":limit", pageLimit); int result; while (SQLITE_ROW == (result = sqlite3_step(events))) { - struct Event event = { - .event = sqlite3_column_int64(events, 0), - .time = sqlite3_column_int64(events, 1), - .type = sqlite3_column_int(events, 2), - .nick = (const char *)sqlite3_column_text(events, 3), - .user = (const char *)sqlite3_column_text(events, 4), - .host = (const char *)sqlite3_column_text(events, 5), - .target = (const char *)sqlite3_column_text(events, 6), - .message = (const char *)sqlite3_column_text(events, 7), - }; + int i = 0; + struct Event event = {0}; + event.event = sqlite3_column_int64(events, i++); + event.time = sqlite3_column_int64(events, i++); + event.type = sqlite3_column_int(events, i++); + event.nick = sqlite3_column_text(events, i++); + event.user = sqlite3_column_text(events, i++); + event.host = sqlite3_column_text(events, i++); + event.target = sqlite3_column_text(events, i++); + event.message = sqlite3_column_text(events, i++); error = htmlEvent(&html, scope, event); if (error) break; } if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db)); - sqlite3_reset(events); - - return error - || htmlFooter(&html) - || khtml_close(&html); + return error || htmlFooter(&html) || khtml_close(&html); } |