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;
case BufferType.CHANNEL:
client.send({ command: "PART", params: [buf.name] });
if (buf.joined) {
client.send({ command: "PART", params: [buf.name] });
}
// fallthrough
case BufferType.NICK:
this.switchBuffer({ name: SERVER_BUFFER });
@ -1150,8 +1152,16 @@ export default class App extends Component {
});
}
handleJoinClick(serverID) {
this.openDialog("join", { server: serverID });
handleJoinClick(buf) {
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) {
@ -1351,7 +1361,7 @@ export default class App extends Component {
bouncerNetwork=${activeBouncerNetwork}
onChannelClick=${this.handleChannelClick}
onClose=${() => this.close(activeBuffer)}
onJoin=${() => this.handleJoinClick(activeBuffer.server)}
onJoin=${() => this.handleJoinClick(activeBuffer)}
onAddNetwork=${this.handleAddNetworkClick}
onManageNetwork=${() => this.handleManageNetworkClick(activeBuffer.server)}
/>

View file

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

View file

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