From 830fdda91ae286eb41081137b813e61cf4042b5d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 14 Apr 2019 14:44:44 +0300 Subject: [PATCH] Implement invite list --- client/components/Chat.vue | 2 + client/components/Special/ListInvites.vue | 31 ++++++++++++++ client/css/style.css | 3 ++ client/js/constants.js | 1 + src/client.js | 2 +- src/models/chan.js | 1 + src/plugins/inputs/invite.js | 10 ++++- .../irc-events/{banlist.js => modelist.js} | 40 ++++++++++++------- 8 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 client/components/Special/ListInvites.vue rename src/plugins/irc-events/{banlist.js => modelist.js} (59%) diff --git a/client/components/Chat.vue b/client/components/Chat.vue index 2fe4b856..5204e58e 100644 --- a/client/components/Chat.vue +++ b/client/components/Chat.vue @@ -107,6 +107,7 @@ import MessageList from "./MessageList.vue"; import ChatInput from "./ChatInput.vue"; import ChatUserList from "./ChatUserList.vue"; import ListBans from "./Special/ListBans.vue"; +import ListInvites from "./Special/ListInvites.vue"; import ListChannels from "./Special/ListChannels.vue"; import ListIgnored from "./Special/ListIgnored.vue"; @@ -126,6 +127,7 @@ export default { specialComponent() { switch (this.channel.special) { case "list_bans": return ListBans; + case "list_invites": return ListInvites; case "list_channels": return ListChannels; case "list_ignored": return ListIgnored; } diff --git a/client/components/Special/ListInvites.vue b/client/components/Special/ListInvites.vue new file mode 100644 index 00000000..dd0596be --- /dev/null +++ b/client/components/Special/ListInvites.vue @@ -0,0 +1,31 @@ + + + diff --git a/client/css/style.css b/client/css/style.css index a08ae8fa..028102a3 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -1318,6 +1318,7 @@ background on hover (unless active) */ #chat table.channel-list, #chat table.ban-list, +#chat table.invite-list, #chat table.ignore-list { margin: 5px 10px; width: calc(100% - 30px); @@ -1325,9 +1326,11 @@ background on hover (unless active) */ #chat table.channel-list th, #chat table.ban-list th, +#chat table.invite-list th, #chat table.ignore-list th, #chat table.channel-list td, #chat table.ban-list td, +#chat table.invite-list td, #chat.table.ignore-list td { padding: 5px; vertical-align: top; diff --git a/client/js/constants.js b/client/js/constants.js index 4d23628d..3432151d 100644 --- a/client/js/constants.js +++ b/client/js/constants.js @@ -43,6 +43,7 @@ const commands = [ "/ignore", "/ignorelist", "/invite", + "/invitelist", "/join", "/kick", "/leave", diff --git a/src/client.js b/src/client.js index 8295bddb..d29f22d6 100644 --- a/src/client.js +++ b/src/client.js @@ -21,7 +21,6 @@ const events = [ "away", "connection", "unhandled", - "banlist", "ctcp", "chghost", "error", @@ -29,6 +28,7 @@ const events = [ "join", "kick", "mode", + "modelist", "motd", "message", "names", diff --git a/src/models/chan.js b/src/models/chan.js index e6274874..7c272c7e 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -18,6 +18,7 @@ Chan.Type = { Chan.SpecialType = { BANLIST: "list_bans", + INVITELIST: "list_invites", CHANNELLIST: "list_channels", IGNORELIST: "list_ignored", }; diff --git a/src/plugins/inputs/invite.js b/src/plugins/inputs/invite.js index a50b4083..7b5702b3 100644 --- a/src/plugins/inputs/invite.js +++ b/src/plugins/inputs/invite.js @@ -3,9 +3,17 @@ const Chan = require("../../models/chan"); const Msg = require("../../models/msg"); -exports.commands = ["invite"]; +exports.commands = [ + "invite", + "invitelist", +]; exports.input = function({irc}, chan, cmd, args) { + if (cmd === "invitelist") { + irc.inviteList(chan.name); + return; + } + if (args.length === 2) { irc.raw("INVITE", args[0], args[1]); // Channel provided in the command } else if (args.length === 1 && chan.type === Chan.Type.CHANNEL) { diff --git a/src/plugins/irc-events/banlist.js b/src/plugins/irc-events/modelist.js similarity index 59% rename from src/plugins/irc-events/banlist.js rename to src/plugins/irc-events/modelist.js index 87ef0894..afb79e29 100644 --- a/src/plugins/irc-events/banlist.js +++ b/src/plugins/irc-events/modelist.js @@ -6,19 +6,36 @@ const Msg = require("../../models/msg"); module.exports = function(irc, network) { const client = this; - irc.on("banlist", function(banlist) { - const channel = banlist.channel; - const bans = banlist.bans; + irc.on("banlist", (list) => { + const data = list.bans.map((ban) => ({ + hostmask: ban.banned, + banned_by: ban.banned_by, + banned_at: ban.banned_at * 1000, + })); - if (!bans || bans.length === 0) { + handleList(Chan.SpecialType.BANLIST, "Ban list", list.channel, data); + }); + + irc.on("inviteList", (list) => { + const data = list.invites.map((invite) => ({ + hostmask: invite.invited, + invited_by: invite.invited_by, + invited_at: invite.invited_at * 1000, + })); + + handleList(Chan.SpecialType.INVITELIST, "Invite list", list.channel, data); + }); + + function handleList(type, name, channel, data) { + if (data.length === 0) { const msg = new Msg({ time: Date.now(), type: Msg.Type.ERROR, - text: "Banlist empty", + text: `${name} is empty`, }); let chan = network.getChannel(channel); - // Send error to lobby if we receive banlist for a channel we're not in + // Send error to lobby if we receive empty list for a channel we're not in if (typeof chan === "undefined") { msg.showInActive = true; chan = network.channels[0]; @@ -29,18 +46,13 @@ module.exports = function(irc, network) { return; } - const chanName = `Banlist for ${channel}`; + const chanName = `${name} for ${channel}`; let chan = network.getChannel(chanName); - const data = bans.map((ban) => ({ - hostmask: ban.banned, - banned_by: ban.banned_by, - banned_at: ban.banned_at * 1000, - })); if (typeof chan === "undefined") { chan = client.createChannel({ type: Chan.Type.SPECIAL, - special: Chan.SpecialType.BANLIST, + special: type, name: chanName, data: data, }); @@ -57,5 +69,5 @@ module.exports = function(irc, network) { data: data, }); } - }); + } };