mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
Handle CHATHISTORY messages when reaching end of batch
Closes: https://todo.sr.ht/~emersion/gamja/115
This commit is contained in:
parent
f45b51d981
commit
4a981997f0
2 changed files with 16 additions and 9 deletions
|
@ -851,15 +851,12 @@ export default class App extends Component {
|
||||||
handleMessage(serverID, msg) {
|
handleMessage(serverID, msg) {
|
||||||
let client = this.clients.get(serverID);
|
let client = this.clients.get(serverID);
|
||||||
|
|
||||||
let destBuffers = this.routeMessage(serverID, msg);
|
|
||||||
|
|
||||||
if (irc.findBatchByType(msg, "chathistory")) {
|
if (irc.findBatchByType(msg, "chathistory")) {
|
||||||
destBuffers.forEach((bufName) => {
|
return; // Handled by the caller
|
||||||
this.addMessage(serverID, bufName, msg);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let destBuffers = this.routeMessage(serverID, msg);
|
||||||
|
|
||||||
this.setState((state) => State.handleMessage(state, msg, serverID, client));
|
this.setState((state) => State.handleMessage(state, msg, serverID, client));
|
||||||
|
|
||||||
let target, channel;
|
let target, channel;
|
||||||
|
@ -1090,7 +1087,14 @@ export default class App extends Component {
|
||||||
from = receiptFromMessage(lastMsg);
|
from = receiptFromMessage(lastMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.fetchHistoryBetween(target.name, from, to, CHATHISTORY_MAX_SIZE).catch((err) => {
|
client.fetchHistoryBetween(target.name, from, to, CHATHISTORY_MAX_SIZE).then((result) => {
|
||||||
|
for (let msg of result.messages) {
|
||||||
|
let destBuffers = this.routeMessage(serverID, msg);
|
||||||
|
for (let bufName of destBuffers) {
|
||||||
|
this.addMessage(serverID, target.name, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
console.error("Failed to fetch backlog for '" + target.name + "': ", err);
|
console.error("Failed to fetch backlog for '" + target.name + "': ", err);
|
||||||
this.showError("Failed to fetch backlog for '" + target.name + "'");
|
this.showError("Failed to fetch backlog for '" + target.name + "'");
|
||||||
});
|
});
|
||||||
|
@ -1496,6 +1500,9 @@ export default class App extends Component {
|
||||||
|
|
||||||
client.fetchHistoryBefore(buf.name, before, limit).then((result) => {
|
client.fetchHistoryBefore(buf.name, before, limit).then((result) => {
|
||||||
this.endOfHistory.set(buf.id, !result.more);
|
this.endOfHistory.set(buf.id, !result.more);
|
||||||
|
for (let msg of result.messages) {
|
||||||
|
this.addMessage(buf.server, buf.name, msg);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -886,7 +886,7 @@ export default class Client extends EventTarget {
|
||||||
let max = Math.min(limit, this.isupport.chatHistory());
|
let max = Math.min(limit, this.isupport.chatHistory());
|
||||||
let params = ["BEFORE", target, "timestamp=" + before, max];
|
let params = ["BEFORE", target, "timestamp=" + before, max];
|
||||||
return this.roundtripChatHistory(params).then((messages) => {
|
return this.roundtripChatHistory(params).then((messages) => {
|
||||||
return { more: messages.length >= max };
|
return { messages, more: messages.length >= max };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,7 +904,7 @@ export default class Client extends EventTarget {
|
||||||
after.time = messages[messages.length - 1].tags.time;
|
after.time = messages[messages.length - 1].tags.time;
|
||||||
return this.fetchHistoryBetween(target, after, before, limit);
|
return this.fetchHistoryBetween(target, after, before, limit);
|
||||||
}
|
}
|
||||||
return null;
|
return { messages };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue