From cd874b2d68bd0a0e2b2021bb344f1fa68113ab16 Mon Sep 17 00:00:00 2001
From: "Richard T. Carback III" <rick.carback@gmail.com>
Date: Tue, 13 Jun 2023 20:54:23 +0000
Subject: [PATCH] Use UpdateFromMessageID instead of recursing

---
 indexedDb/impl/channels/implementation.go | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/indexedDb/impl/channels/implementation.go b/indexedDb/impl/channels/implementation.go
index 91dd1cbf..0cb483e3 100644
--- a/indexedDb/impl/channels/implementation.go
+++ b/indexedDb/impl/channels/implementation.go
@@ -436,19 +436,20 @@ func (w *wasmModel) upsertMessage(msg *Message) (uint64, error) {
 	msgIdObj, err := impl.Put(w.db, messageStoreName, messageObj)
 	if err != nil {
 		// Do not error out when this message already exists inside
-		// the DB. Instead, set the ID and re-attempt as an upsert.
+		// the DB. Instead, set the ID and re-attempt as an update.
 		if msg.ID == 0 { // always error out when not an insert attempt
 			msgID, inErr := message.UnmarshalID(msg.MessageID)
 			if inErr == nil {
 				jww.WARN.Printf("upsertMessage duplicate: %+v",
 					err)
-				existingMsg, inErr := w.GetMessage(msgID)
-				if inErr == nil && existingMsg.UUID != 0 {
-					msg.ID = existingMsg.UUID
-					return w.upsertMessage(msg)
-				}
-				jww.ERROR.Printf("upsertMessage no UUID: %+v",
-					inErr)
+				rnd := &rounds.Round{ID: id.Round(msg.Round)}
+				status := (*channels.SentStatus)(&msg.Status)
+				return w.UpdateFromMessageID(msgID,
+					&msg.Timestamp,
+					rnd,
+					&msg.Pinned,
+					&msg.Hidden,
+					status)
 			}
 		}
 		return 0, errors.Errorf("Unable to put Message: %+v\n%s",
-- 
GitLab