From 77f54080e7e0855896f35c87dd70a2b7f858ecc7 Mon Sep 17 00:00:00 2001
From: Simon Ser <contact@emersion.fr>
Date: Fri, 11 Feb 2022 16:59:56 +0100
Subject: [PATCH] Make delivery receipts follow read receipts

If a message has been read, it's been delivered.

Fixes #23 at least partially.

References: https://todo.sr.ht/~emersion/gamja/23
---
 store.js | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/store.js b/store.js
index 1f283d1..4f93744 100644
--- a/store.js
+++ b/store.js
@@ -1,3 +1,5 @@
+import { ReceiptType } from "./state.js";
+
 const PREFIX = "gamja_";
 
 class Item {
@@ -90,6 +92,10 @@ export class Buffer {
 					updated = true;
 				}
 			});
+			if (receipts[ReceiptType.DELIVERED] < receipts[ReceiptType.READ]) {
+				receipts[ReceiptType.DELIVERED] = receipts[ReceiptType.READ];
+				updated = true;
+			}
 		}
 
 		if (!updated) {