Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
macwilko committed Dec 31, 2023
1 parent e36ae18 commit 11c03c0
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions app/components/channel-feed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,37 @@ export default function ChannelFeed(props) {
try {
const update = JSON.parse(newMessageJson.message);

if (update.user.handle == channel.user.handle) {
return;
}

if (messages.length > 0) {

const idx = messages.length - 1;
const last = messages[idx];
const idx = messages.map((m) => m.id).indexOf(update.id);

if (last.id == update.id) {
if (idx >= 0) {

let mp = [...messages];

mp[idx] = update; //
mp[idx] = update;

setMessages(mp, () => {
if (update.user.handle == channel.user.handle) {
return
}
const feed = feedRef.current;
feed.scrollTop = feed.scrollHeight;
});
} else {
setMessages([...messages, update], () => {
if (update.user.handle == channel.user.handle) {
return
}
const feed = feedRef.current;
feed.scrollTop = feed.scrollHeight;
});
}
} else {
setMessages([update], () => {
if (update.user.handle == channel.user.handle) {
return
}
const feed = feedRef.current;
feed.scrollTop = feed.scrollHeight;
});
Expand All @@ -80,7 +84,7 @@ export default function ChannelFeed(props) {
console.error("encountered an error json decoding");
}
}
}, [messages, channel])
}, [messages, channel]);

useEffect(() => {
handleNewSocketMessage(lastJsonMessage);
Expand Down

0 comments on commit 11c03c0

Please sign in to comment.