From b8d60ddaa6e405f800d88afbec7f05d3e91e5de4 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 20 Jun 2018 19:32:19 +0300 Subject: [PATCH] Correctly handle away and back events Also support for self messages Co-Authored-By: jay2k1 --- client/views/actions/away.tpl | 10 +++++++--- client/views/actions/back.tpl | 8 ++++++-- src/plugins/irc-events/away.js | 23 ++++++++++++++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/client/views/actions/away.tpl b/client/views/actions/away.tpl index 04a54bc6..a7a894e7 100644 --- a/client/views/actions/away.tpl +++ b/client/views/actions/away.tpl @@ -1,3 +1,7 @@ -{{> ../user_name from}} -is away -({{{parse text}}}) +{{#if self}} + {{{parse text}}} +{{else}} + {{> ../user_name from}} + is away + ({{{parse text}}}) +{{/if}} diff --git a/client/views/actions/back.tpl b/client/views/actions/back.tpl index 02520366..bd7a66de 100644 --- a/client/views/actions/back.tpl +++ b/client/views/actions/back.tpl @@ -1,2 +1,6 @@ -{{> ../user_name from}} -is back +{{#if self}} + {{{parse text}}} +{{else}} + {{> ../user_name from}} + is back +{{/if}} diff --git a/src/plugins/irc-events/away.js b/src/plugins/irc-events/away.js index e0cc9e3b..25895632 100644 --- a/src/plugins/irc-events/away.js +++ b/src/plugins/irc-events/away.js @@ -4,9 +4,26 @@ const Msg = require("../../models/msg"); module.exports = function(irc, network) { const client = this; - irc.on("away", (data) => { + + irc.on("away", (data) => handleAway(Msg.Type.AWAY, data)); + irc.on("back", (data) => handleAway(Msg.Type.BACK, data)); + + function handleAway(type, data) { const away = data.message; + if (data.self) { + const msg = new Msg({ + self: true, + type: type, + text: away, + time: data.time, + }); + + network.channels[0].pushMessage(client, msg, true); + + return; + } + network.channels.forEach((chan) => { const user = chan.findUser(data.nick); @@ -15,7 +32,7 @@ module.exports = function(irc, network) { } const msg = new Msg({ - type: away ? Msg.Type.AWAY : Msg.Type.BACK, + type: type, text: away || "", time: data.time, from: user, @@ -24,5 +41,5 @@ module.exports = function(irc, network) { chan.pushMessage(client, msg); user.away = away; }); - }); + } };