Pass PREFIX and CHANTYPES to parser

This commit is contained in:
Pavel Djundik 2018-07-19 20:44:24 +03:00 committed by Pavel Djundik
parent cebfa6ac84
commit f2cbd1efed
21 changed files with 81 additions and 29 deletions

View File

@ -28,6 +28,7 @@
:title="channel.topic" :title="channel.topic"
class="topic"><ParsedMessage class="topic"><ParsedMessage
v-if="channel.topic" v-if="channel.topic"
:network="network"
:text="channel.topic"/></span> :text="channel.topic"/></span>
<button <button
class="menu" class="menu"
@ -50,6 +51,7 @@
<div class="msg"> <div class="msg">
<component <component
:is="specialComponent" :is="specialComponent"
:network="network"
:channel="channel"/> :channel="channel"/>
</div> </div>
</div> </div>
@ -59,6 +61,7 @@
v-else v-else
class="chat-content"> class="chat-content">
<MessageList <MessageList
:network="network"
:channel="channel" :channel="channel"
:settings="settings"/> :settings="settings"/>
<ChatUserList <ChatUserList

View File

@ -19,12 +19,15 @@
<span class="from"/> <span class="from"/>
<component <component
:is="messageComponent" :is="messageComponent"
:network="network"
:message="message"/> :message="message"/>
</template> </template>
<template v-else-if="message.type === 'action'"> <template v-else-if="message.type === 'action'">
<span class="from"/> <span class="from"/>
<span class="content"> <span class="content">
<span class="text"><Username :user="message.from"/> <ParsedMessage :message="message"/></span> <span class="text"><Username :user="message.from"/> <ParsedMessage
:network="network"
:message="message"/></span>
<LinkPreview <LinkPreview
v-for="preview in message.previews" v-for="preview in message.previews"
:keep-scroll-position="keepScrollPosition" :keep-scroll-position="keepScrollPosition"
@ -39,7 +42,9 @@
</template> </template>
</span> </span>
<span class="content"> <span class="content">
<span class="text"><ParsedMessage :message="message"/></span> <span class="text"><ParsedMessage
:network="network"
:message="message"/></span>
<LinkPreview <LinkPreview
v-for="preview in message.previews" v-for="preview in message.previews"
:keep-scroll-position="keepScrollPosition" :keep-scroll-position="keepScrollPosition"
@ -65,6 +70,7 @@ export default {
components: MessageTypes, components: MessageTypes,
props: { props: {
message: Object, message: Object,
network: Object,
keepScrollPosition: Function, keepScrollPosition: Function,
}, },
computed: { computed: {

View File

@ -11,6 +11,7 @@
</div> </div>
<Message <Message
v-for="message in messages" v-for="message in messages"
:network="network"
:message="message" :message="message"
:key="message.id"/> :key="message.id"/>
</div> </div>
@ -26,6 +27,7 @@ export default {
Message, Message,
}, },
props: { props: {
network: Object,
messages: Array, messages: Array,
}, },
data() { data() {

View File

@ -46,9 +46,11 @@
<MessageCondensed <MessageCondensed
v-if="message.type === 'condensed'" v-if="message.type === 'condensed'"
:key="message.id" :key="message.id"
:network="network"
:messages="message.messages"/> :messages="message.messages"/>
<Message <Message
v-else v-else
:network="network"
:message="message" :message="message"
:key="message.id" :key="message.id"
:keep-scroll-position="keepScrollPosition" :keep-scroll-position="keepScrollPosition"
@ -89,6 +91,7 @@ export default {
}, },
props: { props: {
settings: Object, settings: Object,
network: Object,
channel: Object, channel: Object,
}, },
computed: { computed: {

View File

@ -2,11 +2,14 @@
<span class="content"> <span class="content">
<ParsedMessage <ParsedMessage
v-if="message.self" v-if="message.self"
:network="network"
:message="message"/> :message="message"/>
<template v-else> <template v-else>
<Username :user="message.from"/> <Username :user="message.from"/>
is away is away
<i class="away-message">(<ParsedMessage :message="message"/>)</i> <i class="away-message">(<ParsedMessage
:network="network"
:message="message"/>)</i>
</template> </template>
</span> </span>
</template> </template>
@ -22,6 +25,7 @@ export default {
Username, Username,
}, },
props: { props: {
network: Object,
message: Object, message: Object,
}, },
}; };

View File

@ -2,6 +2,7 @@
<span class="content"> <span class="content">
<ParsedMessage <ParsedMessage
v-if="message.self" v-if="message.self"
:network="network"
:message="message"/> :message="message"/>
<template v-else> <template v-else>
<Username :user="message.from"/> <Username :user="message.from"/>
@ -21,6 +22,7 @@ export default {
Username, Username,
}, },
props: { props: {
network: Object,
message: Object, message: Object,
}, },
}; };

