Merge pull request #3176 from thelounge/xpaw/invite-list

Implement invite list
This commit is contained in:
Pavel Djundik 2019-04-15 16:43:24 +03:00 committed by GitHub
commit 451cd3657a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 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;
}

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.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;

View File

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

View File

@ -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",

View File

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

View File

@ -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) {

View File

@ -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,
});
}
});
}
};