mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-14 19:05:01 -05:00
components/buffer: fold NICK change chains
This commit is contained in:
parent
23ceda5523
commit
ebcb731e2f
1 changed files with 34 additions and 1 deletions
|
@ -643,7 +643,38 @@ export default class Buffer extends Component {
|
|||
`;
|
||||
}
|
||||
function createFoldGroup(msgs) {
|
||||
// Filter out PART → JOIN pairs
|
||||
// Merge NICK change chains
|
||||
let nickChanges = new Map();
|
||||
let mergedMsgs = [];
|
||||
for (let msg of msgs) {
|
||||
let keep = true;
|
||||
switch (msg.command) {
|
||||
case "PART":
|
||||
case "QUIT":
|
||||
nickChanges.delete(msg.prefix.name);
|
||||
break;
|
||||
case "NICK":
|
||||
let prev = nickChanges.get(msg.prefix.name);
|
||||
if (!prev) {
|
||||
// Future NICK messages may mutate this one
|
||||
msg = { ...msg };
|
||||
nickChanges.set(msg.params[0], msg);
|
||||
break;
|
||||
}
|
||||
|
||||
prev.params = msg.params;
|
||||
nickChanges.delete(msg.prefix.name);
|
||||
nickChanges.set(msg.params[0], prev);
|
||||
keep = false;
|
||||
break;
|
||||
}
|
||||
if (keep) {
|
||||
mergedMsgs.push(msg);
|
||||
}
|
||||
}
|
||||
msgs = mergedMsgs;
|
||||
|
||||
// Filter out PART → JOIN pairs, as well as no-op NICKs from previous step
|
||||
let partIndexes = new Map();
|
||||
let keep = [];
|
||||
msgs.forEach((msg, i) => {
|
||||
|
@ -654,6 +685,8 @@ export default class Buffer extends Component {
|
|||
keep[partIndexes.get(msg.prefix.name)] = false;
|
||||
partIndexes.delete(msg.prefix.name);
|
||||
keep.push(false);
|
||||
} else if (msg.command === "NICK" && msg.prefix.name == msg.params[0]) {
|
||||
keep.push(false);
|
||||
} else {
|
||||
keep.push(true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue