mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-22 12:13:48 +01:00
Stop using the name 'exist' if it's not for existence check
This commit is contained in:
parent
098ca8e622
commit
23ccb38e73
@ -147,11 +147,11 @@ export async function fetchPerson(
|
||||
}
|
||||
|
||||
//#region Returns if already registered with this server
|
||||
const exist = await Users.findOneBy({ uri });
|
||||
const user = await Users.findOneBy({ uri });
|
||||
|
||||
if (exist) {
|
||||
await uriPersonCache.set(uri, exist);
|
||||
return exist;
|
||||
if (user != null) {
|
||||
await uriPersonCache.set(uri, user);
|
||||
return user;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
@ -396,9 +396,9 @@ export async function updatePerson(
|
||||
}
|
||||
|
||||
//#region Already registered on this server?
|
||||
const exist = (await Users.findOneBy({ uri })) as IRemoteUser;
|
||||
const user = (await Users.findOneBy({ uri })) as IRemoteUser;
|
||||
|
||||
if (exist == null) {
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
//#endregion
|
||||
@ -416,17 +416,15 @@ export async function updatePerson(
|
||||
[person.icon, person.image].map((img) =>
|
||||
img == null
|
||||
? Promise.resolve(null)
|
||||
: resolveImage(exist, img).catch(() => null),
|
||||
: resolveImage(user, img).catch(() => null),
|
||||
),
|
||||
);
|
||||
|
||||
// Custom pictogram acquisition
|
||||
const emojis = await extractEmojis(person.tag || [], exist.host).catch(
|
||||
(e) => {
|
||||
logger.info(`extractEmojis: ${e}`);
|
||||
return [] as Emoji[];
|
||||
},
|
||||
);
|
||||
const emojis = await extractEmojis(person.tag || [], user.host).catch((e) => {
|
||||
logger.info(`extractEmojis: ${e}`);
|
||||
return [] as Emoji[];
|
||||
});
|
||||
|
||||
const emojiNames = emojis.map((emoji) => emoji.name);
|
||||
|
||||
@ -518,11 +516,11 @@ export async function updatePerson(
|
||||
}
|
||||
|
||||
// Update user
|
||||
await Users.update(exist.id, updates);
|
||||
await Users.update(user.id, updates);
|
||||
|
||||
if (person.publicKey) {
|
||||
await UserPublickeys.update(
|
||||
{ userId: exist.id },
|
||||
{ userId: user.id },
|
||||
{
|
||||
keyId: person.publicKey.id,
|
||||
keyPem: person.publicKey.publicKeyPem,
|
||||
@ -531,7 +529,7 @@ export async function updatePerson(
|
||||
}
|
||||
|
||||
await UserProfiles.update(
|
||||
{ userId: exist.id },
|
||||
{ userId: user.id },
|
||||
{
|
||||
url: url,
|
||||
fields,
|
||||
@ -543,15 +541,15 @@ export async function updatePerson(
|
||||
},
|
||||
);
|
||||
|
||||
publishInternalEvent("remoteUserUpdated", { id: exist.id });
|
||||
publishInternalEvent("remoteUserUpdated", { id: user.id });
|
||||
|
||||
// Hashtag Update
|
||||
updateUsertags(exist, tags);
|
||||
updateUsertags(user, tags);
|
||||
|
||||
// If the user in question is a follower, followers will also be updated.
|
||||
await Followings.update(
|
||||
{
|
||||
followerId: exist.id,
|
||||
followerId: user.id,
|
||||
},
|
||||
{
|
||||
followerSharedInbox:
|
||||
@ -560,7 +558,7 @@ export async function updatePerson(
|
||||
},
|
||||
);
|
||||
|
||||
await updateFeatured(exist.id, resolver).catch((err) => logger.error(err));
|
||||
await updateFeatured(user.id, resolver).catch((err) => logger.error(err));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -576,10 +574,10 @@ export async function resolvePerson(
|
||||
if (typeof uri !== "string") throw new Error("uri is not string");
|
||||
|
||||
//#region If already registered on this server, return it.
|
||||
const exist = await fetchPerson(uri);
|
||||
const user = await fetchPerson(uri);
|
||||
|
||||
if (exist) {
|
||||
return exist;
|
||||
if (user != null) {
|
||||
return user;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
|
@ -38,17 +38,17 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw new ApiError(meta.errors.noSuchPost);
|
||||
}
|
||||
|
||||
const exist = await GalleryLikes.findOneBy({
|
||||
const like = await GalleryLikes.findOneBy({
|
||||
postId: post.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exist == null) {
|
||||
if (like == null) {
|
||||
throw new ApiError(meta.errors.notLiked);
|
||||
}
|
||||
|
||||
// Delete like
|
||||
await GalleryLikes.delete(exist.id);
|
||||
await GalleryLikes.delete(like.id);
|
||||
|
||||
GalleryPosts.decrement({ id: post.id }, "likedCount", 1);
|
||||
});
|
||||
|
@ -56,18 +56,18 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
});
|
||||
|
||||
// Check not muting
|
||||
const exist = await Mutings.findOneBy({
|
||||
const muting = await Mutings.findOneBy({
|
||||
muterId: muter.id,
|
||||
muteeId: mutee.id,
|
||||
});
|
||||
|
||||
if (exist == null) {
|
||||
if (muting == null) {
|
||||
throw new ApiError(meta.errors.notMuting);
|
||||
}
|
||||
|
||||
// Delete mute
|
||||
await Mutings.delete({
|
||||
id: exist.id,
|
||||
id: muting.id,
|
||||
});
|
||||
|
||||
publishUserEvent(user.id, "unmute", mutee);
|
||||
|
@ -42,15 +42,15 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
});
|
||||
|
||||
// if already favorited
|
||||
const exist = await NoteFavorites.findOneBy({
|
||||
const favorite = await NoteFavorites.findOneBy({
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exist == null) {
|
||||
if (favorite == null) {
|
||||
throw new ApiError(meta.errors.notFavorited);
|
||||
}
|
||||
|
||||
// Delete favorite
|
||||
await NoteFavorites.delete(exist.id);
|
||||
await NoteFavorites.delete(favorite.id);
|
||||
});
|
||||
|
@ -38,17 +38,17 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw new ApiError(meta.errors.noSuchPage);
|
||||
}
|
||||
|
||||
const exist = await PageLikes.findOneBy({
|
||||
const like = await PageLikes.findOneBy({
|
||||
pageId: page.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exist == null) {
|
||||
if (like == null) {
|
||||
throw new ApiError(meta.errors.notLiked);
|
||||
}
|
||||
|
||||
// Delete like
|
||||
await PageLikes.delete(exist.id);
|
||||
await PageLikes.delete(like.id);
|
||||
|
||||
Pages.decrement({ id: page.id }, "likedCount", 1);
|
||||
});
|
||||
|
@ -45,18 +45,18 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
});
|
||||
|
||||
// Check not muting
|
||||
const exist = await RenoteMutings.findOneBy({
|
||||
const muting = await RenoteMutings.findOneBy({
|
||||
muterId: muter.id,
|
||||
muteeId: mutee.id,
|
||||
});
|
||||
|
||||
if (exist == null) {
|
||||
if (muting == null) {
|
||||
throw new ApiError(meta.errors.notMuting);
|
||||
}
|
||||
|
||||
// Delete mute
|
||||
await RenoteMutings.delete({
|
||||
id: exist.id,
|
||||
id: muting.id,
|
||||
});
|
||||
|
||||
// publishUserEvent(user.id, "unmute", mutee);
|
||||
|
@ -57,8 +57,7 @@ export const paramDef = {
|
||||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
// if already subscribed
|
||||
const exist = await SwSubscriptions.findOneBy({
|
||||
const subscription = await SwSubscriptions.findOneBy({
|
||||
userId: me.id,
|
||||
endpoint: ps.endpoint,
|
||||
auth: ps.auth,
|
||||
@ -67,13 +66,14 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
|
||||
const instance = await fetchMeta(true);
|
||||
|
||||
if (exist != null) {
|
||||
// if already subscribed
|
||||
if (subscription != null) {
|
||||
return {
|
||||
state: "already-subscribed" as const,
|
||||
key: instance.swPublicKey,
|
||||
userId: me.id,
|
||||
endpoint: exist.endpoint,
|
||||
sendReadMessage: exist.sendReadMessage,
|
||||
endpoint: subscription.endpoint,
|
||||
sendReadMessage: subscription.sendReadMessage,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -42,16 +42,16 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const exist = await SwSubscriptions.findOneBy({
|
||||
const subscription = await SwSubscriptions.findOneBy({
|
||||
userId: me.id,
|
||||
endpoint: ps.endpoint,
|
||||
});
|
||||
|
||||
if (exist != null) {
|
||||
if (subscription != null) {
|
||||
return {
|
||||
userId: exist.userId,
|
||||
endpoint: exist.endpoint,
|
||||
sendReadMessage: exist.sendReadMessage,
|
||||
userId: subscription.userId,
|
||||
endpoint: subscription.endpoint,
|
||||
sendReadMessage: subscription.sendReadMessage,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -13,13 +13,13 @@ export default async (
|
||||
user: { id: User["id"]; host: User["host"] },
|
||||
note: Note,
|
||||
) => {
|
||||
// if already unreacted
|
||||
const exist = await NoteReactions.findOneBy({
|
||||
const reaction = await NoteReactions.findOneBy({
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (exist == null) {
|
||||
// if already unreacted
|
||||
if (reaction == null) {
|
||||
throw new IdentifiableError(
|
||||
"60527ec9-b4cb-4a88-a6bd-32d3ad26817d",
|
||||
"not reacted",
|
||||
@ -27,7 +27,7 @@ export default async (
|
||||
}
|
||||
|
||||
// Delete reaction
|
||||
const result = await NoteReactions.delete(exist.id);
|
||||
const result = await NoteReactions.delete(reaction.id);
|
||||
|
||||
if (result.affected !== 1) {
|
||||
throw new IdentifiableError(
|
||||
@ -37,7 +37,7 @@ export default async (
|
||||
}
|
||||
|
||||
// Decrement reactions count
|
||||
const sql = `jsonb_set("reactions", '{${exist.reaction}}', (COALESCE("reactions"->>'${exist.reaction}', '0')::int - 1)::text::jsonb)`;
|
||||
const sql = `jsonb_set("reactions", '{${reaction.reaction}}', (COALESCE("reactions"->>'${reaction.reaction}', '0')::int - 1)::text::jsonb)`;
|
||||
await Notes.createQueryBuilder()
|
||||
.update()
|
||||
.set({
|
||||
@ -49,14 +49,14 @@ export default async (
|
||||
Notes.decrement({ id: note.id }, "score", 1);
|
||||
|
||||
publishNoteStream(note.id, "unreacted", {
|
||||
reaction: decodeReaction(exist.reaction).reaction,
|
||||
reaction: decodeReaction(reaction.reaction).reaction,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
//#region 配信
|
||||
if (Users.isLocalUser(user) && !note.localOnly) {
|
||||
const content = renderActivity(
|
||||
renderUndo(await renderLike(exist, note), user),
|
||||
renderUndo(await renderLike(reaction, note), user),
|
||||
);
|
||||
const dm = new DeliverManager(user, content);
|
||||
if (note.userHost !== null) {
|
||||
|
Loading…
Reference in New Issue
Block a user