Showing
1 changed file
with
13 additions
and
2 deletions
... | @@ -31,7 +31,6 @@ export const Room: React.FC = () => { | ... | @@ -31,7 +31,6 @@ export const Room: React.FC = () => { |
31 | const handleUpdateRoomUser = useCallback((rawMessage: RawMessage) => { | 31 | const handleUpdateRoomUser = useCallback((rawMessage: RawMessage) => { |
32 | if (rawMessage.type == MessageType.ROOM_USER_UPDATE) { | 32 | if (rawMessage.type == MessageType.ROOM_USER_UPDATE) { |
33 | const data = rawMessage.message as UpdateRoomUser; | 33 | const data = rawMessage.message as UpdateRoomUser; |
34 | - console.log(data); | ||
35 | if (data.state == 'removed') { | 34 | if (data.state == 'removed') { |
36 | const newUsers = roomData.users; | 35 | const newUsers = roomData.users; |
37 | const index = newUsers.indexOf(data.user); | 36 | const index = newUsers.indexOf(data.user); |
... | @@ -44,7 +43,19 @@ export const Room: React.FC = () => { | ... | @@ -44,7 +43,19 @@ export const Room: React.FC = () => { |
44 | ...roomData, | 43 | ...roomData, |
45 | users: newUsers | 44 | users: newUsers |
46 | }); | 45 | }); |
47 | - } else if (data.state == 'added') { | 46 | + } else if (data.state === 'updated') { |
47 | + const newUsers = roomData.users; | ||
48 | + const index = newUsers.findIndex(x => x.username === data.user.username); | ||
49 | + if (index < 0) { | ||
50 | + console.log('존재하지 않는 유저를 업데이트 시도'); | ||
51 | + } else { | ||
52 | + newUsers[index] = data.user; | ||
53 | + } | ||
54 | + setRoomData({ | ||
55 | + ...roomData, | ||
56 | + users: newUsers | ||
57 | + }) | ||
58 | + } else { | ||
48 | setRoomData({ | 59 | setRoomData({ |
49 | ...roomData, | 60 | ...roomData, |
50 | users: [data.user, ...roomData.users] | 61 | users: [data.user, ...roomData.users] | ... | ... |
-
Please register or login to post a comment