View File

@ -6,7 +6,9 @@
<Username <Username
v-else v-else
:user="message.target"/> :user="message.target"/>
to <ParsedMessage :text="message.channel"/> to <ParsedMessage
:network="network"
:text="message.channel"/>
</span> </span>
</template> </template>
@ -21,6 +23,7 @@ export default {
Username, Username,
}, },
props: { props: {
network: Object,
message: Object, message: Object,
}, },
}; };

View File

@ -5,7 +5,9 @@
<Username :user="message.target"/> <Username :user="message.target"/>
<i <i
v-if="message.text" v-if="message.text"
class="part-reason">(<ParsedMessage :message="message"/>)</i> class="part-reason">(<ParsedMessage
:network="network"
:message="message"/>)</i>
</span> </span>
</template> </template>
@ -20,6 +22,7 @@ export default {
Username, Username,
}, },
props: { props: {
network: Object,
message: Object, message: Object,
}, },
}; };

View File

@ -1,6 +1,8 @@
<template> <template>
<span class="content"> <span class="content">
<span class="text"><ParsedMessage :text="cleanText"/></span> <span class="text"><ParsedMessage
:network="network"
:text="cleanText"/></span>
</span> </span>
</template> </template>
@ -13,6 +15,7 @@ export default {
ParsedMessage, ParsedMessage,
}, },
props: { props: {
network: Object,
message: Object, message: Object,
}, },
computed: { computed: {

View File

@ -5,7 +5,9 @@
has left the channel has left the channel
<i <i
v-if="message.text" v-if="message.text"
class="part-reason">(<ParsedMessage :message="message"/>)</i> class="part-reason">(<ParsedMessage
:network="network"
:message="message"/>)</i>
</span> </span>
</template> </template>
@ -20,6 +22,7 @@ export default {
Username, Username,
}, },
props: { props: {
network: Object,
message: Object, message: Object,
}, },
}; };

View File

@ -5,7 +5,9 @@
has quit has quit
<i <i
v-if="message.text" v-if="message.text"
class="quit-reason">(<ParsedMessage :message="message"/>)</i> class="quit-reason">(<ParsedMessage
:network="network"
:message="message"/>)</i>
</span> </span>
</template> </template>
@ -20,6 +22,7 @@ export default {
Username, Username,
}, },
props: { props: {
network: Object,
message: Object, message: Object,
}, },
}; };

View File

@ -9,7 +9,9 @@
</template> </template>
<span <span
v-if="message.text" v-if="message.text"
class="new-topic"><ParsedMessage :message="message"/></span> class="new-topic"><ParsedMessage
:network="network"
:message="message"/></span>
</span> </span>
</template> </template>
@ -24,6 +26,7 @@ export default {
Username, Username,
}, },
props: { props: {
network: Object,
message: Object, message: Object,
}, },
}; };

View File

@ -27,7 +27,9 @@
<template v-if="message.whois.real_name"> <template v-if="message.whois.real_name">
<dt>Real name:</dt> <dt>Real name:</dt>
<dd><ParsedMessage :text="message.whois.real_name"/></dd> <dd><ParsedMessage
:network="network"
:text="message.whois.real_name"/></dd>
</template> </template>
<template v-if="message.whois.registered_nick"> <template v-if="message.whois.registered_nick">
@ -37,7 +39,9 @@
<template v-if="message.whois.channels"> <template v-if="message.whois.channels">
<dt>Channels:</dt> <dt>Channels:</dt>
<dd><ParsedMessage :text="message.whois.channels"/></dd> <dd><ParsedMessage
:network="network"
:text="message.whois.channels"/></dd>
</template> </template>
<template v-if="message.whois.modes"> <template v-if="message.whois.modes">
@ -67,7 +71,9 @@
<template v-if="message.whois.away"> <template v-if="message.whois.away">
<dt>Away:</dt> <dt>Away:</dt>
<dd><ParsedMessage :text="message.whois.away"/></dd> <dd><ParsedMessage
:network="network"
:text="message.whois.away"/></dd>
</template> </template>
<template v-if="message.whois.secure"> <template v-if="message.whois.secure">
@ -104,6 +110,7 @@ export default {
Username, Username,
}, },
props: { props: {
network: Object,
message: Object, message: Object,
}, },
}; };

View File

