Preact: Fix DMs not reconnecting
Some checks are pending
Node.js CI / build (22.x) (push) Waiting to run

Fixes the thing where, after reconnecting, DMs still looked
disconnected.
This commit is contained in:
Guangcong Luo 2025-12-04 15:30:41 +00:00
parent ebb7b1c4c7
commit 959b0af8a5
3 changed files with 13 additions and 8 deletions

View File

@ -970,7 +970,7 @@ export class PSRoom extends PSStreamModel<Args | null> implements RoomOptions {
* the room isn't connected to the game server but to something * the room isn't connected to the game server but to something
* else. * else.
* *
* `true` for DMs for historical reasons (TODO: fix) * 'client-only' for DMs
*/ */
connected: 'autoreconnect' | 'client-only' | 'expired' | boolean = false; connected: 'autoreconnect' | 'client-only' | 'expired' | boolean = false;
/** /**

View File

@ -68,8 +68,12 @@ export class ChatRoom extends PSRoom {
} }
override connect() { override connect() {
if (!this.connected || this.connected === 'autoreconnect') { if (!this.connected || this.connected === 'autoreconnect') {
if (this.pmTarget === null) PS.send(`/join ${this.id}`); if (this.pmTarget === null) {
this.connected = true; PS.send(`/join ${this.id}`);
this.connected = true;
} else {
this.connected = 'client-only';
}
this.connectWhenLoggedIn = false; this.connectWhenLoggedIn = false;
} }
} }
@ -729,7 +733,6 @@ export class ChatRoom extends PSRoom {
} }
override destroy() { override destroy() {
if (this.pmTarget) this.connected = false;
if (this.battle) { if (this.battle) {
// since battle is defined here, we might as well deallocate it here // since battle is defined here, we might as well deallocate it here
this.battle.destroy(); this.battle.destroy();
@ -1172,19 +1175,21 @@ export class ChatTextEntry extends preact.Component<{
override render() { override render() {
const { room } = this.props; const { room } = this.props;
const OLD_TEXTBOX = false; const OLD_TEXTBOX = false;
const canTalk = PS.user.named || room.id === 'dm-';
if (room.connected === 'client-only' && room.id.startsWith('battle-')) { if (room.connected === 'client-only' && room.id.startsWith('battle-')) {
return <div return <div
class="chat-log-add hasuserlist" onClick={this.focusIfNoSelection} style={{ left: this.props.left || 0 }} class="chat-log-add hasuserlist" onClick={this.focusIfNoSelection} style={{ left: this.props.left || 0 }}
><CopyableURLBox url={`https://psim.us/r/${room.id.slice(7)}`} /></div>; ><CopyableURLBox url={`https://psim.us/r/${room.id.slice(7)}`} /></div>;
} }
const canTalk = PS.user.named || room.id === 'dm-';
const connected = room.connected === true || room.connected === 'client-only';
return <div return <div
class="chat-log-add hasuserlist" onClick={this.focusIfNoSelection} style={{ left: this.props.left || 0 }} class="chat-log-add hasuserlist" onClick={this.focusIfNoSelection} style={{ left: this.props.left || 0 }}
> >
<form class={`chatbox${this.props.tinyLayout ? ' nolabel' : ''}`} style={canTalk ? {} : { display: 'none' }}> <form class={`chatbox${this.props.tinyLayout ? ' nolabel' : ''}`} style={canTalk ? {} : { display: 'none' }}>
<label style={`color:${BattleLog.usernameColor(PS.user.userid)}`}>{PS.user.name}:</label> <label style={`color:${BattleLog.usernameColor(PS.user.userid)}`}>{PS.user.name}:</label>
{OLD_TEXTBOX ? <textarea {OLD_TEXTBOX ? <textarea
class={room.connected === true && canTalk ? 'textbox autofocus' : 'textbox disabled'} class={connected && canTalk ? 'textbox autofocus' : 'textbox disabled'}
autofocus autofocus
rows={1} rows={1}
onInput={this.update} onInput={this.update}
@ -1192,7 +1197,7 @@ export class ChatTextEntry extends preact.Component<{
style={{ resize: 'none', width: '100%', height: '16px', padding: '2px 3px 1px 3px' }} style={{ resize: 'none', width: '100%', height: '16px', padding: '2px 3px 1px 3px' }}
placeholder={PSView.focusPreview(room)} placeholder={PSView.focusPreview(room)}
/> : <ChatTextBox /> : <ChatTextBox
disabled={room.connected !== true || !canTalk} disabled={!connected || !canTalk}
placeholder={PSView.focusPreview(room)} placeholder={PSView.focusPreview(room)}
/>} />}
</form> </form>

View File

@ -468,7 +468,7 @@ class NewsPanel extends PSRoomPanel {
change = (ev: Event) => { change = (ev: Event) => {
const target = ev.currentTarget as HTMLInputElement; const target = ev.currentTarget as HTMLInputElement;
if (target.value === '1') { if (target.value === '1') {
document.cookie = "preactalpha=1; expires=Thu, 1 Dec 2025 12:00:00 UTC; path=/"; document.cookie = "preactalpha=1; expires=Thu, 1 Jan 2026 12:00:00 UTC; path=/";
} else { } else {
document.cookie = "preactalpha=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; document.cookie = "preactalpha=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
} }