Initial identify rewrite
This commit is contained in:
@@ -16,7 +16,46 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Channel, Emoji, Guild, Member, Role, Sticker } from "../entities";
|
||||
import {
|
||||
Channel,
|
||||
ChannelOverride,
|
||||
ChannelType,
|
||||
Emoji,
|
||||
Guild,
|
||||
Member,
|
||||
PublicUser,
|
||||
Role,
|
||||
Sticker,
|
||||
UserGuildSettings,
|
||||
} from "../entities";
|
||||
|
||||
// TODO: this is not the best place for this type
|
||||
export type ReadyUserGuildSettingsEntries = Omit<
|
||||
UserGuildSettings,
|
||||
"channel_overrides"
|
||||
> & {
|
||||
channel_overrides: (ChannelOverride & { channel_id: string })[];
|
||||
};
|
||||
|
||||
// TODO: probably should move somewhere else
|
||||
export interface ReadyPrivateChannel {
|
||||
id: string;
|
||||
flags: number;
|
||||
is_spam: boolean;
|
||||
last_message_id?: string;
|
||||
recipients: PublicUser[];
|
||||
type: ChannelType.DM | ChannelType.GROUP_DM;
|
||||
}
|
||||
|
||||
export type GuildOrUnavailable =
|
||||
| { id: string; unavailable: boolean }
|
||||
| (Guild & { joined_at?: Date; unavailable: boolean });
|
||||
|
||||
const guildIsAvailable = (
|
||||
guild: GuildOrUnavailable,
|
||||
): guild is Guild & { joined_at: Date; unavailable: false } => {
|
||||
return guild.unavailable == false;
|
||||
};
|
||||
|
||||
export interface IReadyGuildDTO {
|
||||
application_command_counts?: { 1: number; 2: number; 3: number }; // ????????????
|
||||
@@ -64,6 +103,8 @@ export interface IReadyGuildDTO {
|
||||
stickers: Sticker[];
|
||||
threads: unknown[];
|
||||
version: string;
|
||||
guild_hashes: unknown;
|
||||
unavailable: boolean;
|
||||
}
|
||||
|
||||
export class ReadyGuildDTO implements IReadyGuildDTO {
|
||||
@@ -112,8 +153,17 @@ export class ReadyGuildDTO implements IReadyGuildDTO {
|
||||
stickers: Sticker[];
|
||||
threads: unknown[];
|
||||
version: string;
|
||||
guild_hashes: unknown;
|
||||
unavailable: boolean;
|
||||
joined_at: Date;
|
||||
|
||||
constructor(guild: GuildOrUnavailable) {
|
||||
if (!guildIsAvailable(guild)) {
|
||||
this.id = guild.id;
|
||||
this.unavailable = true;
|
||||
return;
|
||||
}
|
||||
|
||||
constructor(guild: Guild) {
|
||||
this.application_command_counts = {
|
||||
1: 5,
|
||||
2: 2,
|
||||
@@ -163,6 +213,8 @@ export class ReadyGuildDTO implements IReadyGuildDTO {
|
||||
this.stickers = guild.stickers;
|
||||
this.threads = [];
|
||||
this.version = "1"; // ??????
|
||||
this.guild_hashes = {};
|
||||
this.joined_at = guild.joined_at;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
@@ -482,3 +482,10 @@ export enum ChannelPermissionOverwriteType {
|
||||
member = 1,
|
||||
group = 2,
|
||||
}
|
||||
|
||||
export interface DMChannel extends Omit<Channel, "type" | "recipients"> {
|
||||
type: ChannelType.DM | ChannelType.GROUP_DM;
|
||||
recipients: Recipient[];
|
||||
|
||||
// TODO: probably more props
|
||||
}
|
||||
|
||||
@@ -280,6 +280,15 @@ export class User extends BaseClass {
|
||||
return user as PublicUser;
|
||||
}
|
||||
|
||||
toPrivateUser() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const user: any = {};
|
||||
PrivateUserProjection.forEach((x) => {
|
||||
user[x] = this[x];
|
||||
});
|
||||
return user as UserPrivate;
|
||||
}
|
||||
|
||||
static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) {
|
||||
return await User.findOneOrFail({
|
||||
where: { id: user_id },
|
||||
|
||||
@@ -40,6 +40,9 @@ import {
|
||||
UserSettings,
|
||||
IReadyGuildDTO,
|
||||
ReadState,
|
||||
UserPrivate,
|
||||
ReadyUserGuildSettingsEntries,
|
||||
ReadyPrivateChannel,
|
||||
} from "@fosscord/util";
|
||||
|
||||
export interface Event {
|
||||
@@ -68,20 +71,8 @@ export interface PublicRelationship {
|
||||
|
||||
export interface ReadyEventData {
|
||||
v: number;
|
||||
user: PublicUser & {
|
||||
mobile: boolean;
|
||||
desktop: boolean;
|
||||
email: string | undefined;
|
||||
flags: string;
|
||||
mfa_enabled: boolean;
|
||||
nsfw_allowed: boolean;
|
||||
phone: string | undefined;
|
||||
premium: boolean;
|
||||
premium_type: number;
|
||||
verified: boolean;
|
||||
bot: boolean;
|
||||
};
|
||||
private_channels: Channel[]; // this will be empty for bots
|
||||
user: UserPrivate;
|
||||
private_channels: ReadyPrivateChannel[]; // this will be empty for bots
|
||||
session_id: string; // resuming
|
||||
guilds: IReadyGuildDTO[];
|
||||
analytics_token?: string;
|
||||
@@ -115,7 +106,7 @@ export interface ReadyEventData {
|
||||
version: number;
|
||||
};
|
||||
user_guild_settings?: {
|
||||
entries: UserGuildSettings[];
|
||||
entries: ReadyUserGuildSettingsEntries[];
|
||||
version: number;
|
||||
partial: boolean;
|
||||
};
|
||||
@@ -127,6 +118,16 @@ export interface ReadyEventData {
|
||||
// probably all users who the user is in contact with
|
||||
users?: PublicUser[];
|
||||
sessions: unknown[];
|
||||
api_code_version: number;
|
||||
tutorial: number | null;
|
||||
resume_gateway_url: string;
|
||||
session_type: string;
|
||||
required_action?:
|
||||
| "REQUIRE_VERIFIED_EMAIL"
|
||||
| "REQUIRE_VERIFIED_PHONE"
|
||||
| "REQUIRE_CAPTCHA" // TODO: allow these to be triggered
|
||||
| "TOS_UPDATE_ACKNOWLEDGMENT"
|
||||
| "AGREEMENTS";
|
||||
}
|
||||
|
||||
export interface ReadyEvent extends Event {
|
||||
|
||||
Reference in New Issue
Block a user