Clean up a few minor code quality issues in the chat system.
This commit is contained in:
parent
ae58ca89eb
commit
41497958b6
3 changed files with 3 additions and 11 deletions
|
@ -68,10 +68,7 @@ export function ChatProvider({ children }: PropsWithChildren) {
|
||||||
|
|
||||||
const setMessagesAndRead = useCallback((messages: IChatMessage[]) => {
|
const setMessagesAndRead = useCallback((messages: IChatMessage[]) => {
|
||||||
setMessages(messages);
|
setMessages(messages);
|
||||||
console.log("TSRM begin");
|
|
||||||
console.log(messages);
|
|
||||||
trySendReadMessage(messages);
|
trySendReadMessage(messages);
|
||||||
console.log("TSRM end")
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const addMessage = useCallback((message: IChatMessage) => {
|
const addMessage = useCallback((message: IChatMessage) => {
|
||||||
|
@ -151,7 +148,6 @@ export function ChatProvider({ children }: PropsWithChildren) {
|
||||||
const [lastMaxTime, setLastMaxTime] = useState<number | null>(null);
|
const [lastMaxTime, setLastMaxTime] = useState<number | null>(null);
|
||||||
const trySendReadMessage = useCallback((messages: IChatMessage[]) => {
|
const trySendReadMessage = useCallback((messages: IChatMessage[]) => {
|
||||||
if (messages.length === 0) {
|
if (messages.length === 0) {
|
||||||
console.log("Early abort");
|
|
||||||
return; // Exit if the messages array is empty
|
return; // Exit if the messages array is empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,10 +156,7 @@ export function ChatProvider({ children }: PropsWithChildren) {
|
||||||
if (maxTime !== lastMaxTime) { // Only emit if there's a new maxTime
|
if (maxTime !== lastMaxTime) { // Only emit if there's a new maxTime
|
||||||
setLastMaxTime(maxTime); // Update the stored maxTime
|
setLastMaxTime(maxTime); // Update the stored maxTime
|
||||||
socket.current?.emit(ChatHandlers.READ, maxTime);
|
socket.current?.emit(ChatHandlers.READ, maxTime);
|
||||||
console.log("Smaxy");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("duvo");
|
|
||||||
}, [lastMaxTime]);
|
}, [lastMaxTime]);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ def speak(data, v):
|
||||||
|
|
||||||
@socketio.on('connect')
|
@socketio.on('connect')
|
||||||
@chat_is_allowed()
|
@chat_is_allowed()
|
||||||
def onConnect(v):
|
def on_connect(v):
|
||||||
if v.username not in online:
|
if v.username not in online:
|
||||||
online.append(v.username)
|
online.append(v.username)
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ def onConnect(v):
|
||||||
|
|
||||||
@socketio.on('disconnect')
|
@socketio.on('disconnect')
|
||||||
@chat_is_allowed()
|
@chat_is_allowed()
|
||||||
def onDisconnect(v):
|
def on_disconnect(v):
|
||||||
if v.username in online:
|
if v.username in online:
|
||||||
online.remove(v.username)
|
online.remove(v.username)
|
||||||
|
|
||||||
|
@ -267,4 +267,3 @@ def reset_everything_seriously(_):
|
||||||
|
|
||||||
# Commit the changes to the database
|
# Commit the changes to the database
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ The first time you do this, it will take a while. It'll be (much) faster next ti
|
||||||
|
|
||||||
Most code edits will be reflected (almost) immediately. If you make any setup changes or database changes, you'll need to ctrl-C the docker-compose status log and run `docker-compose up --build` again.
|
Most code edits will be reflected (almost) immediately. If you make any setup changes or database changes, you'll need to ctrl-C the docker-compose status log and run `docker-compose up --build` again.
|
||||||
|
|
||||||
Chat-related code edits will take a minute to update (if it's in Python) or won't be reflected automatically at all (if it's in Flask). Improvements welcome! But almost nobody touches these systems, so it hasn't been a priority.
|
Chat-related code edits will take a minute to update (if it's in Python) or won't be reflected automatically at all (if it's in React). Improvements welcome! But almost nobody touches these systems, so it hasn't been a priority.
|
||||||
|
|
||||||
# Run the E2E tests:
|
# Run the E2E tests:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue