Add support for znc.in/playback

Fixes #1768
This commit is contained in:
Pavel Djundik 2018-02-02 23:38:25 +02:00
parent 941849eaa8
commit 8f59ca1bec
2 changed files with 15 additions and 0 deletions

View File

@ -271,6 +271,7 @@ Client.prototype.connect = function(args) {
network.irc.requestCap([ network.irc.requestCap([
"znc.in/self-message", // Legacy echo-message for ZNc "znc.in/self-message", // Legacy echo-message for ZNc
"znc.in/playback", // http://wiki.znc.in/Playback
]); ]);
events.forEach((plugin) => { events.forEach((plugin) => {

View File

@ -228,6 +228,10 @@ Chan.prototype.loadMessages = function(client, network) {
.getMessages(network, this) .getMessages(network, this)
.then((messages) => { .then((messages) => {
if (messages.length === 0) { if (messages.length === 0) {
if (network.irc.network.cap.isEnabled("znc.in/playback")) {
requestZncPlayback(this, network, 0);
}
return; return;
} }
@ -241,6 +245,12 @@ Chan.prototype.loadMessages = function(client, network) {
chan: this.id, chan: this.id,
messages: messages.slice(-100), messages: messages.slice(-100),
}); });
if (network.irc.network.cap.isEnabled("znc.in/playback")) {
const from = Math.floor(messages[messages.length - 1].time.getTime() / 1000);
requestZncPlayback(this, network, from);
}
}) })
.catch((err) => log.error(`Failed to load messages: ${err}`)); .catch((err) => log.error(`Failed to load messages: ${err}`));
}; };
@ -248,3 +258,7 @@ Chan.prototype.loadMessages = function(client, network) {
Chan.prototype.isLoggable = function() { Chan.prototype.isLoggable = function() {
return this.type === Chan.Type.CHANNEL || this.type === Chan.Type.QUERY; return this.type === Chan.Type.CHANNEL || this.type === Chan.Type.QUERY;
}; };
function requestZncPlayback(channel, network, from) {
network.irc.raw("ZNC", "*playback", "PLAY", channel.name, from.toString());
}