about summary refs log tree commit diff
path: root/client.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2023-07-17 11:24:51 -0400
committerJune McEnroe <june@causal.agency>2023-07-17 11:24:51 -0400
commit87dffbd7c41e119589113f68601a93f4592b4255 (patch)
tree52cb25f8748f2c653476f184a6771c3e8f05a25f /client.c
parentImplement draft/read-marker (diff)
downloadpounce-87dffbd7c41e119589113f68601a93f4592b4255.tar.gz
pounce-87dffbd7c41e119589113f68601a93f4592b4255.zip
Notify other clients of MARKREAD
Diffstat (limited to '')
-rw-r--r--client.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/client.c b/client.c
index 2227a4c..6bc53f4 100644
--- a/client.c
+++ b/client.c
@@ -416,10 +416,15 @@ static void clientSetMarker(
 	for (size_t i = 0; i < markers.len; ++i) {
 		marker = &markers.ptr[i];
 		if (strcasecmp(marker->target, target)) continue;
-		if (strcmp(timestamp, marker->timestamp) > 0) {
-			set(&marker->timestamp, timestamp);
+		if (strcmp(timestamp, marker->timestamp) < 0) {
+			clientFormat(
+				client, ":%s MARKREAD %s timestamp=%s\r\n",
+				clientOrigin, target, marker->timestamp
+			);
+			return;
 		}
-		goto reply;
+		set(&marker->timestamp, timestamp);
+		goto notify;
 	}
 	if (markers.len == markers.cap) {
 		markers.cap = (markers.cap ? markers.cap * 2 : 8);
@@ -430,11 +435,13 @@ static void clientSetMarker(
 	*marker = (struct Marker) {0};
 	set(&marker->target, target);
 	set(&marker->timestamp, timestamp);
-reply:
-	clientFormat(
-		client, ":%s MARKREAD %s timestamp=%s\r\n",
-		clientOrigin, target, marker->timestamp
+notify:;
+	char buf[512];
+	snprintf(
+		buf, sizeof(buf), ":%s MARKREAD %s timestamp=%s",
+		clientOrigin, marker->target, marker->timestamp
 	);
+	ringProduce(buf);
 }
 
 static regex_t *TimestampRegex(void) {
@@ -677,6 +684,10 @@ static const char *filterMultiPrefix(const char *line) {
 	}
 }
 
+static const char *filterReadMarker(const char *line) {
+	return (wordcmp(line, 0, "MARKREAD") ? line : NULL);
+}
+
 static const char *filterPalaverApp(const char *line) {
 	return (wordcmp(line, 0, "PALAVER") ? line : NULL);
 }
@@ -707,6 +718,7 @@ static Filter *Filters[CapBits] = {
 	[CapMessageTagsBit] = filterMessageTags,
 	[CapMultiPrefixBit] = filterMultiPrefix,
 	[CapPalaverAppBit] = filterPalaverApp,
+	[CapReadMarkerBit] = filterReadMarker,
 	[CapSetnameBit] = filterSetname,
 	[CapUserhostInNamesBit] = filterUserhostInNames,
 };