forked from CringeStudios/gamja
lib/irc: extend parseURL to support flags and skip auth + options
This commit is contained in:
parent
a313363ed7
commit
49a59077b7
@ -909,11 +909,11 @@ export default class App extends Component {
|
|||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
let buf = State.getBuffer(this.state, { server: serverID, name: url.channel || SERVER_BUFFER });
|
let buf = State.getBuffer(this.state, { server: serverID, name: url.entity || SERVER_BUFFER });
|
||||||
if (buf) {
|
if (buf) {
|
||||||
this.switchBuffer(buf.id);
|
this.switchBuffer(buf.id);
|
||||||
} else {
|
} else {
|
||||||
this.open(url.channel, serverID);
|
this.open(url.entity, serverID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
58
lib/irc.js
58
lib/irc.js
@ -648,6 +648,8 @@ export function forEachChannelModeUpdate(msg, isupport, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Check if a realname is worth displaying.
|
||||||
|
*
|
||||||
* Since the realname is mandatory, many clients set a meaningless realname.
|
* Since the realname is mandatory, many clients set a meaningless realname.
|
||||||
*/
|
*/
|
||||||
export function isMeaningfulRealname(realname, nick) {
|
export function isMeaningfulRealname(realname, nick) {
|
||||||
@ -664,26 +666,60 @@ export function isMeaningfulRealname(realname, nick) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parse an irc:// URL.
|
||||||
|
*
|
||||||
|
* See: https://datatracker.ietf.org/doc/html/draft-butcher-irc-url-04
|
||||||
|
*/
|
||||||
export function parseURL(str) {
|
export function parseURL(str) {
|
||||||
if (!str.startsWith("irc://") && !str.startsWith("ircs://")) {
|
if (!str.startsWith("irc://") && !str.startsWith("ircs://")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = str.slice(str.indexOf(":") + 3);
|
str = str.slice(str.indexOf(":") + "://".length);
|
||||||
|
|
||||||
|
let loc;
|
||||||
let i = str.indexOf("/");
|
let i = str.indexOf("/");
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
return { host: str };
|
loc = str;
|
||||||
}
|
str = "";
|
||||||
|
} else {
|
||||||
let host = str.slice(0, i);
|
loc = str.slice(0, i);
|
||||||
str = str.slice(i + 1);
|
str = str.slice(i + 1);
|
||||||
|
|
||||||
// TODO: handle URLs with query params
|
|
||||||
let channel = null;
|
|
||||||
if (str.startsWith("#")) {
|
|
||||||
channel = str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { host, channel };
|
let host = loc;
|
||||||
|
i = loc.indexOf("@");
|
||||||
|
if (i >= 0) {
|
||||||
|
host = loc.slice(i + 1);
|
||||||
|
// TODO: parse authinfo
|
||||||
|
}
|
||||||
|
|
||||||
|
i = str.indexOf("?");
|
||||||
|
if (i >= 0) {
|
||||||
|
str = str.slice(0, i);
|
||||||
|
// TODO: parse options
|
||||||
|
}
|
||||||
|
|
||||||
|
let enttype;
|
||||||
|
i = str.indexOf(",");
|
||||||
|
if (i >= 0) {
|
||||||
|
let flags = str.slice(i + 1).split(",");
|
||||||
|
str = str.slice(0, i);
|
||||||
|
|
||||||
|
if (flags.indexOf("isuser") >= 0) {
|
||||||
|
enttype = "user";
|
||||||
|
} else if (flags.indexOf("ischannel") >= 0) {
|
||||||
|
enttype = "channel";
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: parse hosttype
|
||||||
|
}
|
||||||
|
|
||||||
|
let entity = decodeURIComponent(str);
|
||||||
|
if (!enttype) {
|
||||||
|
// TODO: technically we should use the PREFIX ISUPPORT here
|
||||||
|
enttype = entity.startsWith("#") ? "channel" : "user";
|
||||||
|
}
|
||||||
|
|
||||||
|
return { host, enttype, entity };
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user