This commit is contained in:
Reto Brunner 2024-02-15 23:01:22 +01:00
commit 3eb19135f5
52 changed files with 185 additions and 102 deletions

98
shared/types/msg.ts Normal file
View file

@ -0,0 +1,98 @@
export enum MessageType {
UNHANDLED = "unhandled",
ACTION = "action",
AWAY = "away",
BACK = "back",
ERROR = "error",
INVITE = "invite",
JOIN = "join",
KICK = "kick",
LOGIN = "login",
LOGOUT = "logout",
MESSAGE = "message",
MODE = "mode",
MODE_CHANNEL = "mode_channel",
MODE_USER = "mode_user", // RPL_UMODEIS
MONOSPACE_BLOCK = "monospace_block",
NICK = "nick",
NOTICE = "notice",
PART = "part",
QUIT = "quit",
CTCP = "ctcp",
CTCP_REQUEST = "ctcp_request",
CHGHOST = "chghost",
TOPIC = "topic",
TOPIC_SET_BY = "topic_set_by",
WHOIS = "whois",
RAW = "raw",
PLUGIN = "plugin",
WALLOPS = "wallops",
}
export type SharedUser = {
modes: string[];
// Users in the channel have only one mode assigned
mode: string;
away: string;
nick: string;
lastMessage: number;
};
export type UserInMessage = Partial<SharedUser> & {
mode: string;
};
export type LinkPreview = {
type: string;
head: string;
body: string;
thumb: string;
size: number;
link: string; // Send original matched link to the client
shown?: boolean | null;
error?: string;
message?: string;
media?: string;
mediaType?: string;
maxSize?: number;
thumbActualUrl?: string;
};
export type SharedMsg = {
from?: UserInMessage;
id?: number;
previews?: LinkPreview[];
text?: string;
type?: MessageType;
self?: boolean;
time?: Date;
hostmask?: string;
target?: UserInMessage;
// TODO: new_nick is only on MessageType.NICK,
// we should probably make Msgs that extend this class and use those
// throughout. I'll leave any similar fields below.
new_nick?: string;
highlight?: boolean;
showInActive?: boolean;
new_ident?: string;
new_host?: string;
ctcpMessage?: string;
command?: string;
invitedYou?: boolean;
gecos?: string;
account?: boolean;
// these are all just for error:
error?: string;
nick?: string;
channel?: string;
reason?: string;
raw_modes?: any;
when?: Date;
whois?: any;
users?: UserInMessage[] | string[];
statusmsgGroup?: string;
params?: string[];
};

224
shared/types/socket-events.d.ts vendored Normal file
View file

@ -0,0 +1,224 @@
import {ClientMessage, ClientNetwork, InitClientChan} from "../../client/js/types";
import {Mention} from "../client";
import {ChanState} from "../models/chan";
import Msg from "../models/msg";
import Network from "../models/network";
import User from "../models/user";
import {ChangelogData} from "../plugins/changelog";
import {LinkPreview} from "../plugins/irc-events/link";
import {ClientConfiguration} from "../server";
type Session = {
current: boolean;
active: number;
lastUse: number;
ip: string;
agent: string;
token: string;
};
interface ServerToClientEvents {
"auth:failed": () => void;
"auth:start": (serverHash: number) => void;
"auth:success": () => void;
"upload:auth": (token: string) => void;
changelog: (data: ChangelogData) => void;
"changelog:newversion": () => void;
"channel:state": (data: {chan: number; state: ChanState}) => void;
"change-password": ({success, error}: {success: boolean; error?: any}) => void;
commands: (data: string[]) => void;
configuration: (config: ClientConfiguration) => void;
"push:issubscribed": (isSubscribed: boolean) => void;
"push:unregister": () => void;
"sessions:list": (data: Session[]) => void;
"mentions:list": (data: Mention[]) => void;
"setting:new": ({name: string, value: any}) => void;
"setting:all": (settings: {[key: string]: any}) => void;
"history:clear": ({target}: {target: number}) => void;
"mute:changed": (response: {target: number; status: boolean}) => void;
names: (data: {id: number; users: User[]}) => void;
network: (data: {networks: ClientNetwork[]}) => void;
"network:options": (data: {network: string; serverOptions: {[key: string]: any}}) => void;
"network:status": (data: {network: string; connected: boolean; secure: boolean}) => void;
"network:info": (data: {uuid: string}) => void;
"network:name": (data: {uuid: string; name: string}) => void;
nick: (data: {network: string; nick: string}) => void;
open: (id: number) => void;
part: (data: {chan: number}) => void;
"sign-out": () => void;
sync_sort: (
data:
| {
type: "networks";
order: string[];
target: string;
}
| {
type: "channels";
order: number[];
target: string;
}
) => void;
topic: (data: {chan: number; topic: string}) => void;
users: (data: {chan: number}) => void;
more: ({
chan,
messages,
totalMessages,
}: {
chan: number;
messages: Msg[];
totalMessages: number;
}) => void;
"msg:preview": ({id, chan, preview}: {id: number; chan: number; preview: LinkPreview}) => void;
"msg:special": (data: {chan: number; data?: Record<string, any>}) => void;
msg: (data: {msg: ClientMessage; chan: number; highlight?: number; unread?: number}) => void;
init: ({
active,
networks,
token,
}: {
active: number;
networks: ClientNetwork[];
token: string;
}) => void;
"search:results": (response: SearchResponse) => void;
quit: (args: {network: string}) => void;
error: (error: any) => void;
connecting: () => void;
join: (args: {
shouldOpen: boolean;
index: number;
network: string;
chan: InitClientChan;
}) => void;
}
interface ClientToServerEvents {
"auth:perform":
| (({user, password}: {user: string; password: string}) => void)
| (({
user,
token,
lastMessage,
openChannel,
hasConfig,
}: {
user: string;
token: string;
lastMessage: number;
openChannel: number | null;
hasConfig: boolean;
}) => void);
changelog: () => void;
"change-password": ({
old_password: string,
new_password: string,
verify_password: string,
}) => void;
open: (channelId: number) => void;
names: ({target: number}) => void;
input: ({target, text}: {target: number; text: string}) => void;
"upload:auth": () => void;
"upload:ping": (token: string) => void;
"mute:change": (response: {target: number; setMutedTo: boolean}) => void;
"push:register": (subscriptionJson: PushSubscriptionJSON) => void;
"push:unregister": () => void;
"setting:get": () => void;
"setting:set": ({name: string, value: any}) => void;
"sessions:get": () => void;
sort: ({type, order}: {type: string; order: any; target?: string}) => void;
"mentions:dismiss": (msgId: number) => void;
"mentions:dismiss_all": () => void;
"mentions:get": () => void;
more: ({
target,
lastId,
condensed,
}: {
target: number;
lastId: number;
condensed: boolean;
}) => void;
"msg:preview:toggle": ({
target,
messageIds,
msgId,
shown,
link,
}: {
target: number;
messageIds?: number[];
msgId?: number;
shown?: boolean | null;
link?: string;
}) => void;
"network:get": (uuid: string) => void;
"network:edit": (data: Record<string, any>) => void;
"network:new": (data: Record<string, any>) => void;
"sign-out": (token?: string) => void;
"history:clear": ({target}: {target: number}) => void;
search: ({
networkUuid,
channelName,
searchTerm,
offset,
}: {
networkUuid?: string;
channelName?: string;
searchTerm?: string;
offset: number;
}) => void;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface InterServerEvents {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface SocketData {}