From 8f59ca1becfecfdb44d6f422fc519609bef13ac5 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 2 Feb 2018 23:38:25 +0200 Subject: [PATCH] Add support for znc.in/playback Fixes #1768 --- src/client.js | 1 + src/models/chan.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) 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()); +}