summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-07 23:44:03 -0500
committerJune McEnroe <june@causal.agency>2020-02-07 23:44:03 -0500
commit8b7cc1a0ed95e8a3ff413fa77eb12a3dca7fccb4 (patch)
treee43cd273a49365fefd2d3437da811bca350a56f2
parentUpdate completion on join, part, privmsg (diff)
downloadcatgirl-8b7cc1a0ed95e8a3ff413fa77eb12a3dca7fccb4.tar.gz
catgirl-8b7cc1a0ed95e8a3ff413fa77eb12a3dca7fccb4.zip
Clear completion for ID on self-part
-rw-r--r--chat.h1
-rw-r--r--complete.c12
-rw-r--r--handle.c3
3 files changed, 16 insertions, 0 deletions
diff --git a/chat.h b/chat.h
index aec5a68..6eeed60 100644
--- a/chat.h
+++ b/chat.h
@@ -154,6 +154,7 @@ void completeReject(void);
 void completeAdd(size_t id, const char *str, enum Color color);
 void completeTouch(size_t id, const char *str, enum Color color);
 void completeRemove(size_t id, const char *str);
+void completeClear(size_t id);
 
 FILE *configOpen(const char *path, const char *mode);
 int getopt_config(
diff --git a/complete.c b/complete.c
index 5067512..437bb7d 100644
--- a/complete.c
+++ b/complete.c
@@ -122,3 +122,15 @@ void completeRemove(size_t id, const char *str) {
 		free(node);
 	}
 }
+
+void completeClear(size_t id) {
+	struct Node *next = NULL;
+	for (struct Node *node = head; node; node = next) {
+		next = node->next;
+		if (node->id != id) continue;
+		if (match == node) match = NULL;
+		detach(node);
+		free(node->str);
+		free(node);
+	}
+}
diff --git a/handle.c b/handle.c
index 4faabba..b73d200 100644
--- a/handle.c
+++ b/handle.c
@@ -212,6 +212,9 @@ static void handleJoin(struct Message *msg) {
 static void handlePart(struct Message *msg) {
 	require(msg, true, 1);
 	size_t id = idFor(msg->params[0]);
+	if (self.nick && !strcmp(msg->nick, self.nick)) {
+		completeClear(id);
+	}
 	completeRemove(id, msg->nick);
 	uiFormat(
 		id, Cold, tagTime(msg),