Port ignore list to Vue

This commit is contained in:
Pavel Djundik 2018-07-11 10:54:32 +03:00 committed by Pavel Djundik
parent 739d44b561
commit 771739cf94
6 changed files with 43 additions and 48 deletions

View File

@ -91,6 +91,7 @@ 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 ListChannels from "./Special/ListChannels.vue"; import ListChannels from "./Special/ListChannels.vue";
import ListIgnored from "./Special/ListIgnored.vue";
export default { export default {
name: "Chat", name: "Chat",
@ -109,6 +110,7 @@ export default {
switch (this.channel.special) { switch (this.channel.special) {
case "list_bans": return ListBans; case "list_bans": return ListBans;
case "list_channels": return ListChannels; case "list_channels": return ListChannels;
case "list_ignored": return ListIgnored;
} }
}, },
}, },

View File

@ -0,0 +1,27 @@
<template>
<table class="ignore-list">
<thead>
<tr>
<th class="hostmask">Hostmask</th>
<th class="when">Ignored At</th>
</tr>
</thead>
<tbody>
<tr
v-for="user in channel.data"
:key="user.hostmask">
<td class="hostmask">{{ user.hostmask }}</td>
<td class="when">{{ user.when | localetime }}</td>
</tr>
</tbody>
</table>
</template>
<script>
export default {
name: "ListIgnored",
props: {
channel: Object,
},
};
</script>

View File

@ -64,12 +64,7 @@ function createFragment(fragment) {
// Transform an IRC message potentially filled with styling control codes, URLs, // Transform an IRC message potentially filled with styling control codes, URLs,
// nicknames, and channels into a string of HTML elements to display on the client. // nicknames, and channels into a string of HTML elements to display on the client.
module.exports = function parse(text, users) { module.exports = function parse(text, users = []) {
// if it's not the users we're expecting, but rather is passed from Handlebars (occurs when users passed to template is null or undefined)
if (users && users.hash) {
users = [];
}
// Extract the styling information and get the plain text version from it // Extract the styling information and get the plain text version from it
const styleFragments = parseStyle(text); const styleFragments = parseStyle(text);
const cleanText = styleFragments.map((fragment) => fragment.text).join(""); const cleanText = styleFragments.map((fragment) => fragment.text).join("");

View File

@ -1,18 +0,0 @@
<table class="channel-list">
<thead>
<tr>
<th class="channel">Channel</th>
<th class="users">Users</th>
<th class="topic">Topic</th>
</tr>
</thead>
<tbody>
{{#each channels}}
<tr>
<td class="channel">{{{parse channel}}}</td>
<td class="users">{{num_users}}</td>
<td class="topic">{{{parse topic}}}</td>
</tr>
{{/each}}
</tbody>
</table>

View File

@ -1,16 +0,0 @@
<table class="ignore-list">
<thead>
<tr>
<th class="hostmask">Hostmask</th>
<th class="when">Ignored At</th>
</tr>
</thead>
<tbody>
{{#each ignored}}
<tr>
<td class="hostmask">{{hostmask}}</td>
<td class="when">{{{localetime when}}}</td>
</tr>
{{/each}}
</tbody>
</table>

View File

@ -92,27 +92,32 @@ exports.input = function(network, chan, cmd, args) {
})); }));
} else { } else {
const chanName = "Ignored users"; const chanName = "Ignored users";
const ignored = network.ignoreList.map((data) => ({
hostmask: `${data.nick}!${data.ident}@${data.hostname}`,
when: data.when,
}));
let newChan = network.getChannel(chanName); let newChan = network.getChannel(chanName);
if (typeof newChan === "undefined") { if (typeof newChan === "undefined") {
newChan = client.createChannel({ newChan = client.createChannel({
type: Chan.Type.SPECIAL, type: Chan.Type.SPECIAL,
special: Chan.SpecialType.IGNORELIST,
name: chanName, name: chanName,
data: ignored,
}); });
client.emit("join", { client.emit("join", {
network: network.uuid, network: network.uuid,
chan: newChan.getFilteredClone(true), chan: newChan.getFilteredClone(true),
index: network.addChannel(newChan), index: network.addChannel(newChan),
}); });
} } else {
newChan.data = ignored;
newChan.pushMessage(client, new Msg({ client.emit("msg:special", {
type: Msg.Type.IGNORELIST, chan: newChan.id,
ignored: network.ignoreList.map((data) => ({ data: ignored,
hostmask: `${data.nick}!${data.ident}@${data.hostname}`, });
when: data.when, }
})),
}), true);
} }
break; break;