summary refs log tree commit diff
path: root/contexts.c
diff options
context:
space:
mode:
Diffstat (limited to 'contexts.c')
-rw-r--r--contexts.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/contexts.c b/contexts.c
index e17ccfe..e7f44e4 100644
--- a/contexts.c
+++ b/contexts.c
@@ -31,13 +31,13 @@ const char *ContextsQuery = SQL(
 		SELECT name, query
 		FROM contexts
 		JOIN recentEvents USING (context)
-		WHERE network = :network AND coalesce(query = :query, true)
+		WHERE network = :network AND query <= NOT :public
 		GROUP BY context
 		ORDER BY max(time) DESC
 	), allContexts AS (
 		SELECT name, query
 		FROM contexts
-		WHERE network = :network AND coalesce(query = :query, true)
+		WHERE network = :network AND query <= NOT :public
 		ORDER BY query, name
 	)
 	SELECT name, query, 1 FROM activeContexts
@@ -60,9 +60,10 @@ enum kcgi_err pageContexts(struct kreq *req) {
 		|| htmlNav(&html, scope);
 	if (error) return error;
 
-	dbBindInt(stmt.contexts, ":recent", pageRecent);
+	sqlite3_reset(stmt.contexts);
 	dbBindText(stmt.contexts, ":network", scope.network);
-	if (pagePublic) dbBindInt(stmt.contexts, ":query", false);
+	dbBindInt(stmt.contexts, ":recent", pageRecent);
+	dbBindInt(stmt.contexts, ":public", pagePublic);
 
 	enum State {
 		None,
@@ -74,9 +75,10 @@ enum kcgi_err pageContexts(struct kreq *req) {
 
 	int result;
 	while (SQLITE_ROW == (result = sqlite3_step(stmt.contexts))) {
-		const char *context = (const char *)sqlite3_column_text(stmt.contexts, 0);
-		bool query = sqlite3_column_int(stmt.contexts, 1);
-		bool active = sqlite3_column_int(stmt.contexts, 2);
+		int i = 0;
+		const char *context = sqlite3_column_text(stmt.contexts, i++);
+		bool query = sqlite3_column_int(stmt.contexts, i++);
+		bool active = sqlite3_column_int(stmt.contexts, i++);
 
 		enum State prev = state;
 		state = (active ? Active : (query ? Queries : Channels));
@@ -106,9 +108,5 @@ enum kcgi_err pageContexts(struct kreq *req) {
 		if (error) break;
 	}
 	if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db));
-	sqlite3_reset(stmt.contexts);
-
-	return error
-		|| htmlFooter(&html)
-		|| khtml_close(&html);
+	return error || htmlFooter(&html) || khtml_close(&html);
 }