gamja/state.js

57 lines
1.1 KiB
JavaScript
Raw Normal View History

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