diff --git a/client/js/helpers/ircmessageparser/cleanIrcMessage.ts b/client/js/helpers/ircmessageparser/cleanIrcMessage.ts deleted file mode 100644 index 7e4fdf35..00000000 --- a/client/js/helpers/ircmessageparser/cleanIrcMessage.ts +++ /dev/null @@ -1,4 +0,0 @@ -const matchFormatting = - /\x02|\x1D|\x1F|\x16|\x0F|\x11|\x1E|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?|\x04(?:[0-9a-f]{6}(?:,[0-9a-f]{6})?)?/gi; - -export default (message: string) => message.replace(matchFormatting, "").trim(); diff --git a/client/js/helpers/ircmessageparser/findLinks.ts b/client/js/helpers/ircmessageparser/findLinks.ts deleted file mode 100644 index 15c38be9..00000000 --- a/client/js/helpers/ircmessageparser/findLinks.ts +++ /dev/null @@ -1,83 +0,0 @@ -import LinkifyIt, {Match} from "linkify-it"; -import {Part} from "./merge"; - -export type LinkPart = Part & { - link: string; -}; - -type OurMatch = Match & { - noschema?: boolean; -}; - -LinkifyIt.prototype.normalize = function normalize(match: OurMatch) { - if (!match.schema) { - match.schema = "http:"; - match.url = "http://" + match.url; - match.noschema = true; - } - - if (match.schema === "//") { - match.schema = "http:"; - match.url = "http:" + match.url; - match.noschema = true; - } - - if (match.schema === "mailto:" && !/^mailto:/i.test(match.url)) { - match.url = "mailto:" + match.url; - } -}; - -import tlds from "tlds"; -const linkify = LinkifyIt().tlds(tlds).tlds("onion", true); - -// Known schemes to detect in text -const commonSchemes = [ - "sftp", - "smb", - "file", - "irc", - "ircs", - "svn", - "git", - "steam", - "mumble", - "ts3server", - "svn+ssh", - "ssh", - "gopher", - "gemini", -]; - -for (const schema of commonSchemes) { - linkify.add(schema + ":", "http:"); -} - -function findLinks(text: string) { - const matches = linkify.match(text) as OurMatch[]; - - if (!matches) { - return []; - } - - return matches.map(returnUrl); -} - -function findLinksWithSchema(text: string) { - const matches = linkify.match(text) as OurMatch[]; - - if (!matches) { - return []; - } - - return matches.filter((url) => !url.noschema).map(returnUrl); -} - -function returnUrl(url: OurMatch): LinkPart { - return { - start: url.index, - end: url.lastIndex, - link: url.url, - }; -} - -export {findLinks, findLinksWithSchema}; diff --git a/client/js/helpers/ircmessageparser/merge.ts b/client/js/helpers/ircmessageparser/merge.ts index 9c728cec..707c495d 100644 --- a/client/js/helpers/ircmessageparser/merge.ts +++ b/client/js/helpers/ircmessageparser/merge.ts @@ -2,7 +2,7 @@ import anyIntersection from "./anyIntersection"; import fill from "./fill"; import {ChannelPart} from "./findChannels"; import {EmojiPart} from "./findEmoji"; -import {LinkPart} from "./findLinks"; +import {LinkPart} from "../../../../shared/linkify"; import {NamePart} from "./findNames"; export type Part = { diff --git a/client/js/helpers/parse.ts b/client/js/helpers/parse.ts index b120d70f..e69067a4 100644 --- a/client/js/helpers/parse.ts +++ b/client/js/helpers/parse.ts @@ -3,11 +3,11 @@ import {h as createElement, VNode} from "vue"; import parseStyle from "./ircmessageparser/parseStyle"; -import findChannels, {ChannelPart} from "./ircmessageparser/findChannels"; -import {findLinks, LinkPart} from "./ircmessageparser/findLinks"; -import findEmoji, {EmojiPart} from "./ircmessageparser/findEmoji"; -import findNames, {NamePart} from "./ircmessageparser/findNames"; -import merge, {MergedParts, Part} from "./ircmessageparser/merge"; +import findChannels from "./ircmessageparser/findChannels"; +import {findLinks} from "../../../shared/linkify"; +import findEmoji from "./ircmessageparser/findEmoji"; +import findNames from "./ircmessageparser/findNames"; +import merge, {MergedParts} from "./ircmessageparser/merge"; import emojiMap from "./fullnamemap.json"; import LinkPreviewToggle from "../../components/LinkPreviewToggle.vue"; import LinkPreviewFileSize from "../../components/LinkPreviewFileSize.vue"; diff --git a/client/js/socket-events/msg.ts b/client/js/socket-events/msg.ts index 523b2f56..4bb5e7c4 100644 --- a/client/js/socket-events/msg.ts +++ b/client/js/socket-events/msg.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/restrict-plus-operands */ import socket from "../socket"; -import cleanIrcMessage from "../helpers/ircmessageparser/cleanIrcMessage"; +import {cleanIrcMessage} from "../../../shared/irc"; import {store} from "../store"; import {switchToChannel} from "../router"; import {ClientChan, ClientMention, ClientMessage, NetChan} from "../types"; diff --git a/client/tsconfig.json b/client/tsconfig.json index f5434d2c..4054c4f1 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -1,7 +1,8 @@ { "extends": "../tsconfig.base.json" /* Path to base configuration file to inherit from. Requires TypeScript version 2.1 or later. */, "include": [ - "./**/*" + "./**/*", + "../shared" ] /* Specifies a list of glob patterns that match files to be included in compilation. If no 'files' or 'include' property is present in a tsconfig.json, the compiler defaults to including all files in the containing directory and subdirectories except those specified by 'exclude'. Requires TypeScript version 2.0 or later. */, "files": [ "../package.json", diff --git a/webpack.config.ts b/webpack.config.ts index b103b2a4..02a7ca54 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -58,7 +58,7 @@ const config: webpack.Configuration = { }, { test: /\.ts$/i, - include: [path.resolve(__dirname, "client")], + include: [path.resolve(__dirname, "client"), path.resolve(__dirname, "shared")], exclude: path.resolve(__dirname, "node_modules"), use: { loader: "babel-loader",