gamja/state.js
Simon Ser 811984878c Switch to query params for msgid/timestamp in irc:// URLs
The hash is confusing because channels often start with a # too.
Instead, use a query parameter. This is consistent with [1], which
uses query params for the channel key.

[1]: https://datatracker.ietf.org/doc/html/draft-butcher-irc-url-04
2021-05-25 12:46:00 +02:00

56 lines
1.1 KiB
JavaScript

import Client from "./lib/client.js";
export const SERVER_BUFFER = "*";
export const BufferType = {
SERVER: "server",
CHANNEL: "channel",
NICK: "nick",
};
export const NetworkStatus = Client.Status;
export const Unread = {
NONE: "",
MESSAGE: "message",
HIGHLIGHT: "highlight",
union: (a, b) => {
const priority = {
[Unread.None]: 0,
[Unread.MESSAGE]: 1,
[Unread.HIGHLIGHT]: 2,
};
return (priority[a] > priority[b]) ? a : b;
},
};
export const ReceiptType = {
DELIVERED: "delivered",
READ: "read",
};
export function getNickURL(nick) {
return "irc:///" + encodeURIComponent(nick) + ",isuser";
}
export function getBufferURL(buf) {
switch (buf.type) {
case BufferType.SERVER:
return "irc:///";
case BufferType.CHANNEL:
return "irc:///" + encodeURIComponent(buf.name);
case BufferType.NICK:
return getNickURL(buf.name);
}
throw new Error("Unknown buffer type: " + buf.type);
}
export function getMessageURL(buf, msg) {
var bufURL = getBufferURL(buf);
if (msg.tags.msgid) {
return bufURL + "?msgid=" + encodeURIComponent(msg.tags.msgid);
} else {
return bufURL + "?timestamp=" + encodeURIComponent(msg.tags.time);
}
}