Add support for draft/event-playback

This commit is contained in:
Simon Ser 2021-06-04 19:45:51 +02:00
parent 651e255ddb
commit 34078d5da7
4 changed files with 65 additions and 34 deletions

View file

@ -488,6 +488,7 @@ export default class App extends Component {
handleMessage(serverID, msg) {
var client = this.clients.get(serverID);
var chatHistoryBatch = irc.findBatchByType(msg, "chathistory");
this.setState((state) => State.handleMessage(state, msg, serverID, client));
@ -520,7 +521,9 @@ export default class App extends Component {
if (client.isChannel(target)) {
this.addMessage(serverID, target, msg);
}
if (!chatHistoryBatch) {
this.handleMode(serverID, msg);
}
break;
case "NOTICE":
case "PRIVMSG":
@ -559,7 +562,7 @@ export default class App extends Component {
this.addMessage(serverID, channel, msg);
if (client.isMyNick(msg.prefix.name)) {
if (!chatHistoryBatch && client.isMyNick(msg.prefix.name)) {
this.receipts.delete(channel);
this.saveReceipts();
}
@ -570,6 +573,9 @@ export default class App extends Component {
break;
case "QUIT":
var affectedBuffers = [];
if (chatHistoryBatch) {
affectedBuffers.push(chatHistoryBatch.params[0]);
} else {
this.setState((state) => {
var buffers = new Map(state.buffers);
state.buffers.forEach((buf) => {
@ -587,12 +593,17 @@ export default class App extends Component {
});
return { buffers };
});
}
affectedBuffers.forEach((name) => this.addMessage(serverID, name, msg));
break;
case "NICK":
var newNick = msg.params[0];
var affectedBuffers = [];
if (chatHistoryBatch) {
affectedBuffers.push(chatHistoryBatch.params[0]);
} else {
this.setState((state) => {
var buffers = new Map(state.buffers);
state.buffers.forEach((buf) => {
@ -610,6 +621,8 @@ export default class App extends Component {
});
return { buffers };
});
}
affectedBuffers.forEach((name) => this.addMessage(serverID, name, msg));
break;
case "TOPIC":

View file

@ -13,6 +13,7 @@ const permanentCaps = [
"setname",
"draft/chathistory",
"draft/event-playback",
"soju.im/bouncer-networks",
];
@ -160,6 +161,7 @@ export default class Client extends EventTarget {
msgBatch = this.batches.get(msg.tags["batch"]);
if (msgBatch) {
msgBatch.messages.push(msg);
msg.batch = msgBatch;
}
}

View file

@ -533,3 +533,14 @@ export function parseMembershipModes(str) {
}
return memberships;
}
export function findBatchByType(msg, type) {
var batch = msg.batch;
while (batch) {
if (batch.type === type) {
return batch;
}
batch = batch.parent;
}
return null;
}

View file

@ -249,6 +249,11 @@ export const State = {
return State.updateBuffer(state, { server: serverID, name }, updater);
}
// Don't update our internal state if it's a chat history message
if (irc.findBatchByType(msg, "chathistory")) {
return;
}
switch (msg.command) {
case irc.RPL_MYINFO:
// TODO: parse available modes