IRC_Client/state.js

73 lines
1.4 KiB
JavaScript
Raw Normal View History

import Client from "./lib/client.js";
2021-01-22 18:29:22 +01:00
2020-07-13 17:22:24 +02:00
export const SERVER_BUFFER = "*";
2020-06-26 10:35:38 +02:00
export const BufferType = {
SERVER: "server",
CHANNEL: "channel",
NICK: "nick",
};
2020-06-24 16:56:28 +02:00
2021-01-22 18:29:22 +01:00
export const NetworkStatus = Client.Status;
2020-06-24 16:56:28 +02:00
export const Unread = {
NONE: "",
MESSAGE: "message",
2020-06-29 11:08:47 +02:00
HIGHLIGHT: "highlight",
2020-06-24 16:56:28 +02:00
2021-05-27 22:35:41 +02:00
union(a, b) {
2020-06-24 16:56:28 +02:00
const priority = {
2021-05-27 22:35:41 +02:00
[Unread.NONE]: 0,
2020-06-24 16:56:28 +02:00
[Unread.MESSAGE]: 1,
2020-06-29 11:08:47 +02:00
[Unread.HIGHLIGHT]: 2,
2020-06-24 16:56:28 +02:00
};
return (priority[a] > priority[b]) ? a : b;
},
};
2020-07-15 18:47:33 +02:00
2020-07-23 09:58:05 +02:00
export const ReceiptType = {
DELIVERED: "delivered",
READ: "read",
};
2020-07-15 18:47:33 +02:00
export function getNickURL(nick) {
return "irc:///" + encodeURIComponent(nick) + ",isuser";
2020-07-15 18:47:33 +02:00
}
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);
2020-07-21 14:48:04 +02:00
if (msg.tags.msgid) {
return bufURL + "?msgid=" + encodeURIComponent(msg.tags.msgid);
2020-07-21 14:48:04 +02:00
} else {
return bufURL + "?timestamp=" + encodeURIComponent(msg.tags.time);
2020-07-21 14:48:04 +02:00
}
2020-07-15 18:47:33 +02:00
}
export function getNetworkName(network, bouncerNetwork, isBouncer) {
if (bouncerNetwork && bouncerNetwork.name) {
return bouncerNetwork.name;
}
if (isBouncer) {
return "bouncer";
}
var netName = network.isupport.get("NETWORK");
if (netName) {
return netName;
}
return "server";
}