diff options
author | Simon Ser <contact@emersion.fr> | 2023-04-19 11:43:45 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-04-19 11:43:45 +0200 |
commit | 57f64e9cc2670fd5cc5c16803890ab4e2fda6cbc (patch) | |
tree | 2663c7a7aaec37d27984f9b9bb749f2256c99fea | |
parent | 57809be989f564e88eebf31519f8cb44091f518c (diff) | |
download | gamja-57f64e9cc2670fd5cc5c16803890ab4e2fda6cbc.tar.gz gamja-57f64e9cc2670fd5cc5c16803890ab4e2fda6cbc.zip |
lib/irc: add formatURL
-rw-r--r-- | components/buffer.js | 6 | ||||
-rw-r--r-- | components/member-list.js | 3 | ||||
-rw-r--r-- | lib/irc.js | 11 | ||||
-rw-r--r-- | state.js | 14 |
4 files changed, 18 insertions, 16 deletions
diff --git a/components/buffer.js b/components/buffer.js index 58cb464..a165c5a 100644 --- a/components/buffer.js +++ b/components/buffer.js @@ -2,7 +2,7 @@ import { html, Component } from "../lib/index.js"; import linkify from "../lib/linkify.js"; import * as irc from "../lib/irc.js"; import { strip as stripANSI } from "../lib/ansi.js"; -import { BufferType, ServerStatus, BufferEventsDisplayMode, getNickURL, getChannelURL, getMessageURL, isMessageBeforeReceipt, SettingsContext } from "../state.js"; +import { BufferType, ServerStatus, BufferEventsDisplayMode, getMessageURL, isMessageBeforeReceipt, SettingsContext } from "../state.js"; import * as store from "../store.js"; import Membership from "./membership.js"; @@ -23,7 +23,7 @@ function Nick(props) { let colorIndex = djb2(props.nick) % 16 + 1; return html` - <a href=${getNickURL(props.nick)} class="nick nick-${colorIndex}" onClick=${handleClick}>${props.nick}</a> + <a href=${irc.formatURL({ entity: props.nick })} class="nick nick-${colorIndex}" onClick=${handleClick}>${props.nick}</a> `; } @@ -103,7 +103,7 @@ class LogLine extends Component { } function createChannel(channel) { return html` - <a href=${getChannelURL(channel)} onClick=${onChannelClick}> + <a href=${irc.formatURL({ entity: channel })} onClick=${onChannelClick}> ${channel} </a> `; diff --git a/components/member-list.js b/components/member-list.js index 70847cf..d7fa439 100644 --- a/components/member-list.js +++ b/components/member-list.js @@ -1,5 +1,4 @@ import { html, Component } from "../lib/index.js"; -import { getNickURL } from "../state.js"; import { strip as stripANSI } from "../lib/ansi.js"; import Membership from "./membership.js"; import * as irc from "../lib/irc.js"; @@ -73,7 +72,7 @@ class MemberItem extends Component { return html` <li> <a - href=${getNickURL(this.props.nick)} + href=${irc.formatURL({ entity: this.props.nick, enttype: "user" })} class=${classes.join(" ")} title=${title} onClick=${this.handleClick} @@ -839,6 +839,17 @@ export function parseURL(str) { return { host, enttype, entity }; } +export function formatURL({ host, enttype, entity } = {}) { + host = host || ""; + entity = entity || ""; + + let s = "irc://" + host + "/" + encodeURIComponent(entity); + if (enttype) { + s += ",is" + enttype; + } + return s; +} + export class CapRegistry { available = new Map(); enabled = new Set(); @@ -43,22 +43,14 @@ export const BufferEventsDisplayMode = { export const SettingsContext = createContext("settings"); -export function getNickURL(nick) { - return "irc:///" + encodeURIComponent(nick) + ",isuser"; -} - -export function getChannelURL(channel) { - return "irc:///" + encodeURIComponent(channel); -} - export function getBufferURL(buf) { switch (buf.type) { case BufferType.SERVER: - return "irc:///"; + return irc.formatURL(); case BufferType.CHANNEL: - return getChannelURL(buf.name); + return irc.formatURL({ entity: buf.name }); case BufferType.NICK: - return getNickURL(buf.name); + return irc.formatURL({ entity: buf.name, enttype: "user" }); } throw new Error("Unknown buffer type: " + buf.type); } |