1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-12 21:52:40 +01:00

Stop returning defaults when using getPublicUser()

This commit is contained in:
TomatoCake 2024-09-01 18:44:35 +02:00
parent 143cbf2e98
commit 269d4eecdd
5 changed files with 16 additions and 13 deletions

View File

@ -1,17 +1,17 @@
/* /*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors Copyright (C) 2023 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify 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 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 by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
@ -84,7 +84,7 @@ router.post(
}).save(); }).save();
const data = invite.toJSON(); 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.guild = await Guild.findOne({ where: { id: guild_id } });
data.channel = channel; data.channel = channel;

View File

@ -41,7 +41,10 @@ router.get(
const { guild_id, with_mutual_guilds } = req.query; const { guild_id, with_mutual_guilds } = req.query;
const user = await User.getPublicUser(req.params.id, { const user = await User.findOneOrFail({
where: {
id: req.params.id,
},
relations: ["connected_accounts"], relations: ["connected_accounts"],
}); });

View File

@ -87,7 +87,9 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
} }
if (opts.author_id) { 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); const rights = await getRights(opts.author_id);
rights.hasThrow("SEND_MESSAGES"); rights.hasThrow("SEND_MESSAGES");
} }

View File

@ -238,7 +238,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
if (session?.status == "unknown") session.status = "online"; 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, { return Send(this, {
op: OPCODES.Dispatch, op: OPCODES.Dispatch,

View File

@ -279,14 +279,12 @@ export class User extends BaseClass {
return user as UserPrivate; return user as UserPrivate;
} }
static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) { static async getPublicUser(user_id: string): Promise<PublicUser> {
return await User.findOneOrFail({ const user = await User.findOneOrFail({
where: { id: user_id }, where: { id: user_id },
...opts, select: PublicUserProjection,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
select: [...PublicUserProjection, ...(opts?.select || [])], // TODO: fix
}); });
return user.toPublicUser();
} }
public static async generateDiscriminator( public static async generateDiscriminator(