Skip to content

Commit 986b269

Browse files
committed
games: Update possibly-stale room reference on rejoining
1 parent 956817f commit 986b269

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/ps/handlers/joinRooms.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PSGames } from '@/cache';
12
import { gameCache } from '@/cache/games';
23
import { usePersistedCache } from '@/cache/persisted';
34
import { i18n } from '@/i18n';
@@ -17,6 +18,14 @@ export function joinRoomHandler(this: Client, roomid: string, user: string, isIn
1718

1819
const $T = i18n(getLanguage(room));
1920

21+
// If we have any existing games, we need to update the room reference (since a new room object is created on reconnect)
22+
Object.values(PSGames)
23+
.flatMap(games => Object.values(games ?? {}))
24+
.filter(game => game.roomid === roomid)
25+
.forEach(game => {
26+
game.room = room;
27+
});
28+
2029
const allBackups = openGamesCache.get();
2130
const gamesToRestore = allBackups.filter(backup => backup.roomid === roomid);
2231
gamesToRestore.forEach(toRestore => {

0 commit comments

Comments
 (0)