~emersion/gamja

ebcb731e2fbebe92450e00f2efa4fc10f004aea2 — Simon Ser a month ago 23ceda5
components/buffer: fold NICK change chains
1 files changed, 34 insertions(+), 1 deletions(-)

M components/buffer.js
M components/buffer.js => components/buffer.js +34 -1
@@ 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);
				}