Close a channel's web tab when the user parts or is kicked (closes #185) #192
+31
-5
@@ -355,6 +355,14 @@ function App() {
|
|||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// removeChannelTab closes a channel's tab and shows the Server tab.
|
||||||
|
const removeChannelTab = useCallback((name) => {
|
||||||
|
setTabs((prev) =>
|
||||||
|
prev.filter((t) => !(t.type === "channel" && t.name === name)),
|
||||||
|
);
|
||||||
|
setActiveTab(0);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const processMessage = useCallback(
|
const processMessage = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
const body = Array.isArray(msg.body) ? msg.body.join("\n") : "";
|
const body = Array.isArray(msg.body) ? msg.body.join("\n") : "";
|
||||||
@@ -424,6 +432,13 @@ function App() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "PART": {
|
case "PART": {
|
||||||
|
// The user's own PART, sent from this client or another,
|
||||||
|
// closes the tab and adds no message or unread count.
|
||||||
|
if (msg.from === nickRef.current) {
|
||||||
|
removeChannelTab(msg.to);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
const reason = body ? " (" + body + ")" : "";
|
const reason = body ? " (" + body + ")" : "";
|
||||||
const text = `${msg.from} has parted ${msg.to}${reason}`;
|
const text = `${msg.from} has parted ${msg.to}${reason}`;
|
||||||
if (msg.to) addMessage(msg.to, { ...base, text, system: true });
|
if (msg.to) addMessage(msg.to, { ...base, text, system: true });
|
||||||
@@ -431,6 +446,20 @@ function App() {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "KICK": {
|
||||||
|
// The kicked nick is in params; the body is the reason.
|
||||||
|
const kicked = Array.isArray(msg.params) ? msg.params[0] : "";
|
||||||
|
const reason = body ? " (" + body + ")" : "";
|
||||||
|
const text = `${kicked} was kicked from ${msg.to} by ${msg.from}${reason}`;
|
||||||
|
if (msg.to) addMessage(msg.to, { ...base, text, system: true });
|
||||||
|
if (kicked === nickRef.current) {
|
||||||
|
removeChannelTab(msg.to);
|
||||||
|
} else if (msg.to && msg.to.startsWith("#")) {
|
||||||
|
refreshMembers(msg.to);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "QUIT": {
|
case "QUIT": {
|
||||||
const reason = body ? " (" + body + ")" : "";
|
const reason = body ? " (" + body + ")" : "";
|
||||||
const text = `${msg.from} has quit${reason}`;
|
const text = `${msg.from} has quit${reason}`;
|
||||||
@@ -656,7 +685,7 @@ function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[addMessage, refreshMembers],
|
[addMessage, refreshMembers, removeChannelTab],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Long-poll loop.
|
// Long-poll loop.
|
||||||
@@ -865,10 +894,7 @@ function App() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Ignore.
|
// Ignore.
|
||||||
}
|
}
|
||||||
setTabs((prev) =>
|
removeChannelTab(name);
|
||||||
prev.filter((t) => !(t.type === "channel" && t.name === name)),
|
|
||||||
);
|
|
||||||
setActiveTab(0);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeTab = (idx) => {
|
const closeTab = (idx) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user