Keep track of channel join status

This makes us behave better when we receive a self-PART message
from the server.
This commit is contained in:
Simon Ser 2021-11-05 11:49:56 +01:00
parent 7b19cf48a4
commit 800f5ceb6a
3 changed files with 44 additions and 13 deletions

View file

@ -1023,7 +1023,9 @@ export default class App extends Component {
} }
break; break;
case BufferType.CHANNEL: case BufferType.CHANNEL:
if (buf.joined) {
client.send({ command: "PART", params: [buf.name] }); client.send({ command: "PART", params: [buf.name] });
}
// fallthrough // fallthrough
case BufferType.NICK: case BufferType.NICK:
this.switchBuffer({ name: SERVER_BUFFER }); this.switchBuffer({ name: SERVER_BUFFER });
@ -1150,8 +1152,16 @@ export default class App extends Component {
}); });
} }
handleJoinClick(serverID) { handleJoinClick(buf) {
this.openDialog("join", { server: serverID }); switch (buf.type) {
case BufferType.SERVER:
this.openDialog("join", { server: buf.server });
break;
case BufferType.CHANNEL:
let client = this.clients.get(buf.server);
client.send({ command: "JOIN", params: [buf.name] });
break;
}
} }
handleJoinSubmit(data) { handleJoinSubmit(data) {
@ -1351,7 +1361,7 @@ export default class App extends Component {
bouncerNetwork=${activeBouncerNetwork} bouncerNetwork=${activeBouncerNetwork}
onChannelClick=${this.handleChannelClick} onChannelClick=${this.handleChannelClick}
onClose=${() => this.close(activeBuffer)} onClose=${() => this.close(activeBuffer)}
onJoin=${() => this.handleJoinClick(activeBuffer.server)} onJoin=${() => this.handleJoinClick(activeBuffer)}
onAddNetwork=${this.handleAddNetworkClick} onAddNetwork=${this.handleAddNetworkClick}
onManageNetwork=${() => this.handleManageNetworkClick(activeBuffer.server)} onManageNetwork=${() => this.handleManageNetworkClick(activeBuffer.server)}
/> />

View file

@ -117,6 +117,7 @@ export default function BufferHeader(props) {
if (props.buffer.topic) { if (props.buffer.topic) {
description = linkify(stripANSI(props.buffer.topic), props.onChannelClick); description = linkify(stripANSI(props.buffer.topic), props.onChannelClick);
} }
if (props.buffer.joined) {
actions = html` actions = html`
<button <button
key="part" key="part"
@ -124,6 +125,19 @@ export default function BufferHeader(props) {
onClick=${handleCloseClick} onClick=${handleCloseClick}
>Leave</button> >Leave</button>
`; `;
} else {
actions = html`
<button
key="join"
onClick=${handleJoinClick}
>Join</button>
<button
key="part"
class="danger"
onClick=${handleCloseClick}
>Close</button>
`;
}
break; break;
case BufferType.NICK: case BufferType.NICK:
if (props.user) { if (props.user) {

View file

@ -283,6 +283,7 @@ export const State = {
type, type,
server: serverID, server: serverID,
serverInfo: null, // if server serverInfo: null, // if server
joined: false, // if channel
topic: null, // if channel topic: null, // if channel
members: new irc.CaseMapMap(null, client.cm), // if channel members: new irc.CaseMapMap(null, client.cm), // if channel
messages: [], messages: [],
@ -406,7 +407,10 @@ export const State = {
update = updateBuffer(channel, (buf) => { update = updateBuffer(channel, (buf) => {
let members = new irc.CaseMapMap(buf.members); let members = new irc.CaseMapMap(buf.members);
members.set(msg.prefix.name, ""); members.set(msg.prefix.name, "");
return { members };
let joined = buf.joined || client.isMyNick(msg.prefix.name);
return { members, joined };
}); });
state = { ...state, ...update }; state = { ...state, ...update };
@ -434,7 +438,10 @@ export const State = {
return updateBuffer(channel, (buf) => { return updateBuffer(channel, (buf) => {
let members = new irc.CaseMapMap(buf.members); let members = new irc.CaseMapMap(buf.members);
members.delete(msg.prefix.name); members.delete(msg.prefix.name);
return { members };
let joined = buf.joined && !client.isMyNick(msg.prefix.name);
return { members, joined };
}); });
case "KICK": case "KICK":
channel = msg.params[0]; channel = msg.params[0];