2023-06-26 19:00:27 +03:00
|
|
|
import { NameChangeEvent } from '../../../interfaces/socket-events';
|
|
|
|
import { CurrentUser } from '../../../interfaces/current-user';
|
2022-05-26 23:52:04 +03:00
|
|
|
|
2023-06-26 19:00:27 +03:00
|
|
|
export function handleNameChangeEvent(
|
|
|
|
message: NameChangeEvent,
|
|
|
|
setChatMessages,
|
|
|
|
setCurrentUser: (_: (_: CurrentUser) => CurrentUser) => void,
|
|
|
|
) {
|
|
|
|
setCurrentUser(currentUser =>
|
|
|
|
currentUser.id === message.user.id
|
|
|
|
? {
|
|
|
|
...currentUser,
|
|
|
|
displayName: message.user.displayName,
|
|
|
|
}
|
|
|
|
: currentUser,
|
|
|
|
);
|
2022-12-30 07:11:20 +03:00
|
|
|
setChatMessages(currentState => [...currentState, message]);
|
2022-05-26 23:52:04 +03:00
|
|
|
}
|