diff --git a/lib/actions.ts b/lib/actions.ts index 4112fc3..9756845 100644 --- a/lib/actions.ts +++ b/lib/actions.ts @@ -18,6 +18,7 @@ import { AccountInfo, AccountStrike, Bot, + Channel, File, Member, Message, @@ -281,10 +282,7 @@ export async function suspendUser(userId: string) { } } -export async function updateUserBadges( - userId: string, - badges: number -): Promise<{ updatePublished: boolean }> { +export async function updateUserBadges(userId: string, badges: number) { await checkPermission("users/update/badges", userId, { badges }); await mongo().db("revolt").collection("users").updateOne( { @@ -297,23 +295,22 @@ export async function updateUserBadges( } ); - 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 }; - } + const memberships = await mongo() + .db("revolt") + .collection<{ _id: { user: string; server: string } }>("server_members") + .find({ "_id.user": userId }) + .toArray(); - return { updatePublished: true }; + for (const topic of [userId, ...memberships.map((x) => x._id.server)]) { + await publishMessage(topic, { + type: "UserUpdate", + id: userId, + data: { + badges, + }, + clear: [], + }); + } } export async function wipeUser(userId: string, flags = 4) { @@ -321,16 +318,39 @@ export async function wipeUser(userId: string, flags = 4) { await checkPermission("users/action/wipe", userId, { flags }); + const user = await mongo() + .db("revolt") + .collection("users") + .findOne({ _id: userId }); + + const messages = await mongo() + .db("revolt") + .collection("messages") + .find({ author: userId }, { sort: { _id: -1 } }) + .toArray(); + + const dms = await mongo() + .db("revolt") + .collection("channels") + .find({ + channel_type: "DirectMessage", + recipients: userId, + }) + .toArray(); + + const memberships = await mongo() + .db("revolt") + .collection<{ _id: { user: string; server: string } }>("server_members") + .find({ "_id.user": userId }) + .toArray(); + // retrieve messages, dm channels, relationships, server memberships const backup = { _event: "wipe", - user: await fetchUserById(userId), - messages: await fetchMessages({ author: userId }, undefined), - dms: await fetchChannels({ - channel_type: "DirectMessage", - recipients: userId, - }), - memberships: await fetchMembershipsByUser(userId), + user, + messages, + dms, + memberships, }; await writeFile(