T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/lavocat.ca/public_html/src/hooks/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.ca/public_html/src/hooks/useSocialActions.ts
import { useState } from 'react';
import { useSession } from 'next-auth/react';

export interface SocialActionResponse {
  success: boolean;
  message: string;
  data?: any;
}

export function useFollowUser() {
  const { data: session } = useSession();
  const [isLoading, setIsLoading] = useState(false);

  const followUser = async (userId: string): Promise<SocialActionResponse> => {
    if (!session?.user?.id) {
      return { success: false, message: 'You must be logged in to follow users' };
    }

    setIsLoading(true);
    try {
      const response = await fetch('/api/friends/request', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ friendId: userId }),
      });

      const data = await response.json();
      
      if (!response.ok) {
        throw new Error(data.message || 'Failed to send friend request');
      }

      return { success: true, message: 'Friend request sent successfully', data };
    } catch (error) {
      console.error('Error following user:', error);
      return { 
        success: false, 
        message: error instanceof Error ? error.message : 'Failed to follow user' 
      };
    } finally {
      setIsLoading(false);
    }
  };

  return { followUser, isLoading };
}

export function useFriendActions() {
  const { data: session } = useSession();
  const [isLoading, setIsLoading] = useState(false);

  const sendFriendRequest = async (friendId: string): Promise<SocialActionResponse> => {
    if (!session?.user?.id) {
      return { success: false, message: 'You must be logged in to send friend requests' };
    }

    setIsLoading(true);
    try {
      const response = await fetch('/api/friends/request', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ friendId }),
      });

      const data = await response.json();
      
      if (!response.ok) {
        throw new Error(data.message || 'Failed to send friend request');
      }

      return { success: true, message: 'Friend request sent successfully', data };
    } catch (error) {
      console.error('Error sending friend request:', error);
      return { 
        success: false, 
        message: error instanceof Error ? error.message : 'Failed to send friend request' 
      };
    } finally {
      setIsLoading(false);
    }
  };

  const acceptFriendRequest = async (friendId: string): Promise<SocialActionResponse> => {
    if (!session?.user?.id) {
      return { success: false, message: 'You must be logged in to accept friend requests' };
    }

    setIsLoading(true);
    try {
      const response = await fetch('/api/friends/accept', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ friendId }),
      });

      const data = await response.json();
      
      if (!response.ok) {
        throw new Error(data.message || 'Failed to accept friend request');
      }

      return { success: true, message: 'Friend request accepted successfully', data };
    } catch (error) {
      console.error('Error accepting friend request:', error);
      return { 
        success: false, 
        message: error instanceof Error ? error.message : 'Failed to accept friend request' 
      };
    } finally {
      setIsLoading(false);
    }
  };

  const declineFriendRequest = async (friendId: string): Promise<SocialActionResponse> => {
    if (!session?.user?.id) {
      return { success: false, message: 'You must be logged in to decline friend requests' };
    }

    setIsLoading(true);
    try {
      const response = await fetch('/api/friends/decline', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ friendId }),
      });

      const data = await response.json();
      
      if (!response.ok) {
        throw new Error(data.message || 'Failed to decline friend request');
      }

      return { success: true, message: 'Friend request declined successfully', data };
    } catch (error) {
      console.error('Error declining friend request:', error);
      return { 
        success: false, 
        message: error instanceof Error ? error.message : 'Failed to decline friend request' 
      };
    } finally {
      setIsLoading(false);
    }
  };

  const removeFriend = async (friendId: string): Promise<SocialActionResponse> => {
    if (!session?.user?.id) {
      return { success: false, message: 'You must be logged in to remove friends' };
    }

    setIsLoading(true);
    try {
      const response = await fetch('/api/friends/remove', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ friendId }),
      });

      const data = await response.json();
      
      if (!response.ok) {
        throw new Error(data.message || 'Failed to remove friend');
      }

      return { success: true, message: 'Friend removed successfully', data };
    } catch (error) {
      console.error('Error removing friend:', error);
      return { 
        success: false, 
        message: error instanceof Error ? error.message : 'Failed to remove friend' 
      };
    } finally {
      setIsLoading(false);
    }
  };

  return { 
    sendFriendRequest, 
    acceptFriendRequest, 
    declineFriendRequest, 
    removeFriend, 
    isLoading 
  };
}

