diff --git a/src/app/[locale]/(user)/user/[profileUrl]/page.tsx b/src/app/[locale]/(user)/user/[profileUrl]/page.tsx index 5b4fecb0..036eca5c 100644 --- a/src/app/[locale]/(user)/user/[profileUrl]/page.tsx +++ b/src/app/[locale]/(user)/user/[profileUrl]/page.tsx @@ -31,7 +31,6 @@ import { import { Link } from '@/navigation' import { Button } from '@/components/ui/button' import ContextMenuProfile from '@/components/user/contextMenuProfile' -import { getUser } from '@/utils/server-api/account/user' import { getAvatarImageUrlView, getBannerImageUrlPreview, @@ -70,12 +69,6 @@ export async function generateMetadata({ export default async function UserProfile({ params: { profileUrl } }) { const { databases } = await createSessionServerClient() - let account = null - try { - account = await getUser() - } catch (error) { - // User is not logged in - } const userDataResponse: UserData.UserDataType = await databases.listDocuments( 'hp_db', @@ -85,8 +78,7 @@ export default async function UserProfile({ params: { profileUrl } }) { const userData = userDataResponse.documents[0] const followers = await getFollowers(userData.$id, 0, 5000000) const following = await getFollowing(userData.$id, 0, 5000000) - const isFollowingResponse = await getIsFollowing(account?.$id, userData?.$id) - const isFollowing = isFollowingResponse?.documents?.length > 0 || false + const isFollowing = await getIsFollowing(userData?.$id) const totalFollowers: number = followers?.length const totalFollowing: number = following?.length diff --git a/src/utils/server-api/followers/getFollowing.ts b/src/utils/server-api/followers/getFollowing.ts index 57607892..6dd5a862 100644 --- a/src/utils/server-api/followers/getFollowing.ts +++ b/src/utils/server-api/followers/getFollowing.ts @@ -1,13 +1,7 @@ -import { createSessionServerClient } from '@/app/appwrite-session' import { Followers } from '@/utils/types/models' -import { ExecutionMethod, Query } from 'node-appwrite' -import { unstable_noStore } from 'next/cache' +import { ExecutionMethod } from 'node-appwrite' +import { createSessionServerClient } from '@/app/appwrite-session' -/** - * This function is used to get the followers of a user. - * @example - * const following = await getFollowing('user_id', 0, 20) - */ export async function getFollowing( userId: string, offset: number = 0, @@ -24,32 +18,15 @@ export async function getFollowing( return JSON.parse(data.responseBody) } -/** - * This function is used to check if a user is following another user. - * @param {string} userId The user id. - * @param {string} followerId The follower id. - * @returns {Promise} The follower document. - * @example - * const following = await isFollowing('user_id', 'follower_id') - * if (following.documents.length > 0) { - * console.log('User is following') - * return - * } - */ -export async function getIsFollowing( - userId: string, - followerId: string -): Promise { - unstable_noStore() - const { databases } = await createSessionServerClient() - return await databases - .listDocuments('hp_db', 'followers', [ - Query.and([ - Query.equal('userId', userId), - Query.equal('followerId', followerId), - ]), - ]) - .catch((error) => { - return error - }) +export async function getIsFollowing(followerId: string) { + const { functions } = await createSessionServerClient() + const data = await functions.createExecution( + 'user-endpoints', + '', + false, + `/user/isFollowing?followerId=${followerId}`, + ExecutionMethod.POST + ) + + return JSON.parse(data.responseBody) }