about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-24 18:11:28 -0500
committerJune McEnroe <june@causal.agency>2019-12-24 18:11:28 -0500
commite4fac25c6f5eb761d462fd40a189325f701e6a44 (patch)
tree2d4fc95bf0b08771fe7ed2472089c9c5848af488
parentIt's The Big Refactor (diff)
downloadlitterbox-e4fac25c6f5eb761d462fd40a189325f701e6a44.tar.gz
litterbox-e4fac25c6f5eb761d462fd40a189325f701e6a44.zip
Handle quit
-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) {