1
0
Fork 0

don't error if publishing badge update failed

dufisgsd
Lea 2023-08-09 21:01:38 +02:00
parent 19465043a1
commit 2522cfe6de
Signed by: lea
GPG Key ID: 1BAFFE8347019C42
2 changed files with 21 additions and 12 deletions

View File

@ -75,10 +75,13 @@ export function UserActions({ user, bot }: { user: User; bot?: Bot }) {
const badges =
(decodeTime(user._id) < 1629638578431 ? 256 : 0) |
((userDraft.badges ?? 0) ^ badge);
await updateUserBadges(user._id, badges);
const result = await updateUserBadges(user._id, badges);
setUserDraft((user) => ({ ...user!, badges }));
toast({
title: "Updated user badges",
description: result.updatePublished
? undefined
: "Failed to publish event, users will need to reload to see the change",
});
} catch (err) {
toast({

View File

@ -225,7 +225,7 @@ export async function suspendUser(userId: string) {
}
}
export async function updateUserBadges(userId: string, badges: number) {
export async function updateUserBadges(userId: string, badges: number): Promise<{ updatePublished: boolean }> {
await checkPermission("users/update/badges", userId, { badges });
await mongo().db("revolt").collection<User>("users").updateOne(
{
@ -238,17 +238,23 @@ export async function updateUserBadges(userId: string, badges: number) {
}
);
const memberships = await fetchMembershipsByUser(userId);
for (const topic of [userId, ...memberships.map((x) => x._id.server)]) {
await publishMessage(topic, {
type: "UserUpdate",
id: userId,
data: {
badges,
},
clear: [],
});
try {
const memberships = await fetchMembershipsByUser(userId);
for (const topic of [userId, ...memberships.map((x) => x._id.server)]) {
await publishMessage(topic, {
type: "UserUpdate",
id: userId,
data: {
badges,
},
clear: [],
});
}
} catch(e) {
return { updatePublished: false };
}
return { updatePublished: true };
}
export async function wipeUser(userId: string, flags = 4) {