Correctly handle away and back events

Also support for self messages

Co-Authored-By: jay2k1 <jay2k1@users.noreply.github.com>
This commit is contained in:
Pavel Djundik 2018-06-20 19:32:19 +03:00
parent bdccfd82f1
commit b8d60ddaa6
3 changed files with 33 additions and 8 deletions

View File

@ -1,3 +1,7 @@
{{#if self}}
{{{parse text}}}
{{else}}
{{> ../user_name from}} {{> ../user_name from}}
is away is away
<i class="away-message">({{{parse text}}})</i> <i class="away-message">({{{parse text}}})</i>
{{/if}}

View File

@ -1,2 +1,6 @@
{{#if self}}
{{{parse text}}}
{{else}}
{{> ../user_name from}} {{> ../user_name from}}
is back is back
{{/if}}

View File

@ -4,9 +4,26 @@ const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
const client = this; 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; 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) => { network.channels.forEach((chan) => {
const user = chan.findUser(data.nick); const user = chan.findUser(data.nick);
@ -15,7 +32,7 @@ module.exports = function(irc, network) {
} }
const msg = new Msg({ const msg = new Msg({
type: away ? Msg.Type.AWAY : Msg.Type.BACK, type: type,
text: away || "", text: away || "",
time: data.time, time: data.time,
from: user, from: user,
@ -24,5 +41,5 @@ module.exports = function(irc, network) {
chan.pushMessage(client, msg); chan.pushMessage(client, msg);
user.away = away; user.away = away;
}); });
}); }
}; };