summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--litterbox.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/litterbox.c b/litterbox.c
index 658822c..2cbd059 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -167,12 +167,13 @@ static void updateJoin(const char *old, const char *new) {
 	dbRun(stmt);
 }
 
-static void clearJoins(const char *channel) {
+static void clearJoins(const char *nick, const char *channel) {
 	static sqlite3_stmt *stmt;
 	const char *sql = SQL(
-		DELETE FROM joins WHERE channel = :channel;
+		DELETE FROM joins WHERE nick = :nick OR channel = :channel;
 	);
 	dbPersist(&stmt, sql);
+	dbBindText(stmt, ":nick", nick);
 	dbBindText(stmt, ":channel", channel);
 	dbRun(stmt);
 }
@@ -337,7 +338,7 @@ static void handlePart(struct Message *msg) {
 		msg->nick, msg->user, msg->host, NULL, msg->params[1]
 	);
 	if (!strcmp(msg->nick, self)) {
-		clearJoins(msg->params[0]);
+		clearJoins(NULL, msg->params[0]);
 	} else {
 		deleteJoin(msg->nick, msg->params[0]);
 	}
@@ -345,6 +346,7 @@ static void handlePart(struct Message *msg) {
 
 static void handleKick(struct Message *msg) {
 	require(msg, 2);
+	// FIXME: Sometimes the server kicks people...
 	insertContext(msg->params[0], false);
 	insertName(msg->nick, msg->user, msg->host);
 	insertEvent(
@@ -353,7 +355,7 @@ static void handleKick(struct Message *msg) {
 		msg->params[1], msg->params[2]
 	);
 	if (!strcmp(msg->params[1], self)) {
-		clearJoins(msg->params[0]);
+		clearJoins(NULL, msg->params[0]);
 	} else {
 		deleteJoin(msg->params[1], msg->params[0]);
 	}
@@ -370,6 +372,15 @@ static void handleNick(struct Message *msg) {
 	updateJoin(msg->nick, msg->params[0]);
 }
 
+static void handleQuit(struct Message *msg) {
+	insertName(msg->nick, msg->user, msg->host);
+	insertEvents(
+		msg->time, Quit,
+		msg->nick, msg->user, msg->host, NULL, msg->params[0]
+	);
+	clearJoins(msg->nick, NULL);
+}
+
 static void handlePing(struct Message *msg) {
 	require(msg, 1);
 	format("PONG :%s\r\n", msg->params[0]);
@@ -390,6 +401,7 @@ static const struct {
 	{ "PART", true, handlePart },
 	{ "PING", false, handlePing },
 	{ "PRIVMSG", true, handlePrivmsg },
+	{ "QUIT", true, handleQuit },
 };
 
 static void handle(struct Message msg) {
ver-highlight'> 2019-07-27Shell script style passJune McEnroe 2019-07-27Add c11.pdfJune McEnroe 2019-07-27Move pdf script to MakefileJune McEnroe 2019-07-27Update macOS neovim to 0.3.8June McEnroe Which somehow still doesn't include my man fix. 2019-07-27Rewrite port makefiles consistentlyJune McEnroe 2019-07-27Rewrite Makefile once more with more organizationJune McEnroe 2019-07-27Reference png.h in bin.7June McEnroe 2019-07-27Revert "Use scheme to style HTMLs"June McEnroe This reverts commit 4b7d5161a30645b0a23691687ef1aafdda62d3bb. I don't know why but I don't like it. 2019-07-27Remove scheme text linkJune McEnroe No standard base64 encoder so no way to maintain it. 2019-07-26Update Dark.terminalJune McEnroe Why are the blobs so much bigger now? 2019-07-26Lighten dark whiteJune McEnroe 2019-07-25Add png.3 man pageJune McEnroe 2019-07-25Use scheme to style HTMLsJune McEnroe 2019-07-25Don't match comments in strings in makeJune McEnroe 2019-07-25Generate index.html with links from bin.7June McEnroe 2019-07-24Warn when date has changedJune McEnroe 2019-07-24Add whenJune McEnroe When? Now. 2019-07-24Remove histedit from bitJune McEnroe