export function useEndorseUser() {
  const { data: session } = useSession();
  const [isLoading, setIsLoading] = useState(false);

  const endorseUser = async (userId: string, endorsement: string): Promise<SocialActionResponse> => {
    if (!session?.user?.id) {
      return { success: false, message: 'You must be logged in to endorse users' };
    }

    setIsLoading(true);
    try {
      const response = await fetch('/api/users/endorse', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ userId, endorsement }),
      });

      const data = await response.json();
      
      if (!response.ok) {
        throw new Error(data.message || 'Failed to endorse user');
      }

      return { success: true, message: 'User endorsed successfully', data };
    } catch (error) {
      console.error('Error endorsing user:', error);
      return { 
        success: false, 
        message: error instanceof Error ? error.message : 'Failed to endorse user' 
      };
    } finally {
      setIsLoading(false);
    }
  };

  return { endorseUser, isLoading };
}

export function useMessageUser() {
  const { data: session } = useSession();
  const [isLoading, setIsLoading] = useState(false);

  const sendMessage = async (recipientId: string, message: string): Promise<SocialActionResponse> => {
    if (!session?.user?.id) {
      return { success: false, message: 'You must be logged in to send messages' };
    }

    setIsLoading(true);
    try {
      const response = await fetch('/api/messages/send', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ recipientId, message }),
      });

      const data = await response.json();
      
      if (!response.ok) {
        throw new Error(data.message || 'Failed to send message');
      }

      return { success: true, message: 'Message sent successfully', data };
    } catch (error) {
      console.error('Error sending message:', error);
      return { 
        success: false, 
        message: error instanceof Error ? error.message : 'Failed to send message' 
      };
    } finally {
      setIsLoading(false);
    }
  };

  return { sendMessage, isLoading };
}

export function useShareProfile() {
  const [isLoading, setIsLoading] = useState(false);

  const shareProfile = async (userId: string, platform: string): Promise<SocialActionResponse> => {
    setIsLoading(true);
    try {
      const profileUrl = `${window.location.origin}/profile/${userId}`;
      
      // Handle different sharing platforms
      switch (platform) {
        case 'copy':
          await navigator.clipboard.writeText(profileUrl);
          return { success: true, message: 'Profile URL copied to clipboard' };
        
        case 'twitter':
          window.open(`https://twitter.com/intent/tweet?text=Check out this profile&url=${encodeURIComponent(profileUrl)}`);
          return { success: true, message: 'Opened Twitter share dialog' };
        
        case 'linkedin':
          window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(profileUrl)}`);
          return { success: true, message: 'Opened LinkedIn share dialog' };
        
        case 'facebook':
          window.open(`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(profileUrl)}`);
          return { success: true, message: 'Opened Facebook share dialog' };
        
        default:
          return { success: false, message: 'Unsupported sharing platform' };
      }
    } catch (error) {
      console.error('Error sharing profile:', error);
      return { 
        success: false, 
        message: error instanceof Error ? error.message : 'Failed to share profile' 
      };
    } finally {
      setIsLoading(false);
    }
  };

  return { shareProfile, isLoading };
}

export function useReportUser() {
  const { data: session } = useSession();
  const [isLoading, setIsLoading] = useState(false);

  const reportUser = async (userId: string, reason: string, details?: string): Promise<SocialActionResponse> => {
    if (!session?.user?.id) {
      return { success: false, message: 'You must be logged in to report users' };
    }

    setIsLoading(true);
    try {
      const response = await fetch('/api/users/report', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ userId, reason, details }),
      });

      const data = await response.json();
      
      if (!response.ok) {
        throw new Error(data.message || 'Failed to report user');
      }

      return { success: true, message: 'User reported successfully', data };
    } catch (error) {
      console.error('Error reporting user:', error);
      return { 
        success: false, 
        message: error instanceof Error ? error.message : 'Failed to report user' 
      };
    } finally {
      setIsLoading(false);
    }
  };

  return { reportUser, isLoading };
} 

CasperSecurity Mini