@ -7,13 +7,15 @@ export default {
props: { props: {
text: String, text: String,
message: Object, message: Object,
network: Object,
}, },
render(createElement, context) { render(createElement, context) {
if (typeof context.props.text !== "undefined") { return parse(
return parse(createElement, context.props.text); createElement,
} typeof context.props.text !== "undefined" ? context.props.text : context.props.message.text,
context.props.message,
return parse(createElement, context.props.message.text, context.props.message); context.props.network
);
}, },
}; };
</script> </script>

View File

@ -23,6 +23,7 @@
export default { export default {
name: "ListBans", name: "ListBans",
props: { props: {
network: Object,
channel: Object, channel: Object,
}, },
}; };

View File

@ -14,9 +14,13 @@
<tr <tr
v-for="chan in channel.data" v-for="chan in channel.data"
:key="chan.channel"> :key="chan.channel">
<td class="channel"><ParsedMessage :text="chan.channel"/></td> <td class="channel"><ParsedMessage
:network="network"
:text="chan.channel"/></td>
<td class="users">{{ chan.num_users }}</td> <td class="users">{{ chan.num_users }}</td>
<td class="topic"><ParsedMessage :text="chan.topic"/></td> <td class="topic"><ParsedMessage
:network="network"
:text="chan.topic"/></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -31,6 +35,7 @@ export default {
ParsedMessage, ParsedMessage,
}, },
props: { props: {
network: Object,
channel: Object, channel: Object,
}, },
}; };

View File

@ -21,6 +21,7 @@
export default { export default {
name: "ListIgnored", name: "ListIgnored",
props: { props: {
network: Object,
channel: Object, channel: Object,
}, },
}; };

View File

@ -57,7 +57,7 @@ function createFragment(fragment, createElement) {
// 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(createElement, text, message = null) { module.exports = function parse(createElement, text, message = undefined, network = undefined) {
// 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("");
@ -65,8 +65,8 @@ module.exports = function parse(createElement, text, message = null) {
// On the plain text, find channels and URLs, returned as "parts". Parts are // On the plain text, find channels and URLs, returned as "parts". Parts are
// arrays of objects containing start and end markers, as well as metadata // arrays of objects containing start and end markers, as well as metadata
// depending on what was found (channel or link). // depending on what was found (channel or link).
const channelPrefixes = ["#", "&"]; // TODO Channel prefixes should be RPL_ISUPPORT.CHANTYPES const channelPrefixes = network ? network.serverOptions.CHANTYPES : ["#", "&"];
const userModes = ["!", "@", "%", "+"]; // TODO User modes should be RPL_ISUPPORT.PREFIX const userModes = network ? network.serverOptions.PREFIX : ["!", "@", "%", "+"];
const channelParts = findChannels(cleanText, channelPrefixes, userModes); const channelParts = findChannels(cleanText, channelPrefixes, userModes);
const linkParts = findLinks(cleanText); const linkParts = findLinks(cleanText);
const emojiParts = findEmoji(cleanText); const emojiParts = findEmoji(cleanText);

View File

@ -27,7 +27,7 @@ socket.on("network", function(data) {
.prop("disabled", false); .prop("disabled", false);
}); });
socket.on("network_changed", function(data) { socket.on("network:options", function(data) {
vueApp.networks.find((n) => n.uuid === data.network).serverOptions = data.serverOptions; vueApp.networks.find((n) => n.uuid === data.network).serverOptions = data.serverOptions;
}); });

View File

@ -40,6 +40,7 @@ function Network(attr) {
hostname: null, hostname: null,
irc: null, irc: null,
serverOptions: { serverOptions: {
CHANTYPES: [],
PREFIX: [], PREFIX: [],
NETWORK: "", NETWORK: "",
}, },

View File

@ -142,20 +142,17 @@ module.exports = function(irc, network) {
}); });
irc.on("server options", function(data) { irc.on("server options", function(data) {
if (network.serverOptions.PREFIX === data.options.PREFIX && network.serverOptions.NETWORK === data.options.NETWORK) {
return;
}
network.prefixLookup = {}; network.prefixLookup = {};
data.options.PREFIX.forEach((mode) => { data.options.PREFIX.forEach((mode) => {
network.prefixLookup[mode.mode] = mode.symbol; network.prefixLookup[mode.mode] = mode.symbol;
}); });
network.serverOptions.PREFIX = data.options.PREFIX; network.serverOptions.CHANTYPES = data.options.CHANTYPES;
network.serverOptions.PREFIX = data.options.PREFIX.map((p) => p.symbol);
network.serverOptions.NETWORK = data.options.NETWORK; network.serverOptions.NETWORK = data.options.NETWORK;
client.emit("network_changed", { client.emit("network:options", {
network: network.uuid, network: network.uuid,
serverOptions: network.serverOptions, serverOptions: network.serverOptions,
}); });