diff --git a/src/app/chat/page.tsx b/src/app/chat/page.tsx
index 97c68cb..c3505b1 100644
--- a/src/app/chat/page.tsx
+++ b/src/app/chat/page.tsx
@@ -168,8 +168,8 @@ export default function Home() {
setConnected(true);
if (token != null)
socket.emit('SIG_CHAT_JOIN', { token }, joinChatRes);
-
- socket.emit('SIG_CHAT_CHANNELS', {}, channelsChatRes);
+ else
+ socket.emit('SIG_CHAT_CHANNELS', {}, channelsChatRes);
setTextBox(
@@ -267,17 +267,6 @@ export default function Home() {
removeUser(userId);
});
- const prevscrtop = useRef(0);
- useEffect(() => {
- if (
- chatPaneRef.current != null
- && chatPaneRef.current.scrollTop >= prevscrtop.current
- ) {
- chatPaneRef.current.scrollTop = chatPaneRef.current.scrollHeight;
- prevscrtop.current = chatPaneRef.current.scrollTop;
- }
- }, [messages])
-
// message stuff
function addMessage(messagesdata:MessageType) {
@@ -335,6 +324,7 @@ export default function Home() {
setError(type, spec, data);
} else {
setWhoAmI(data);
+ socket.emit('SIG_CHAT_CHANNELS', {}, channelsChatRes);
}
}
@@ -352,6 +342,8 @@ export default function Home() {
}
}
+ const prevscrtop = useRef(0);
+
function chgchannelChatRes({ type, spec, data }:Res) {
unsetError();
if (type.includes("ERR")) {
@@ -366,6 +358,7 @@ export default function Home() {
let [ messageLayout, setMessageLayout ] = useState();
useEffect(() => {
+
if (messages.length > 0)
setMessageLayout(messages.map(Message.current));
else if (whoami.admin || channels.find(x => x.name == channel)?.writable)
@@ -390,6 +383,16 @@ export default function Home() {
>);
}, [affectedByUpdate, messages]);
+ useEffect(() => {
+ if (
+ chatPaneRef.current != null
+ && chatPaneRef.current.scrollTop >= prevscrtop.current - 100
+ ) {
+ chatPaneRef.current.scrollTop = chatPaneRef.current.scrollHeight;
+ prevscrtop.current = chatPaneRef.current.scrollTop;
+ }
+ }, [messageLayout])
+
return (