Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SR fixing self follow #117

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions project/app/(tabs)/Profile/requests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ import {
removeFollowerRequest,
removeFollowingRequest,
updateUserProfile,
getUserProfile
getUserProfile,
getAllFollowers
} from '@/serviceFiles/usersDatabaseService';

interface FollowRequest {
Expand Down Expand Up @@ -247,20 +248,21 @@ export default function FollowRequests() {
await addFollowing(requestId, userId);
await removeFollowerRequest(userId, requestId);
await removeFollowingRequest(requestId, userId);


const followerList = await getAllFollowers(userId);

if(receiverProfile){
await updateUserProfile(userId, { followerCount: receiverProfile.followerCount + 1 });
await updateUserProfile(userId, { followerCount: followerList.length});
}
const senderProfile = await getUserProfile(requestId);
if (senderProfile) {
await updateUserProfile(requestId, { followingCount: senderProfile.followingCount + 1 });
}

Alert.alert('Success', 'Follow request accepted');

fetchFollowRequests();
} catch (error) {
console.error('Error accepting follow request:', error);
Alert.alert('Error', 'Failed to accept follow request');
console.log('Error accepting follow request:', error);
}
};

Expand All @@ -274,8 +276,8 @@ export default function FollowRequests() {
Alert.alert('Success', 'Follow request rejected');
fetchFollowRequests();
} catch (error) {
console.error('Error rejecting follow request:', error);
Alert.alert('Error', 'Failed to reject follow request');
console.log('Error rejecting follow request:', error);

}
};

Expand Down
16 changes: 14 additions & 2 deletions project/serviceFiles/usersDatabaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,21 @@ export const addFollowerRequest = async (userId: string, requestId: string) => {
);

const requestProfileData = await getUserProfile(requestId);

if(requestId == userId){
throw new Error("User cannot follow themselves."); // Explicit error
}else{

const requestData = {
username: requestProfileData?.username,
profilePicture: requestProfileData?.profilePicture,
};


await setDoc(requestDocRef, requestData);
}
} catch (error) {
console.error("Error adding follower request: ", error);
console.log("Error adding follower request: ", error);
}
};

Expand All @@ -167,14 +174,19 @@ export const addFollowingRequest = async (
);

const requestProfileData = await getUserProfile(requestId);

if(requestId == userId){
throw new Error("User cannot follow themselves."); // Explicit error
}else{
const requestData = {
username: requestProfileData?.username,
profilePicture: requestProfileData?.profilePicture,
};

await setDoc(requestDocRef, requestData);
}
} catch (error) {
console.error("Error adding following request: ", error);
console.log("Error adding following request: ", error);
}
};

Expand Down