mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-29 13:27:31 -07:00
Merge pull request '[PR]: chore: Use exist
instead of findOneBy
to check for existence' (#10484) from naskya/calckey:chore/findOneBy-exist into develop
Reviewed-on: https://codeberg.org/calckey/calckey/pulls/10484
This commit is contained in:
commit
d2926e0822
33 changed files with 206 additions and 158 deletions
|
@ -147,11 +147,11 @@ export async function fetchPerson(
|
||||||
}
|
}
|
||||||
|
|
||||||
//#region Returns if already registered with this server
|
//#region Returns if already registered with this server
|
||||||
const exist = await Users.findOneBy({ uri });
|
const user = await Users.findOneBy({ uri });
|
||||||
|
|
||||||
if (exist) {
|
if (user != null) {
|
||||||
await uriPersonCache.set(uri, exist);
|
await uriPersonCache.set(uri, user);
|
||||||
return exist;
|
return user;
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
@ -396,9 +396,9 @@ export async function updatePerson(
|
||||||
}
|
}
|
||||||
|
|
||||||
//#region Already registered on this server?
|
//#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;
|
return;
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
@ -416,17 +416,15 @@ export async function updatePerson(
|
||||||
[person.icon, person.image].map((img) =>
|
[person.icon, person.image].map((img) =>
|
||||||
img == null
|
img == null
|
||||||
? Promise.resolve(null)
|
? Promise.resolve(null)
|
||||||
: resolveImage(exist, img).catch(() => null),
|
: resolveImage(user, img).catch(() => null),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Custom pictogram acquisition
|
// Custom pictogram acquisition
|
||||||
const emojis = await extractEmojis(person.tag || [], exist.host).catch(
|
const emojis = await extractEmojis(person.tag || [], user.host).catch((e) => {
|
||||||
(e) => {
|
|
||||||
logger.info(`extractEmojis: ${e}`);
|
logger.info(`extractEmojis: ${e}`);
|
||||||
return [] as Emoji[];
|
return [] as Emoji[];
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const emojiNames = emojis.map((emoji) => emoji.name);
|
const emojiNames = emojis.map((emoji) => emoji.name);
|
||||||
|
|
||||||
|
@ -518,11 +516,11 @@ export async function updatePerson(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update user
|
// Update user
|
||||||
await Users.update(exist.id, updates);
|
await Users.update(user.id, updates);
|
||||||
|
|
||||||
if (person.publicKey) {
|
if (person.publicKey) {
|
||||||
await UserPublickeys.update(
|
await UserPublickeys.update(
|
||||||
{ userId: exist.id },
|
{ userId: user.id },
|
||||||
{
|
{
|
||||||
keyId: person.publicKey.id,
|
keyId: person.publicKey.id,
|
||||||
keyPem: person.publicKey.publicKeyPem,
|
keyPem: person.publicKey.publicKeyPem,
|
||||||
|
@ -531,7 +529,7 @@ export async function updatePerson(
|
||||||
}
|
}
|
||||||
|
|
||||||
await UserProfiles.update(
|
await UserProfiles.update(
|
||||||
{ userId: exist.id },
|
{ userId: user.id },
|
||||||
{
|
{
|
||||||
url: url,
|
url: url,
|
||||||
fields,
|
fields,
|
||||||
|
@ -543,15 +541,15 @@ export async function updatePerson(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
publishInternalEvent("remoteUserUpdated", { id: exist.id });
|
publishInternalEvent("remoteUserUpdated", { id: user.id });
|
||||||
|
|
||||||
// Hashtag Update
|
// Hashtag Update
|
||||||
updateUsertags(exist, tags);
|
updateUsertags(user, tags);
|
||||||
|
|
||||||
// If the user in question is a follower, followers will also be updated.
|
// If the user in question is a follower, followers will also be updated.
|
||||||
await Followings.update(
|
await Followings.update(
|
||||||
{
|
{
|
||||||
followerId: exist.id,
|
followerId: user.id,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
followerSharedInbox:
|
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");
|
if (typeof uri !== "string") throw new Error("uri is not string");
|
||||||
|
|
||||||
//#region If already registered on this server, return it.
|
//#region If already registered on this server, return it.
|
||||||
const exist = await fetchPerson(uri);
|
const user = await fetchPerson(uri);
|
||||||
|
|
||||||
if (exist) {
|
if (user != null) {
|
||||||
return exist;
|
return user;
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,9 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
const exist = await PromoNotes.findOneBy({ noteId: note.id });
|
const exist = await PromoNotes.exist({ where: { noteId: note.id } });
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist) {
|
||||||
throw new ApiError(meta.errors.alreadyPromoted);
|
throw new ApiError(meta.errors.alreadyPromoted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
const accessToken = secureRndstr(32, true);
|
const accessToken = secureRndstr(32, true);
|
||||||
|
|
||||||
// Fetch exist access token
|
// Fetch exist access token
|
||||||
const exist = await AccessTokens.findOneBy({
|
const exist = await AccessTokens.exist({
|
||||||
|
where: {
|
||||||
appId: session.appId,
|
appId: session.appId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (!exist) {
|
||||||
// Lookup app
|
// Lookup app
|
||||||
const app = await Apps.findOneByOrFail({ id: session.appId });
|
const app = await Apps.findOneByOrFail({ id: session.appId });
|
||||||
|
|
||||||
|
|
|
@ -69,12 +69,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if already blocking
|
// Check if already blocking
|
||||||
const exist = await Blockings.findOneBy({
|
const exist = await Blockings.exist({
|
||||||
|
where: {
|
||||||
blockerId: blocker.id,
|
blockerId: blocker.id,
|
||||||
blockeeId: blockee.id,
|
blockeeId: blockee.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist) {
|
||||||
throw new ApiError(meta.errors.alreadyBlocking);
|
throw new ApiError(meta.errors.alreadyBlocking);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,12 +69,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check not blocking
|
// Check not blocking
|
||||||
const exist = await Blockings.findOneBy({
|
const exist = await Blockings.exist({
|
||||||
|
where: {
|
||||||
blockerId: blocker.id,
|
blockerId: blocker.id,
|
||||||
blockeeId: blockee.id,
|
blockeeId: blockee.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (!exist) {
|
||||||
throw new ApiError(meta.errors.notBlocking);
|
throw new ApiError(meta.errors.notBlocking);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,12 +57,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
const exist = await ClipNotes.findOneBy({
|
const exist = await ClipNotes.exist({
|
||||||
|
where: {
|
||||||
noteId: note.id,
|
noteId: note.id,
|
||||||
clipId: clip.id,
|
clipId: clip.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist) {
|
||||||
throw new ApiError(meta.errors.alreadyClipped);
|
throw new ApiError(meta.errors.alreadyClipped);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,12 @@ export const paramDef = {
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default define(meta, paramDef, async (ps, user) => {
|
export default define(meta, paramDef, async (ps, user) => {
|
||||||
const file = await DriveFiles.findOneBy({
|
const exist = await DriveFiles.exist({
|
||||||
|
where: {
|
||||||
md5: ps.md5,
|
md5: ps.md5,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return file != null;
|
return exist;
|
||||||
});
|
});
|
||||||
|
|
|
@ -82,12 +82,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if already following
|
// Check if already following
|
||||||
const exist = await Followings.findOneBy({
|
const exist = await Followings.exist({
|
||||||
|
where: {
|
||||||
followerId: follower.id,
|
followerId: follower.id,
|
||||||
followeeId: followee.id,
|
followeeId: followee.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist) {
|
||||||
throw new ApiError(meta.errors.alreadyFollowing);
|
throw new ApiError(meta.errors.alreadyFollowing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,12 +69,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check not following
|
// Check not following
|
||||||
const exist = await Followings.findOneBy({
|
const exist = await Followings.exist({
|
||||||
|
where: {
|
||||||
followerId: follower.id,
|
followerId: follower.id,
|
||||||
followeeId: followee.id,
|
followeeId: followee.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (!exist) {
|
||||||
throw new ApiError(meta.errors.notFollowing);
|
throw new ApiError(meta.errors.notFollowing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,12 +69,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check not following
|
// Check not following
|
||||||
const exist = await Followings.findOneBy({
|
const exist = await Followings.exist({
|
||||||
|
where: {
|
||||||
followerId: follower.id,
|
followerId: follower.id,
|
||||||
followeeId: followee.id,
|
followeeId: followee.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (!exist) {
|
||||||
throw new ApiError(meta.errors.notFollowing);
|
throw new ApiError(meta.errors.notFollowing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,12 +40,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if already liked
|
// if already liked
|
||||||
const exist = await GalleryLikes.findOneBy({
|
const exist = await GalleryLikes.exist({
|
||||||
|
where: {
|
||||||
postId: post.id,
|
postId: post.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist) {
|
||||||
throw new ApiError(meta.errors.alreadyLiked);
|
throw new ApiError(meta.errors.alreadyLiked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,17 +38,17 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
throw new ApiError(meta.errors.noSuchPost);
|
throw new ApiError(meta.errors.noSuchPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
const exist = await GalleryLikes.findOneBy({
|
const like = await GalleryLikes.findOneBy({
|
||||||
postId: post.id,
|
postId: post.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (like == null) {
|
||||||
throw new ApiError(meta.errors.notLiked);
|
throw new ApiError(meta.errors.notLiked);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete like
|
// Delete like
|
||||||
await GalleryLikes.delete(exist.id);
|
await GalleryLikes.delete(like.id);
|
||||||
|
|
||||||
GalleryPosts.decrement({ id: post.id }, "likedCount", 1);
|
GalleryPosts.decrement({ id: post.id }, "likedCount", 1);
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,19 +30,23 @@ export const paramDef = {
|
||||||
|
|
||||||
export default define(meta, paramDef, async (ps, user) => {
|
export default define(meta, paramDef, async (ps, user) => {
|
||||||
// Check if announcement exists
|
// Check if announcement exists
|
||||||
const announcement = await Announcements.findOneBy({ id: ps.announcementId });
|
const exist = await Announcements.exist({
|
||||||
|
where: { id: ps.announcementId },
|
||||||
|
});
|
||||||
|
|
||||||
if (announcement == null) {
|
if (!exist) {
|
||||||
throw new ApiError(meta.errors.noSuchAnnouncement);
|
throw new ApiError(meta.errors.noSuchAnnouncement);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if already read
|
// Check if already read
|
||||||
const read = await AnnouncementReads.findOneBy({
|
const read = await AnnouncementReads.exist({
|
||||||
|
where: {
|
||||||
announcementId: ps.announcementId,
|
announcementId: ps.announcementId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (read != null) {
|
if (read) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,9 @@ export const paramDef = {
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default define(meta, paramDef, async (ps, user) => {
|
export default define(meta, paramDef, async (ps, user) => {
|
||||||
const token = await AccessTokens.findOneBy({ id: ps.tokenId });
|
const exist = await AccessTokens.exist({ where: { id: ps.tokenId } });
|
||||||
|
|
||||||
if (token) {
|
if (exist) {
|
||||||
await AccessTokens.delete({
|
await AccessTokens.delete({
|
||||||
id: ps.tokenId,
|
id: ps.tokenId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
|
|
@ -64,12 +64,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if already muting
|
// Check if already muting
|
||||||
const exist = await Mutings.findOneBy({
|
const exist = await Mutings.exist({
|
||||||
|
where: {
|
||||||
muterId: muter.id,
|
muterId: muter.id,
|
||||||
muteeId: mutee.id,
|
muteeId: mutee.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist) {
|
||||||
throw new ApiError(meta.errors.alreadyMuting);
|
throw new ApiError(meta.errors.alreadyMuting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,18 +56,18 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check not muting
|
// Check not muting
|
||||||
const exist = await Mutings.findOneBy({
|
const muting = await Mutings.findOneBy({
|
||||||
muterId: muter.id,
|
muterId: muter.id,
|
||||||
muteeId: mutee.id,
|
muteeId: mutee.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (muting == null) {
|
||||||
throw new ApiError(meta.errors.notMuting);
|
throw new ApiError(meta.errors.notMuting);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete mute
|
// Delete mute
|
||||||
await Mutings.delete({
|
await Mutings.delete({
|
||||||
id: exist.id,
|
id: muting.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
publishUserEvent(user.id, "unmute", mutee);
|
publishUserEvent(user.id, "unmute", mutee);
|
||||||
|
|
|
@ -224,11 +224,13 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
|
|
||||||
// Check blocking
|
// Check blocking
|
||||||
if (renote.userId !== user.id) {
|
if (renote.userId !== user.id) {
|
||||||
const block = await Blockings.findOneBy({
|
const isBlocked = await Blockings.exist({
|
||||||
|
where: {
|
||||||
blockerId: renote.userId,
|
blockerId: renote.userId,
|
||||||
blockeeId: user.id,
|
blockeeId: user.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (block) {
|
if (isBlocked) {
|
||||||
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,11 +251,13 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
|
|
||||||
// Check blocking
|
// Check blocking
|
||||||
if (reply.userId !== user.id) {
|
if (reply.userId !== user.id) {
|
||||||
const block = await Blockings.findOneBy({
|
const isBlocked = await Blockings.exist({
|
||||||
|
where: {
|
||||||
blockerId: reply.userId,
|
blockerId: reply.userId,
|
||||||
blockeeId: user.id,
|
blockeeId: user.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (block) {
|
if (isBlocked) {
|
||||||
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,12 +43,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// if already favorited
|
// if already favorited
|
||||||
const exist = await NoteFavorites.findOneBy({
|
const exist = await NoteFavorites.exist({
|
||||||
|
where: {
|
||||||
noteId: note.id,
|
noteId: note.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist) {
|
||||||
throw new ApiError(meta.errors.alreadyFavorited);
|
throw new ApiError(meta.errors.alreadyFavorited);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,15 +42,15 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// if already favorited
|
// if already favorited
|
||||||
const exist = await NoteFavorites.findOneBy({
|
const favorite = await NoteFavorites.findOneBy({
|
||||||
noteId: note.id,
|
noteId: note.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (favorite == null) {
|
||||||
throw new ApiError(meta.errors.notFavorited);
|
throw new ApiError(meta.errors.notFavorited);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete favorite
|
// Delete favorite
|
||||||
await NoteFavorites.delete(exist.id);
|
await NoteFavorites.delete(favorite.id);
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,12 +40,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if already liked
|
// if already liked
|
||||||
const exist = await PageLikes.findOneBy({
|
const exist = await PageLikes.exist({
|
||||||
|
where: {
|
||||||
pageId: page.id,
|
pageId: page.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist) {
|
||||||
throw new ApiError(meta.errors.alreadyLiked);
|
throw new ApiError(meta.errors.alreadyLiked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,17 +38,17 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
throw new ApiError(meta.errors.noSuchPage);
|
throw new ApiError(meta.errors.noSuchPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const exist = await PageLikes.findOneBy({
|
const like = await PageLikes.findOneBy({
|
||||||
pageId: page.id,
|
pageId: page.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (like == null) {
|
||||||
throw new ApiError(meta.errors.notLiked);
|
throw new ApiError(meta.errors.notLiked);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete like
|
// Delete like
|
||||||
await PageLikes.delete(exist.id);
|
await PageLikes.delete(like.id);
|
||||||
|
|
||||||
Pages.decrement({ id: page.id }, "likedCount", 1);
|
Pages.decrement({ id: page.id }, "likedCount", 1);
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,12 +33,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
const exist = await PromoReads.findOneBy({
|
const exist = await PromoReads.exist({
|
||||||
|
where: {
|
||||||
noteId: note.id,
|
noteId: note.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,12 +47,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if already muting
|
// Check if already muting
|
||||||
const exist = await RenoteMutings.findOneBy({
|
const exist = await RenoteMutings.exist({
|
||||||
|
where: {
|
||||||
muterId: muter.id,
|
muterId: muter.id,
|
||||||
muteeId: mutee.id,
|
muteeId: mutee.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist) {
|
||||||
throw new ApiError(meta.errors.alreadyMuting);
|
throw new ApiError(meta.errors.alreadyMuting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,18 +45,18 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check not muting
|
// Check not muting
|
||||||
const exist = await RenoteMutings.findOneBy({
|
const muting = await RenoteMutings.findOneBy({
|
||||||
muterId: muter.id,
|
muterId: muter.id,
|
||||||
muteeId: mutee.id,
|
muteeId: mutee.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (muting == null) {
|
||||||
throw new ApiError(meta.errors.notMuting);
|
throw new ApiError(meta.errors.notMuting);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete mute
|
// Delete mute
|
||||||
await RenoteMutings.delete({
|
await RenoteMutings.delete({
|
||||||
id: exist.id,
|
id: muting.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// publishUserEvent(user.id, "unmute", mutee);
|
// publishUserEvent(user.id, "unmute", mutee);
|
||||||
|
|
|
@ -57,8 +57,7 @@ export const paramDef = {
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default define(meta, paramDef, async (ps, me) => {
|
export default define(meta, paramDef, async (ps, me) => {
|
||||||
// if already subscribed
|
const subscription = await SwSubscriptions.findOneBy({
|
||||||
const exist = await SwSubscriptions.findOneBy({
|
|
||||||
userId: me.id,
|
userId: me.id,
|
||||||
endpoint: ps.endpoint,
|
endpoint: ps.endpoint,
|
||||||
auth: ps.auth,
|
auth: ps.auth,
|
||||||
|
@ -67,13 +66,14 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
|
|
||||||
const instance = await fetchMeta(true);
|
const instance = await fetchMeta(true);
|
||||||
|
|
||||||
if (exist != null) {
|
// if already subscribed
|
||||||
|
if (subscription != null) {
|
||||||
return {
|
return {
|
||||||
state: "already-subscribed" as const,
|
state: "already-subscribed" as const,
|
||||||
key: instance.swPublicKey,
|
key: instance.swPublicKey,
|
||||||
userId: me.id,
|
userId: me.id,
|
||||||
endpoint: exist.endpoint,
|
endpoint: subscription.endpoint,
|
||||||
sendReadMessage: exist.sendReadMessage,
|
sendReadMessage: subscription.sendReadMessage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,16 +42,16 @@ export const paramDef = {
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
// eslint-disable-next-line import/no-default-export
|
||||||
export default define(meta, paramDef, async (ps, me) => {
|
export default define(meta, paramDef, async (ps, me) => {
|
||||||
const exist = await SwSubscriptions.findOneBy({
|
const subscription = await SwSubscriptions.findOneBy({
|
||||||
userId: me.id,
|
userId: me.id,
|
||||||
endpoint: ps.endpoint,
|
endpoint: ps.endpoint,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (subscription != null) {
|
||||||
return {
|
return {
|
||||||
userId: exist.userId,
|
userId: subscription.userId,
|
||||||
endpoint: exist.endpoint,
|
endpoint: subscription.endpoint,
|
||||||
sendReadMessage: exist.sendReadMessage,
|
sendReadMessage: subscription.sendReadMessage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,11 +98,13 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
if (me == null) {
|
if (me == null) {
|
||||||
throw new ApiError(meta.errors.forbidden);
|
throw new ApiError(meta.errors.forbidden);
|
||||||
} else if (me.id !== user.id) {
|
} else if (me.id !== user.id) {
|
||||||
const following = await Followings.findOneBy({
|
const isFollowed = await Followings.exist({
|
||||||
|
where: {
|
||||||
followeeId: user.id,
|
followeeId: user.id,
|
||||||
followerId: me.id,
|
followerId: me.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (following == null) {
|
if (!isFollowed) {
|
||||||
throw new ApiError(meta.errors.nullFollowers);
|
throw new ApiError(meta.errors.nullFollowers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,11 +97,13 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
if (me == null) {
|
if (me == null) {
|
||||||
throw new ApiError(meta.errors.forbidden);
|
throw new ApiError(meta.errors.forbidden);
|
||||||
} else if (me.id !== user.id) {
|
} else if (me.id !== user.id) {
|
||||||
const following = await Followings.findOneBy({
|
const isFollowing = await Followings.exist({
|
||||||
|
where: {
|
||||||
followeeId: user.id,
|
followeeId: user.id,
|
||||||
followerId: me.id,
|
followerId: me.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (following == null) {
|
if (!isFollowing) {
|
||||||
throw new ApiError(meta.errors.cannot_find);
|
throw new ApiError(meta.errors.cannot_find);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,12 +52,14 @@ export const paramDef = {
|
||||||
|
|
||||||
export default define(meta, paramDef, async (ps, me) => {
|
export default define(meta, paramDef, async (ps, me) => {
|
||||||
// Fetch the list
|
// Fetch the list
|
||||||
const userList = await UserLists.findOneBy({
|
const listExists = await UserLists.exist({
|
||||||
|
where: {
|
||||||
id: ps.listId,
|
id: ps.listId,
|
||||||
userId: me.id,
|
userId: me.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (userList == null) {
|
if (!listExists) {
|
||||||
throw new ApiError(meta.errors.noSuchList);
|
throw new ApiError(meta.errors.noSuchList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,18 +72,22 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
|
|
||||||
// Check blocking
|
// Check blocking
|
||||||
if (user.id !== me.id) {
|
if (user.id !== me.id) {
|
||||||
const block = await Blockings.findOneBy({
|
const isBlocked = await Blockings.exist({
|
||||||
|
where: {
|
||||||
blockerId: user.id,
|
blockerId: user.id,
|
||||||
blockeeId: me.id,
|
blockeeId: me.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (block) {
|
if (isBlocked) {
|
||||||
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const exist = await UserListJoinings.findOneBy({
|
const exist = await UserListJoinings.exist({
|
||||||
|
where: {
|
||||||
userListId: userList.id,
|
userListId: userList.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist) {
|
if (exist) {
|
||||||
|
|
|
@ -37,12 +37,14 @@ export const paramDef = {
|
||||||
|
|
||||||
export default define(meta, paramDef, async (ps, me) => {
|
export default define(meta, paramDef, async (ps, me) => {
|
||||||
// Fetch the list
|
// Fetch the list
|
||||||
const userList = await UserLists.findOneBy({
|
const exist = await UserLists.exist({
|
||||||
|
where: {
|
||||||
id: ps.listId,
|
id: ps.listId,
|
||||||
userId: me.id,
|
userId: me.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (userList == null) {
|
if (!exist) {
|
||||||
throw new ApiError(meta.errors.noSuchList);
|
throw new ApiError(meta.errors.noSuchList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,13 @@ export default class extends Channel {
|
||||||
this.listId = params.listId as string;
|
this.listId = params.listId as string;
|
||||||
|
|
||||||
// Check existence and owner
|
// Check existence and owner
|
||||||
const list = await UserLists.findOneBy({
|
const exist = await UserLists.exist({
|
||||||
|
where: {
|
||||||
id: this.listId,
|
id: this.listId,
|
||||||
userId: this.user!.id,
|
userId: this.user!.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (!list) return;
|
if (!exist) return;
|
||||||
|
|
||||||
// Subscribe stream
|
// Subscribe stream
|
||||||
this.subscriber.on(`userListStream:${this.listId}`, this.send);
|
this.subscriber.on(`userListStream:${this.listId}`, this.send);
|
||||||
|
|
|
@ -13,13 +13,13 @@ export default async (
|
||||||
user: { id: User["id"]; host: User["host"] },
|
user: { id: User["id"]; host: User["host"] },
|
||||||
note: Note,
|
note: Note,
|
||||||
) => {
|
) => {
|
||||||
// if already unreacted
|
const reaction = await NoteReactions.findOneBy({
|
||||||
const exist = await NoteReactions.findOneBy({
|
|
||||||
noteId: note.id,
|
noteId: note.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
// if already unreacted
|
||||||
|
if (reaction == null) {
|
||||||
throw new IdentifiableError(
|
throw new IdentifiableError(
|
||||||
"60527ec9-b4cb-4a88-a6bd-32d3ad26817d",
|
"60527ec9-b4cb-4a88-a6bd-32d3ad26817d",
|
||||||
"not reacted",
|
"not reacted",
|
||||||
|
@ -27,7 +27,7 @@ export default async (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete reaction
|
// Delete reaction
|
||||||
const result = await NoteReactions.delete(exist.id);
|
const result = await NoteReactions.delete(reaction.id);
|
||||||
|
|
||||||
if (result.affected !== 1) {
|
if (result.affected !== 1) {
|
||||||
throw new IdentifiableError(
|
throw new IdentifiableError(
|
||||||
|
@ -37,7 +37,7 @@ export default async (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrement reactions count
|
// 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()
|
await Notes.createQueryBuilder()
|
||||||
.update()
|
.update()
|
||||||
.set({
|
.set({
|
||||||
|
@ -49,14 +49,14 @@ export default async (
|
||||||
Notes.decrement({ id: note.id }, "score", 1);
|
Notes.decrement({ id: note.id }, "score", 1);
|
||||||
|
|
||||||
publishNoteStream(note.id, "unreacted", {
|
publishNoteStream(note.id, "unreacted", {
|
||||||
reaction: decodeReaction(exist.reaction).reaction,
|
reaction: decodeReaction(reaction.reaction).reaction,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
//#region 配信
|
//#region 配信
|
||||||
if (Users.isLocalUser(user) && !note.localOnly) {
|
if (Users.isLocalUser(user) && !note.localOnly) {
|
||||||
const content = renderActivity(
|
const content = renderActivity(
|
||||||
renderUndo(await renderLike(exist, note), user),
|
renderUndo(await renderLike(reaction, note), user),
|
||||||
);
|
);
|
||||||
const dm = new DeliverManager(user, content);
|
const dm = new DeliverManager(user, content);
|
||||||
if (note.userHost !== null) {
|
if (note.userHost !== null) {
|
||||||
|
|
|
@ -42,9 +42,9 @@ export async function insertNoteUnread(
|
||||||
|
|
||||||
// 2秒経っても既読にならなかったら「未読の投稿がありますよ」イベントを発行する
|
// 2秒経っても既読にならなかったら「未読の投稿がありますよ」イベントを発行する
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const exist = await NoteUnreads.findOneBy({ id: unread.id });
|
const exist = await NoteUnreads.exist({ where: { id: unread.id } });
|
||||||
|
|
||||||
if (exist == null) return;
|
if (!exist) return;
|
||||||
|
|
||||||
if (params.isMentioned) {
|
if (params.isMentioned) {
|
||||||
publishMainStream(userId, "unreadMention", note.id);
|
publishMainStream(userId, "unreadMention", note.id);
|
||||||
|
|
Loading…
Reference in a new issue