Implement invite list

This commit is contained in:
Pavel Djundik 2019-04-14 14:44:44 +03:00
parent 5d479f3e62
commit 830fdda91a
8 changed files with 74 additions and 16 deletions

View File

@ -107,6 +107,7 @@ import MessageList from "./MessageList.vue";
import ChatInput from "./ChatInput.vue"; import ChatInput from "./ChatInput.vue";
import ChatUserList from "./ChatUserList.vue"; import ChatUserList from "./ChatUserList.vue";
import ListBans from "./Special/ListBans.vue"; import ListBans from "./Special/ListBans.vue";
import ListInvites from "./Special/ListInvites.vue";
import ListChannels from "./Special/ListChannels.vue"; import ListChannels from "./Special/ListChannels.vue";
import ListIgnored from "./Special/ListIgnored.vue"; import ListIgnored from "./Special/ListIgnored.vue";
@ -126,6 +127,7 @@ export default {
specialComponent() { specialComponent() {
switch (this.channel.special) { switch (this.channel.special) {
case "list_bans": return ListBans; case "list_bans": return ListBans;
case "list_invites": return ListInvites;
case "list_channels": return ListChannels; case "list_channels": return ListChannels;
case "list_ignored": return ListIgnored; case "list_ignored": return ListIgnored;
} }

View File

@ -0,0 +1,31 @@
<template>
<table class="invite-list">
<thead>
<tr>
<th class="hostmask">Invited</th>
<th class="invitened_by">Invited By</th>
<th class="invitened_at">Invited At</th>
</tr>
</thead>
<tbody>
<tr
v-for="invite in channel.data"
:key="invite.hostmask"
>
<td class="hostmask">{{ invite.hostmask }}</td>
<td class="invitened_by">{{ invite.invited_by }}</td>
<td class="invitened_at">{{ invite.invited_at | localetime }}</td>
</tr>
</tbody>
</table>
</template>
<script>
export default {
name: "ListInvites",
props: {
network: Object,
channel: Object,
},
};
</script>

View File

@ -1318,6 +1318,7 @@ background on hover (unless active) */
#chat table.channel-list, #chat table.channel-list,
#chat table.ban-list, #chat table.ban-list,
#chat table.invite-list,
#chat table.ignore-list { #chat table.ignore-list {
margin: 5px 10px; margin: 5px 10px;
width: calc(100% - 30px); width: calc(100% - 30px);
@ -1325,9 +1326,11 @@ background on hover (unless active) */
#chat table.channel-list th, #chat table.channel-list th,
#chat table.ban-list th, #chat table.ban-list th,
#chat table.invite-list th,
#chat table.ignore-list th, #chat table.ignore-list th,
#chat table.channel-list td, #chat table.channel-list td,
#chat table.ban-list td, #chat table.ban-list td,
#chat table.invite-list td,
#chat.table.ignore-list td { #chat.table.ignore-list td {
padding: 5px; padding: 5px;
vertical-align: top; vertical-align: top;

View File

@ -43,6 +43,7 @@ const commands = [
"/ignore", "/ignore",
"/ignorelist", "/ignorelist",
"/invite", "/invite",
"/invitelist",
"/join", "/join",
"/kick", "/kick",
"/leave", "/leave",

View File

@ -21,7 +21,6 @@ const events = [
"away", "away",
"connection", "connection",
"unhandled", "unhandled",
"banlist",
"ctcp", "ctcp",
"chghost", "chghost",
"error", "error",
@ -29,6 +28,7 @@ const events = [
"join", "join",
"kick", "kick",
"mode", "mode",
"modelist",
"motd", "motd",
"message", "message",
"names", "names",

View File

@ -18,6 +18,7 @@ Chan.Type = {
Chan.SpecialType = { Chan.SpecialType = {
BANLIST: "list_bans", BANLIST: "list_bans",
INVITELIST: "list_invites",
CHANNELLIST: "list_channels", CHANNELLIST: "list_channels",
IGNORELIST: "list_ignored", IGNORELIST: "list_ignored",
}; };

View File

@ -3,9 +3,17 @@
const Chan = require("../../models/chan"); const Chan = require("../../models/chan");
const Msg = require("../../models/msg"); const Msg = require("../../models/msg");
exports.commands = ["invite"]; exports.commands = [
"invite",
"invitelist",
];
exports.input = function({irc}, chan, cmd, args) { exports.input = function({irc}, chan, cmd, args) {
if (cmd === "invitelist") {
irc.inviteList(chan.name);
return;
}
if (args.length === 2) { if (args.length === 2) {
irc.raw("INVITE", args[0], args[1]); // Channel provided in the command irc.raw("INVITE", args[0], args[1]); // Channel provided in the command
} else if (args.length === 1 && chan.type === Chan.Type.CHANNEL) { } else if (args.length === 1 && chan.type === Chan.Type.CHANNEL) {

View File

@ -6,19 +6,36 @@ const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
const client = this; const client = this;
irc.on("banlist", function(banlist) { irc.on("banlist", (list) => {
const channel = banlist.channel; const data = list.bans.map((ban) => ({
const bans = banlist.bans; 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({ const msg = new Msg({
time: Date.now(), time: Date.now(),
type: Msg.Type.ERROR, type: Msg.Type.ERROR,
text: "Banlist empty", text: `${name} is empty`,
}); });
let chan = network.getChannel(channel); 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") { if (typeof chan === "undefined") {
msg.showInActive = true; msg.showInActive = true;
chan = network.channels[0]; chan = network.channels[0];
@ -29,18 +46,13 @@ module.exports = function(irc, network) {
return; return;
} }
const chanName = `Banlist for ${channel}`; const chanName = `${name} for ${channel}`;
let chan = network.getChannel(chanName); 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") { if (typeof chan === "undefined") {
chan = client.createChannel({ chan = client.createChannel({
type: Chan.Type.SPECIAL, type: Chan.Type.SPECIAL,
special: Chan.SpecialType.BANLIST, special: type,
name: chanName, name: chanName,
data: data, data: data,
}); });
@ -57,5 +69,5 @@ module.exports = function(irc, network) {
data: data, data: data,
}); });
} }
}); }
}; };