Clean up some schemas

This commit is contained in:
Rory&
2026-08-08 06:53:15 +02:00
parent 580d438c3a
commit fc086ddcea
32 changed files with 143 additions and 71 deletions
Binary file not shown.
Binary file not shown.
+5 -1
View File
@@ -68,7 +68,11 @@ router.patch(
relations: { settings: true },
});
if (!user.settings) user.settings = UserSettings.create<UserSettings>(body);
if (!user.settings)
user.settings = UserSettings.create<UserSettings>({
...body,
friend_source_flags: body.friend_source_flags ?? { all: true },
});
else user.settings.assign(body);
if (body.guild_folders) user.settings.guild_folders = body.guild_folders;
+2 -2
View File
@@ -18,7 +18,7 @@
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm";
import { arrayRemove } from "@spacebar/extensions";
import { Config, GuildWelcomeScreen, Snowflake, handleFile } from "@spacebar/util";
import { Config, Snowflake, handleFile } from "@spacebar/util";
import { Ban } from "./Ban";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
@@ -31,7 +31,7 @@ import { Template } from "./Template";
import { User } from "./User";
import { VoiceState } from "./VoiceState";
import { Webhook } from "./Webhook";
import { DiscoverableGuild, IntegrationGuild } from "@spacebar/schemas";
import { DiscoverableGuild, GuildWelcomeScreen, IntegrationGuild } from "@spacebar/schemas";
import { Categories } from "@spacebar/database";
// TODO: application_command_count, application_command_counts: {1: 0, 2: 0, 3: 0}
// TODO: guild_scheduled_events
+3 -2
View File
@@ -19,10 +19,11 @@
import crypto from "node:crypto";
import { Column, CreateDateColumn, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm";
import { DateBuilder, TimeSpan, Random } from "@spacebar/extensions";
import { ClientStatus, PrivateStatus } from "@spacebar/schemas";
import { IpDataClient } from "@spacebar/util/util/networking";
import { Activity, GatewaySession, GatewaySessionClientInfo } from "../../util/interfaces";
import { User } from "./User";
import { BaseClassWithoutId } from "./BaseClass";
import { Activity, ClientStatus, GatewaySession, GatewaySessionClientInfo, PrivateStatus } from "../../util/interfaces";
import { IpDataClient } from "@spacebar/util/util/networking";
@Entity({
name: "sessions",
+1 -1
View File
@@ -118,7 +118,7 @@ export class UserSettings extends BaseClassWithoutId {
stream_notifications_enabled: boolean = false;
@Column({ nullable: true })
theme: "dark" | "light" = "dark"; // dark
theme: "dark" | "light" | "darker" | "midnight" = "dark"; // dark
@Column({ nullable: true })
timezone_offset: number = 0; // e.g -60
+2 -2
View File
@@ -18,8 +18,8 @@
import { Session, User } from "@spacebar/database";
import { WebSocket, Payload } from "@spacebar/gateway";
import { emitEvent, InternalStatusOrder, PresenceUpdateEvent, PrivateStatus } from "@spacebar/util";
import { ActivitySchema } from "@spacebar/schemas";
import { emitEvent, PresenceUpdateEvent } from "@spacebar/util";
import { ActivitySchema, InternalStatusOrder, PrivateStatus } from "@spacebar/schemas";
import { check } from "./instanceOf";
export async function onPresenceUpdate(this: WebSocket, { d }: Payload) {
+1
View File
@@ -17,6 +17,7 @@
*/
export * from "./AuditLog";
export * from "./Automod";
export * from "./Emoji";
export * from "./GuildProfileResponse";
export * from "./GuildSchema";
export * from "./Role";
+1
View File
@@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export * from "./Attachments";
export * from "./Components";
export * from "./Embeds";
export * from "./Message";
@@ -16,8 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { PublicAttachment } from "@spacebar/schemas/api/messages/Attachments";
import { MessageReferenceIds } from "@spacebar/schemas";
import { MessageReferenceIds, PublicAttachment } from "@spacebar/schemas";
export interface AttachmentListResponse {
items: {
+5 -4
View File
@@ -16,7 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//TODO: remove entity import
import { ConnectedAccount } from "@spacebar/database";
export type PublicConnectedAccount = Pick<ConnectedAccount, "name" | "type" | "verified">;
export interface PublicConnectedAccount {
name: string;
type: string;
verified?: boolean;
}
+1 -3
View File
@@ -16,9 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { ActivitySchema, Snowflake } from "@spacebar/schemas";
// TODO: remove entity import
import { ClientStatus } from "@spacebar/util";
import { ActivitySchema, ClientStatus, Snowflake } from "@spacebar/schemas";
export type SessionsLogoutSchema = { session_ids?: Snowflake[]; session_id_hashes?: string[] };
export type GetSessionsResponse = { user_sessions: DeviceInfo[] };
+15 -5
View File
@@ -16,11 +16,17 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Snowflake } from "@spacebar/schemas";
export type UserSettingsUpdateSchema = Partial<UserSettingsSchema>;
export interface UserSettingsSchema {
activity_restricted_guild_ids: Snowflake[];
activity_joining_restricted_guild_ids: Snowflake[];
afk_timeout: number;
allow_accessibility_detection: boolean;
allow_activity_party_privacy_friends: boolean;
allow_activity_party_privacy_voice_channel: boolean;
animate_emoji: boolean;
animate_stickers: number;
contact_sync_enabled: boolean;
@@ -33,24 +39,26 @@ export interface UserSettingsSchema {
enable_tts_command: boolean;
explicit_content_filter: number;
friend_discovery_flags: number;
friend_source_flags: FriendSourceFlags;
gateway_connected: boolean;
friend_source_flags: FriendSourceFlags | null;
gif_auto_play: boolean;
guild_folders: GuildFolder[]; // every top guild is displayed as a "folder"
guild_positions: string[]; // guild ids ordered by position
inline_attachment_media: boolean;
inline_embed_media: boolean;
locale: string; // en_US
message_display_compact: boolean;
native_phone_integration_enabled: boolean;
passwordless: boolean;
render_embeds: boolean;
render_reactions: boolean;
restricted_guilds: string[];
show_current_game: boolean;
slayer_sdk_receive_dms_in_game: number;
soundboard_volume: number;
status: "online" | "offline" | "dnd" | "idle" | "invisible";
stream_notifications_enabled: boolean;
theme: "dark" | "light"; // dark
theme: "dark" | "light" | "darker" | "midnight"; // dark
timezone_offset: number; // e.g -60
view_nsfw_commands: boolean;
view_nsfw_guilds: boolean;
}
@@ -69,5 +77,7 @@ export interface GuildFolder {
}
export interface FriendSourceFlags {
all: boolean;
all?: boolean;
mutual_friends?: boolean;
mutual_guilds?: boolean;
}
+2 -1
View File
@@ -19,6 +19,7 @@
export * from "./ConnectedAccount";
export * from "./InstanceUserDeleteSchema";
export * from "./Member";
export * from "./SessionsSchemas";
export * from "./Status";
export * from "./User";
export * from "./UserSettings";
export * from "./SessionsSchemas";
@@ -16,8 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Snowflake, StickerResponse } from "@spacebar/schemas";
import { EmojiResponse } from "@spacebar/schemas/api/guilds/Emoji";
import { EmojiResponse, Snowflake, StickerResponse } from "@spacebar/schemas";
export interface DiscoverableGuildsResponse {
total: number;
+1 -3
View File
@@ -16,9 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// TODO: remove import from util
import { GuildWelcomeScreen } from "@spacebar/util";
import { GuildUpdateSchema } from "@spacebar/schemas";
import { GuildUpdateSchema, GuildWelcomeScreen } from "@spacebar/schemas";
export interface GuildCreateResponse extends Omit<GuildUpdateSchema, "name"> {
id: string;
@@ -16,10 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// TODO: remove dependency on entities
import { Role } from "@spacebar/database";
import { BaseMessageComponents, Embed, MessageType, Poll, PublicUser, RoleResponse } from "@spacebar/schemas";
import { PublicAttachment } from "../api/messages/Attachments";
import { BaseMessageComponents, Embed, MessageType, Poll, PublicUser, RoleResponse, PublicAttachment } from "@spacebar/schemas";
export interface GuildMessagesSearchMessage {
id: string;
@@ -0,0 +1,28 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2026 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export interface GuildWelcomeScreen {
enabled: boolean;
description: string;
welcome_channels: {
description: string;
emoji_id?: string;
emoji_name?: string;
channel_id: string;
}[];
}
@@ -16,8 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// TODO: remove util import
import { ClientStatus } from "@spacebar/util";
import { ClientStatus } from "@spacebar/schemas/api/users/Status";
export interface GuildWidgetJsonResponse {
id: string;
@@ -26,7 +26,21 @@ export interface HubDirectoryEntry {
directory_channel_id: string;
guild: Guild;
primary_category_id: number;
type: number; // TODO: not exactly sure what this is, channel type?
type: HubDirectoryEntryType;
}
export enum HubDirectoryEntryType {
GUILD = 0,
GUILD_SCHEDULED_EVENT = 1,
}
export enum HubDirectoryCategory {
UNCATEGORIZED = 0,
SCHOOL_CLUB = 1,
CLASS = 2,
STUDY_SOCIAL = 3,
SUBJECT_MAJOR = 4,
MISC = 5,
}
export type HubDirectoryEntriesResponse = HubDirectoryEntry[];
@@ -16,8 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { GuildCreateResponse, RoleResponse, StickerResponse } from "@spacebar/schemas";
import { EmojiResponse } from "@spacebar/schemas/api/guilds/Emoji";
import { GuildCreateResponse, RoleResponse, StickerResponse, EmojiResponse } from "@spacebar/schemas";
export interface MemberJoinGuildResponse {
guild: GuildCreateResponse;
+14 -1
View File
@@ -17,6 +17,19 @@
*/
// TODO: remove entity import
import { Team } from "@spacebar/database";
import { Snowflake } from "@spacebar/schemas";
export interface Team {
id: Snowflake;
name: string;
icon: string | null;
owner_user_id: Snowflake;
// members?: TeamMember[]; // TODO: only in application object
// TODO: only on Get/List Team(s) w/ include_payout_account_status=true
// payout_account_status?: TeamPayoutAccountStatus | null;
// payout_account_statuses?: TeamPayoutAccount[];
// TODO: Get Team only
// stripe_connect_account_id?: string;
}
export type TeamListResponse = Team[];
+2 -3
View File
@@ -16,12 +16,11 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// TODO: remove dependency on entities
import { BackupCode, UserSettings } from "@spacebar/database";
import { BackupCode, UserSettingsSchema } from "@spacebar/schemas";
export interface TokenResponse {
token: string;
settings: UserSettings;
settings: UserSettingsSchema;
}
export interface TokenOnlyResponse {
+1 -1
View File
@@ -20,7 +20,7 @@
import { GeneralConfiguration, LimitsConfiguration } from "../../util/config/types";
import { DmChannelDTO } from "../../util/dtos";
// TODO: remove entity imports
import { Application, BackupCode, Categories, Channel, Guild, Invite, Member, Template, Webhook } from "@spacebar/database";
import { Application, Categories, Channel, Guild, Invite, Template } from "@spacebar/database";
import { GuildCreateResponse, PrivateUser, PublicUser } from "@spacebar/schemas";
// TODO: remove this entire file!
+33 -13
View File
@@ -1,6 +1,6 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors
Copyright (C) 2026 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
@@ -16,20 +16,40 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// TODO: remove entity imports
import { Badge, Member, User } from "@spacebar/database";
import { PublicConnectedAccount, PublicMember, PublicUser } from "@spacebar/schemas";
import { EmojiResponse, PublicConnectedAccount, PublicMember, PublicUser, Snowflake } from "@spacebar/schemas";
export type MutualGuild = {
export interface ProfileBadge {
id: string;
description: string;
icon: string;
link?: string;
}
export interface MutualGuild {
id: string;
nick?: string;
};
}
export type PublicMemberProfile = Pick<Member, "banner" | "bio" | "guild_id"> & {
accent_color: null; // TODO
};
export interface ProfileMetadataResponse {
pronouns: string;
bio?: string;
banner?: string | null;
accent_color?: number | null;
theme_colors?: [number, number] | null;
popout_animation_particle_type?: Snowflake | null;
emoji?: EmojiResponse | null;
profile_effect?: ProfileEffect | null;
}
export type UserProfile = Pick<User, "bio" | "accent_color" | "banner" | "pronouns" | "theme_colors">;
export interface GuildProfileMetadataResponse extends ProfileMetadataResponse {
guild_id: Snowflake;
accent_color?: null; // ignored by clients
}
export interface ProfileEffect {
id: Snowflake;
expires_at: number | null;
}
export interface UserProfileResponse {
user: PublicUser;
@@ -39,8 +59,8 @@ export interface UserProfileResponse {
mutual_guilds: MutualGuild[];
premium_type: number;
profile_themes_experiment_bucket: number;
user_profile: UserProfile;
user_profile: ProfileMetadataResponse;
guild_member?: PublicMember;
guild_member_profile?: PublicMemberProfile;
badges: Badge[];
guild_member_profile?: GuildProfileMetadataResponse;
badges: ProfileBadge[];
}
+1
View File
@@ -39,6 +39,7 @@ export * from "./GuildPruneResponse";
export * from "./GuildRecommendationsResponse";
export * from "./GuildVanityUrl";
export * from "./GuildVoiceRegionsResponse";
export * from "./GuildWelcomeScreen";
export * from "./GuildWidgetJsonResponse";
export * from "./GuildWidgetSettingsResponse";
export * from "./HubDirectoryEntriesResponse";
+2 -2
View File
@@ -16,8 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// TODO: remove entity imports
import { Activity, ClientStatus, SetPrivateStatus, Status } from "@spacebar/util";
import { ClientStatus, SetPrivateStatus } from "@spacebar/schemas";
import { Activity } from "@spacebar/util";
export const ActivitySchema = {
$afk: Boolean,
+2 -1
View File
@@ -17,7 +17,7 @@
*/
import { ConnectedAccount, Invite, Role, Emoji, Channel, User, Sticker, UserSettings, ReadState, ThreadMember } from "@spacebar/database";
import { Activity, Presence, IReadyGuildDTO, ReadyUserGuildSettingsEntries, ReadyPrivateChannel, GuildOrUnavailable, Snowflake, PrivateStatus } from "@spacebar/util";
import { Activity, Presence, IReadyGuildDTO, ReadyUserGuildSettingsEntries, ReadyPrivateChannel, GuildOrUnavailable, Snowflake } from "@spacebar/util";
import { JsonValue } from "@protobuf-ts/runtime";
import {
ApplicationCommand,
@@ -25,6 +25,7 @@ import {
Interaction,
InteractionFailureReason,
PartialEmoji,
PrivateStatus,
PublicChannel,
PublicMember,
PublicMessage,
-10
View File
@@ -1,10 +0,0 @@
export interface GuildWelcomeScreen {
enabled: boolean;
description: string;
welcome_channels: {
description: string;
emoji_id?: string;
emoji_name?: string;
channel_id: string;
}[];
}
+1 -2
View File
@@ -16,9 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { ClientStatus, Status } from "./Status";
import { ClientStatus, Status, PublicUser } from "@spacebar/schemas";
import { Activity } from "./Activity";
import { PublicUser } from "@spacebar/schemas";
export interface Presence {
user: PublicUser;
-1
View File
@@ -21,4 +21,3 @@ export * from "./ConnectedAccount";
export * from "./Event";
export * from "./GuildWelcomeScreen";
export * from "./Presence";
export * from "./Status";