Skip to content

Conversation

@Devothman1
Copy link

import { db } from '../firebase/firebase';
import { doc, updateDoc, arrayUnion, arrayRemove, getDoc } from 'firebase/firestore';

// دالة المتابعة
export const followUser = async (currentUserId, targetUserId) => {
try {
const currentUserRef = doc(db, 'users', currentUserId);
const targetUserRef = doc(db, 'users', targetUserId);

// تحديث بيانات المستخدم الحالي
await updateDoc(currentUserRef, {
  following: arrayUnion(targetUserId)
});

// تحديث بيانات المستخدم المستهدف
await updateDoc(targetUserRef, {
  followers: arrayUnion(currentUserId)
});

return true;

} catch (error) {
console.error('Error following user:', error);
return false;
}
};

// دالة إلغاء المتابعة
export const unfollowUser = async (currentUserId, targetUserId) => {
try {
const currentUserRef = doc(db, 'users', currentUserId);
const targetUserRef = doc(db, 'users', targetUserId);

await updateDoc(currentUserRef, {
  following: arrayRemove(targetUserId)
});

await updateDoc(targetUserRef, {
  followers: arrayRemove(currentUserId)
});

return true;

} catch (error) {
console.error('Error unfollowing user:', error);
return false;
}
};

// دالة获取 بيانات المستخدم
export const getUserData = async (userId) => {
try {
const userDoc = await getDoc(doc(db, 'users', userId));
if (userDoc.exists()) {
return userDoc.data();
}
return null;
} catch (error) {
console.error('Error getting user data:', error);
return null;
}
};

@vercel
Copy link

vercel bot commented Nov 7, 2025

@Hdsuhesgsy is attempting to deploy a commit to the Sashen Jayathilaka's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Devothman1
Copy link
Author

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant