Merge remote-tracking branch 'DEVTomatoCake/fix/getPublicUser-no-defaults'

This commit is contained in:
Rory&
2025-12-17 11:28:29 +01:00
8 changed files with 21 additions and 18 deletions
@@ -1,17 +1,17 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 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/>.
*/
@@ -72,7 +72,7 @@ router.post(
}).save();
const data = invite.toJSON();
data.inviter = (await User.getPublicUser(req.user_id)).toPublicUser();
data.inviter = await User.getPublicUser(req.user_id);
data.guild = await Guild.findOne({ where: { id: guild_id } });
data.channel = channel;
+3 -3
View File
@@ -20,7 +20,7 @@ import { route } from "@spacebar/api";
import { Ban, DiscordApiErrors, GuildBanAddEvent, GuildBanRemoveEvent, Member, User, emitEvent } from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
import { APIBansArray, BanCreateSchema, BanRegistrySchema, GuildBansResponse } from "@spacebar/schemas";
import { APIBansArray, BanCreateSchema, BanRegistrySchema, GuildBansResponse, PublicUser } from "@spacebar/schemas";
const router: Router = Router({ mergeParams: true });
@@ -43,7 +43,7 @@ router.get(
const { guild_id } = req.params;
let bans = await Ban.find({ where: { guild_id: guild_id } });
const promisesToAwait: Promise<User>[] = [];
const promisesToAwait: Promise<PublicUser>[] = [];
const bansObj: APIBansArray = [];
bans = bans.filter((ban) => ban.user_id !== ban.executor_id); // pretend self-bans don't exist to prevent victim chasing
@@ -236,7 +236,7 @@ router.put(
event: "GUILD_BAN_ADD",
data: {
guild_id: guild_id,
user: banned_user.toPublicUser(),
user: banned_user,
delete_message_secs: Math.floor(deleteMessagesMs / 1000),
},
guild_id: guild_id,
+1 -1
View File
@@ -94,7 +94,7 @@ router.post(
event: "GUILD_BAN_ADD",
data: {
guild_id: guild_id,
user: banned_user.toPublicUser(),
user: banned_user,
},
guild_id: guild_id,
} as GuildBanAddEvent),
+4 -1
View File
@@ -29,7 +29,10 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
const { guild_id, with_mutual_guilds, with_mutual_friends, with_mutual_friends_count } = req.query;
const user = await User.getPublicUser(req.params.user_id, {
const user = await User.findOneOrFail({
where: {
id: req.params.id,
},
relations: ["connected_accounts"],
});
+3 -1
View File
@@ -158,7 +158,9 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
}
if (opts.author_id) {
message.author = await User.getPublicUser(opts.author_id);
message.author = await User.findOneOrFail({
where: { id: opts.author_id },
});
const rights = await getRights(opts.author_id);
rights.hasThrow("SEND_MESSAGES");
}
+1 -1
View File
@@ -192,7 +192,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (session?.status == "unknown") session.status = "online";
const user = (await User.getPublicUser(x)).toPublicUser(); // why is this needed?
const user = await User.getPublicUser(x);
return Send(this, {
op: OPCODES.Dispatch,
+1 -1
View File
@@ -378,7 +378,7 @@ export class Member extends BaseClassWithoutId {
event: "GUILD_MEMBER_ADD",
data: {
...member,
user: user.toPublicUser(),
user: user,
guild_id,
},
guild_id,
+4 -6
View File
@@ -206,14 +206,12 @@ export class User extends BaseClass {
return user as UserPrivate;
}
static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) {
return await User.findOneOrFail({
static async getPublicUser(user_id: string): Promise<PublicUser> {
const user = await User.findOneOrFail({
where: { id: user_id },
...opts,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
select: [...PublicUserProjection, ...(opts?.select || [])], // TODO: fix
select: PublicUserProjection,
});
return user.toPublicUser();
}
public static async generateDiscriminator(username: string): Promise<string | undefined> {