Skip to content

Commit d164cad

Browse files
committed
fix: improve message filtering and update handling in polling function
1 parent 835930f commit d164cad

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

‎frontend/script.js‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,28 @@ async function pollForMessages() {
6161

6262
if (messages.length > 0) {
6363
messages.sort((a, b) => a.timestamp - b.timestamp);
64-
const newMessages = messages.filter(
65-
(message) =>
66-
!displayedMessages.some(
67-
(item) => String(item.id) === String(message.id),
68-
),
64+
65+
// since filtresinin ilerlemesi için timestamp'i her zaman güncelle,
66+
// mesaj daha önce görülmüş (sadece reaksiyonu değişmiş) olsa bile.
67+
lastTimestamp = Math.max(
68+
lastTimestamp,
69+
...messages.map((message) => message.timestamp),
6970
);
7071

71-
if (newMessages.length > 0) {
72-
displayedMessages.push(...newMessages);
73-
lastTimestamp = Math.max(
74-
lastTimestamp,
75-
...newMessages.map((message) => message.timestamp),
72+
const newMessages = [];
73+
for (const message of messages) {
74+
const isNew = !displayedMessages.some(
75+
(item) => String(item.id) === String(message.id),
7676
);
77+
if (isNew) {
78+
displayedMessages.push(message);
79+
newMessages.push(message);
80+
} else {
81+
updateMessageReaction(message);
82+
}
83+
}
84+
85+
if (newMessages.length > 0) {
7786
appendMessages(newMessages);
7887
}
7988
}

0 commit comments

Comments
 (0)