From a591989f8859d0fadaa41e1c5c5355d3c5b34aa7 Mon Sep 17 00:00:00 2001
From: Zita Szupera <szuperaz@gmail.com>
Date: Fri, 15 Dec 2023 10:09:33 +0100
Subject: [PATCH] fix: don't change readBy array reference on message.read
 event

---
 projects/stream-chat-angular/src/lib/channel.service.ts | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/projects/stream-chat-angular/src/lib/channel.service.ts b/projects/stream-chat-angular/src/lib/channel.service.ts
index 7fe39c84..743663ac 100644
--- a/projects/stream-chat-angular/src/lib/channel.service.ts
+++ b/projects/stream-chat-angular/src/lib/channel.service.ts
@@ -1375,7 +1375,12 @@ export class ChannelService<
           if (!latestMessage || !e.user) {
             return;
           }
-          latestMessage.readBy = getReadBy(latestMessage, channel);
+          if (latestMessage.readBy) {
+            latestMessage.readBy.splice(0, latestMessage.readBy.length);
+          } else {
+            latestMessage.readBy = [];
+          }
+          latestMessage.readBy.push(...getReadBy(latestMessage, channel));
           messages[messages.length - 1] = { ...latestMessage };
 
           this.activeChannelMessagesSubject.next([...messages]);