diff --git a/src/client.js b/src/client.js index c2264732..d5ac110a 100644 --- a/src/client.js +++ b/src/client.js @@ -271,6 +271,7 @@ Client.prototype.connect = function(args) { network.irc.requestCap([ "znc.in/self-message", // Legacy echo-message for ZNc + "znc.in/playback", // http://wiki.znc.in/Playback ]); events.forEach((plugin) => { diff --git a/src/models/chan.js b/src/models/chan.js index 446ef8e4..c82b7f6a 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -228,6 +228,10 @@ Chan.prototype.loadMessages = function(client, network) { .getMessages(network, this) .then((messages) => { if (messages.length === 0) { + if (network.irc.network.cap.isEnabled("znc.in/playback")) { + requestZncPlayback(this, network, 0); + } + return; } @@ -241,6 +245,12 @@ Chan.prototype.loadMessages = function(client, network) { chan: this.id, 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}`)); }; @@ -248,3 +258,7 @@ Chan.prototype.loadMessages = function(client, network) { Chan.prototype.isLoggable = function() { 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()); +}