Untitled

 avatar
unknown
plain_text
a year ago
33 kB
4
Indexable
// Customizable Area Start
// @ts-nocheck
// @ts-ignore
import { IBlock } from '../../../../framework/src/IBlock'
import { Message } from '../../../../framework/src/Message'
import { BlockComponent } from '../../../../framework/src/BlockComponent'
import MessageEnum, {
  getName,
} from '../../../../framework/src/Messages/MessageEnum'
import { runEngine } from '../../../../framework/src/RunEngine'
import StorageProvider from '../../../../framework/src/StorageProvider'
import { Alert } from 'react-native'
import Apptheme from '../../../HamburgerMenu/src/Apptheme'
import { CommonContext } from '../../../../components/src/CommonContextProvider'
import SoundPlayer from 'react-native-sound-player'
import React from 'react'
import { getStorageData } from 'framework/src/Utilities'

export const configJSON = require('../config')

export interface Props {
  navigation: any
  id: string
}

interface S {
  error:string;
  selectedSongTrack_idInput:any;
  guideList: boolean
  playList: boolean
  eventList: boolean
  exhibitionList: boolean
  showGenre: any
  showTrending: any
  coverImage: any
  userName: any
  loading: boolean
  aboutText: string;
  genrearray: any;
  loadingarray: boolean;
  favArray: any;
  height: any;
  profileImage: any;
  userIdFromApi: any;
  accounID: any;
  is_following: boolean;
  _showThreeDots: boolean;
  loader: boolean,
  loaderPlaylist: boolean;
  profioleFeedPostList: any
  handleRefresh: any;
  postarray: any
  songDetails: any;
  isPlaying: boolean;
  contextId: number;
  contextData: boolean;
  songImageUrl: string;
  sondDetails: any;
  pause: boolean
  play: boolean
  currentSongTitle: any
  currSongArtist: any
  Musicindex: number;
  handle: string;
  spotifyUri: string;
  progress: any;
  showCreatepost: boolean;
  headerShown: boolean;
  Genre: any;
  status: boolean;
  istastemaker: boolean;
  platform: string;
  selectetab: string;
  songName: any;
  artistName: any;
  imageUrl: any;
  showNotification: boolean;
  message: string;
  deletePostId: any;
  playlistsearchList: any;
  appleMusicPlaylist:Array;
  favGenre: any;
  userFollowing: any;
  userFollower: any;
  indexId: number;
  sonMedialUrl: string;
  profileSongResponse: any;
  pageNo: number;
  totdalNumberOfPage: number;
}

interface SS {
  id: any
}

export default class FeedBlockProfileController extends BlockComponent<
  Props,
  S,
  SS
> {
  getProfileApiCallId: any
  getAppleMusicplaylistApiCallId:any
  labelTitle: string = ''
  getProfilePostListApiCallid: any
  getfavPostListApiCallid: any
  apiPlaylistSearchGetCall: any
  apiSendRepostId: any
  deletePostApiCallId: any
  navigationgobackListener: any;
  apiGenreSearchGetCall: any;
  pauseInterval: any;
  favgenrelistCallIdd: any;
  aRef: any;
  myRef: any;
  animatedValue: any;
  _onFinishedPlayingSubscription: any;
  _onFinishedLoadingSubscription: any;
  _onFinishedLoadingFileSubscription: any;
  _onFinishedLoadingURLSubscription: any;
  focusListener: any;
  RBSheet: any
  static contextType = CommonContext;



  constructor(props: Props) {
    super(props)
    this.receive = this.receive.bind(this)
    this.myRef = React.createRef();
    this.subScribedMessages = [
      getName(MessageEnum.CountryCodeMessage),
      getName(MessageEnum.RestAPIResponceMessage),
      getName(MessageEnum.ReciveUserCredentials),
    ]

    this.state = {
      error:'',
      selectedSongTrack_idInput:'',
      coverImage: false,
      userName: '',
      loading: false,
      aboutText: '',
      profileImage: false,
      userIdFromApi: '',
      accounID: '',
      is_following: false,
      _showThreeDots: false,
      loader: false,
      loaderPlaylist: false,
      profioleFeedPostList: [],
      handleRefresh: false,
      guideList: false,
      playList: true,
      eventList: false,
      exhibitionList: false,
      showGenre: false,
      showTrending: false,
      postarray: [],
      isPlaying: false,
      songDetails: {},
      contextId: -1,
      contextData: true,
      songImageUrl: '',
      sondDetails: [],
      currentSongTitle: '',
      currSongArtist: '',
      play: false,
      pause: true,
      Musicindex: -1,
      handle: '',
      spotifyUri: '',
      genrearray: [],
      loadingarray: false,
      favArray: [],
      height: 0,
      progress: 0,
      showCreatepost: false,
      headerShown: true,
      Genre: [],
      status: false,
      istastemaker: false,
      platform: '',
      selectetab: 'MyProfile',
      songName: '',
      artistName: '',
      imageUrl: false,
      showNotification: false,
      message: '',
      deletePostId: '',
      playlistsearchList: [],
      appleMusicPlaylist:[],
      favGenre: [],
      userFollowing: 0,
      userFollower: 0,
      indexId: 0,
      sonMedialUrl: '',
      profileSongResponse: [],
      pageNo: 1,
      totdalNumberOfPage: 15,
    }

    this.labelTitle = configJSON.labelTitle;

    runEngine.attachBuildingBlock(this as IBlock, this.subScribedMessages)
  }


  async componentDidMount() {
    const form = this.context.platform
    this.showPlaylist()
    this.setState({ platform: form })

    this.setState({ profioleFeedPostList: [] })
    this.getProfilePostListApi()
    this.getProflieApi()
   
    this.handlegenre()
    this.handleFavList()
    this.favGenrelistApi()
    this.setState({
      coverImage: this.context.userProfileData.coverPic,
      profileImage: this.context.userProfileData.photoUrl,
      userName: this.context.userProfileData.userName,

    })
    this.focusListener = this.props.navigation.addListener('didFocus', () => {
      this.favGenrelistApi()
    })


    Apptheme.homenavigation = true;
  }

  async componentWillUnmount() {
    this.focusListener.remove()   
  }


  async receive(from: string, message: Message) {

    if (
      getName(MessageEnum.RestAPIResponceMessage) === message.id &&
      this.getProfilePostListApiCallid !== null &&
      this.getProfilePostListApiCallid ===
      message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
    ) {
      this.getProfilePostListApiCallid = null

      var responseJson = message.getData(
        getName(MessageEnum.RestAPIResponceSuccessMessage),
      )
      this.setState({profioleFeedPostList: [], postarray: []})
      if (responseJson && !responseJson.errors && !responseJson.data.errors) {
      
        this.setState({ loadingarray: false })
       
        this.setState({
          profioleFeedPostList: responseJson?.data ? responseJson.data : [],


        })
        var resultpost = this.state.profioleFeedPostList.filter(obj => {
          return obj.attributes.is_comment === false
        })

        this.setState({
          postarray: resultpost,
          handleRefresh: false,
        })

      } else if (responseJson.errors) {
        this.setState({ loader: false, })

      } else {


        this.parseApiErrorResponse(responseJson.data)
      }
    }  

    if (
      getName(MessageEnum.RestAPIResponceMessage) === message.id &&
      this.getfavPostListApiCallid !== null &&
      this.getfavPostListApiCallid ===
      message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
    ) {
      this.getfavPostListApiCallid = null

      var responseJson = message.getData(
        getName(MessageEnum.RestAPIResponceSuccessMessage),
      )

      if (responseJson && !responseJson.errors && !responseJson.data.errors) {
        this.setState({ loadingarray: false })
        this.setState({
          favArray: responseJson?.data ? responseJson.data : [],


        })

      } else if (responseJson.errors) {
        this.setState({ loader: false, })

      } else {


        this.parseApiErrorResponse(responseJson.data)
      }
    }  
    if (
      getName(MessageEnum.RestAPIResponceMessage) === message.id &&
      this.getAppleMusicplaylistApiCallId !== null &&
      this.getAppleMusicplaylistApiCallId ===
      message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
    ) {
      this.getAppleMusicplaylistApiCallId = null;

      let responseJson = message.getData(
        getName(MessageEnum.RestAPIResponceSuccessMessage)
      );
    //  this.context.PlayListArrayAdded(responseJson);

    console.log("check apple playlist-->",responseJson);
this.setState({error:responseJson.error})
      if (responseJson.data.length === 0) {

        this.setState({ appleMusicPlaylist: [] });
       
      }else{

        this.setState({ appleMusicPlaylist: responseJson.data });
      }
    }

    if (
      getName(MessageEnum.RestAPIResponceMessage) === message.id &&
      this.apiPlaylistSearchGetCall !== null &&
      this.apiPlaylistSearchGetCall ===
      message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
    ) {
      this.apiPlaylistSearchGetCall = null;
    
      const responseJson = message.getData(
        getName(MessageEnum.RestAPIResponceSuccessMessage)
      );
        // Extract relevant data from the response
      const { error, playlist_data } = responseJson;
    
      // Check for token expiration error
      if (error === 'The access token expired') {
        console.log("playlistdata in Context", this.context.spotifyplaylistArray);
        this.setState({ error });
      } else {
        console.log("playlistdata in api", responseJson);
      }
    
      // Determine the playlist data to use
      const playlistToUse = error === 'The access token expired' ? this.context.spotifyplaylistArray?.playlist_data : playlist_data;
    
      // Update state variables
      this.context.PlayListArrayAdded(responseJson);
      this.setState({
        loader: false,
        loaderPlaylist: false,
        playlistsearchList: this.state.playlistsearchList.concat(playlistToUse),
        pageNo: this.state.pageNo + 1,
        totdalNumberOfPage: error === 'The access token expired' ? this.context.spotifyplaylistArray?.total_pages : responseJson.total_pages
      });
    
      // Check if the playlist data is undefined, null, or an empty array
      if (!playlistToUse || playlistToUse.length === 0) {
        this.setState({ playlistsearchList: [] });
      }
    }
    

    if (
      getName(MessageEnum.RestAPIResponceMessage) === message.id &&
      this.favgenrelistCallIdd !== null &&
      this.favgenrelistCallIdd ===
      message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
    )  
    {
      this.favgenrelistCallIdd = null

      var responseJson = message.getData(
        getName(MessageEnum.RestAPIResponceSuccessMessage),
      )
       
      if (responseJson && !responseJson.errors) {

        this.setState({ favGenre: responseJson.data })
      
      } else if (responseJson.errors) {
        this.setState({ favGenre: [] })
        this.setState({ loader: false })


      } else {
        this.parseApiErrorResponse(responseJson.data)
      }
    }   

    if (
      getName(MessageEnum.RestAPIResponceMessage) === message.id &&
      this.apiSendRepostId !== null &&
      this.apiSendRepostId ===
      message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
    ) {
      this.apiSendRepostId = null

      var responseJson = message.getData(
        getName(MessageEnum.RestAPIResponceSuccessMessage),
      )

      if (responseJson && !responseJson.errors && !responseJson.data.errors) {
        this.setState({ profioleFeedPostList: [] })
        this.getProfilePostListApi()
        this.getProflieApi()
        this.handlegenre()

      } else if (responseJson.errors) {
        this.setState({ loader: false, })

      } else {


        this.parseApiErrorResponse(responseJson.data)
      }
    }  

    if (
      getName(MessageEnum.RestAPIResponceMessage) === message.id &&
      this.deletePostApiCallId != null &&
      this.deletePostApiCallId === message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
    ) {

      var responseJson = message.getData(
        getName(MessageEnum.RestAPIResponceSuccessMessage)
      );
      if (responseJson !== undefined && responseJson?.errors === undefined) {

        this.getProfilePostListApi()
        this.setState({ showNotification: true, message: 'Post Deleted' })

        setTimeout(() => {
          this.setState({ message: '' })
        }, 5000)

        // you have response 
      } else {
        var errorReponse = message.getData(
          getName(MessageEnum.RestAPIResponceErrorMessage)
        );
        this.parseApiCatchErrorResponse(errorReponse);
      }

    }

    if (
      getName(MessageEnum.RestAPIResponceMessage) === message.id &&
      this.getProfileApiCallId !== null &&
      this.getProfileApiCallId ===
      message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
    ) {
      this.getProfileApiCallId = null

      var responseJson = message.getData(
        getName(MessageEnum.RestAPIResponceSuccessMessage),
      )  

      if (
        responseJson &&
        !responseJson.errors &&
        responseJson.data.attributes
      ) {
        this.setState({ loading: false })
        this.getProfileSuccessCallBack(responseJson)
      } else {

        this.getProfileFailureCallBack(responseJson)

      }

    }
    
    if (
      getName(MessageEnum.RestAPIResponceMessage) === message.id &&
      this.apiGenreSearchGetCall != null &&
      this.apiGenreSearchGetCall === message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
    ) {
      this.setState({ loader: false })
      var responseJson = message.getData(
        getName(MessageEnum.RestAPIResponceSuccessMessage)
      );

      if (responseJson !== undefined && responseJson?.errors === undefined) {

        this.setState({ genrearray: responseJson.data })


      } else {
        var errorReponse = message.getData(
          getName(MessageEnum.RestAPIResponceErrorMessage)
        );

        this.parseApiCatchErrorResponse(errorReponse);
      }

    }




  }
  async componentWillUnmount() {
    this.navigationgobackListener.remove()
  }


  refresh = () => {
    if (this.state.profioleFeedPostList.length !== undefined) {
      if (this.state.profioleFeedPostList !== []) {
        this.setState({
          guideList: true,
          eventList: false,
          exhibitionList: false,
          showGenre: false,
          showTrending: false,
          playList: false,


        });
        this.setState({ profioleFeedPostList: [] })
        this.getProfilePostListApi()
        this.getProflieApi()
        this.handlegenre()
      }
    }

  }



showPlaylist = async () => {
 let platform = await this.context.platform && await getStorageData('PLATFORM')
if(platform === 'apple'){
  this._appleMusicPlaylist()
 }else
this._searchPlaylistFunction(this.state.pageNo)
}



  ShowHideTextComponentView = () => {
    this.setState({ status: !this.state.status })
  }

  playPauseSong = () => {
    this.context.nextDisabled(true)
    
    if (this.context?.playSongData?.songMediaUrl !== '' && this.context?.playSongData?.songMediaUrl !== undefined && this.context?.playSongData?.songMediaUrl !== null) {
      if (this.context.isplay === false) {
        this.context.playData(true)
        SoundPlayer.pause()
      } else if (this.context.isplay === true) {
        if (this.state.progress > 0.9) {
          this.context.playData(false)
          console.log("eneneprger", this.context?.playSongData)
          SoundPlayer.playUrl(this.context?.playSongData?.songMediaUrl)
        } else if (this.state.progress < 0.9) {
          SoundPlayer.resume()
          this.context.playData(false)
        }
      }
    } else {
      this.context.playData(true)
    }
  }

  toggleTabsButtons = (index: any) => {
    if (index === 0) {
      this.setState({
        guideList: true,
        eventList: false,
        exhibitionList: false,
        showGenre: false,
        showTrending: false,
        playList: false,

      });
    } else if (index === 1) {
      this.setState({
        playList: true,
        guideList: false,
        eventList: false,
        exhibitionList: false,
        showGenre: false,
        showTrending: false,
        loadingarray: false
      });

    } else if (index === 2) {
      this.setState({
        guideList: false,
        eventList: true,
        exhibitionList: false,
        showGenre: true,
        showTrending: false,
        playList: false,
        loadingarray: false
      });
    } else if (index === 3) {
      this.setState({
        guideList: false,
        eventList: false,
        exhibitionList: true,
        showTrending: false,
        showGenre: false,
        playList: false,
        loadingarray: false
      });
    }
  };

  getProfileSuccessCallBack = async (responseJson: any) => {
    this.setState({
      loading: false,
      selectedSongTrack_idInput:responseJson?.data.attributes.spotify_track_id,
      userName: responseJson.data.attributes.fullname,
      aboutText: responseJson.data.attributes.bio,
      profileImage: responseJson.data.attributes.profile_pic,
      coverImage: responseJson.data.attributes.cover_pic,
      userIdFromApi: responseJson?.data?.id,
      accounID: responseJson?.data?.id,
      is_following: responseJson?.data?.is_following,
      handle: responseJson.data.attributes.user_name,
      Genre: responseJson.data.attributes.genres.data,
      istastemaker: responseJson.data.attributes.is_a_tastemaker,
      songName: responseJson.data.attributes.song_name,
      artistName: responseJson.data.attributes.artist_name,
      imageUrl: responseJson.data.attributes.image_url,
      userFollowing: responseJson.data.attributes.followings,
      userFollower: responseJson.data.attributes.followers,
      sonMedialUrl: responseJson.data.attributes.media_url,
      indexId: responseJson.data.id,
      profileSongResponse: [responseJson?.data?.attributes]
    })
    this.setState({
      songDetails: {
        songName: responseJson.data.attributes.song_name ? responseJson.data.attributes.song_name : '',
        artistName: responseJson.data.attributes.artist_name ? responseJson.data.attributes.artist_name : '',
        songImageUrl: responseJson.data.attributes.image_url ? responseJson.data.attributes.image_url : '',
        songMediaUrl: responseJson.data.attributes.media_url ? responseJson.data.attributes.media_url :'',
        spotify_post_id: responseJson.data.attributes.spotify_track_id ? responseJson.data.attributes.spotify_track_id : '',
        type:'post'
      }
    })
  }

  handleEditProfile = () => {
    this.RBSheet.open()
  }

  handlecloseEditProfile = () => {
    this.RBSheet.close()
    this.getProflieApi()
  }


  sharePostNotification = () => {
    this.setState({ showNotification: true, message: 'Message Sent' })

    setTimeout(() => {
      this.setState({ showNotification: false, message: '' })
    }, 5000)
  }

  editpost = (item: any) => {
    this.context.homeFocusFunction(false)
    this.props.navigation.navigate('EditPostBlock', {
      editpostdata: item,
    })

  }

  handleDeleteFeedPost = async (deletePostId: any) => {
   
    var feedList = this.state.postarray
    var filterData = feedList.filter((feed : any) => feed.id !== deletePostId)
    this.setState({ postarray :[]})
    this.setState({ postarray: filterData,deletePostId:'' })

    var favList = this.state.favArray
    var filterData = favList.filter((feed : any) => feed.id !== deletePostId)
    this.setState({ favArray :[]})
    this.setState({ favArray: filterData,deletePostId:'' })

    this.setState({ deletePostId: deletePostId, handleRefresh: true })
    const _postId = deletePostId

    const _token = await StorageProvider?.get('USER_TOKEN')
    this.setState({ loader: true })
    const header = {
      'Content-Type': 'application/json',
      token: _token,
    }

    const requestMessage = new Message(
      getName(MessageEnum.RestAPIRequestMessage),
    )

    this.deletePostApiCallId = requestMessage.messageId

    requestMessage.addData(
      getName(MessageEnum.RestAPIResponceEndPointMessage),
      configJSON.deletePostApiEndPoint + `/${_postId}`,
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestHeaderMessage),
      JSON.stringify(header),
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestMethodMessage),
      configJSON.httpDeleteType,
    )

    runEngine.sendMessage(requestMessage.id, requestMessage)
    return true
  }


  getProfilePostListApi = async () => {

   
    const _token = await getStorageData('USER_TOKEN')

    const _localEMail = await getStorageData('USER_DETAILS')


    let _userEmail = this.props.navigation.state.params?.anotherProfileEmail
      ? this.props.navigation.state.params?.anotherProfileEmail
      : this.props.navigation.state.params?.fromMyProfile
        ? JSON.parse(_localEMail).email
        : JSON.parse(_localEMail).email


    this.setState({ loadingarray: true })

    const header = {
      'Content-Type': 'multipart/form-data',
      token: _token,
    }


    const formData = new FormData()
    formData.append('account[email]', _userEmail)


    const requestMessage = new Message(
      getName(MessageEnum.RestAPIRequestMessage),
    )
    this.getProfilePostListApiCallid = requestMessage.messageId
    requestMessage.addData(
      getName(MessageEnum.RestAPIResponceEndPointMessage),
      configJSON.getProfilePostListApiEndPoint,
    )
    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestHeaderMessage),
      JSON.stringify(header),
    )
    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestBodyMessage),
      formData,
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestMethodMessage),
      configJSON.httpPostType,
    )
    runEngine.sendMessage(requestMessage.id, requestMessage)
  }



  handlegenre = async () => {

    this.setState({ loader: true })
    const token = await getStorageData("USER_TOKEN")

    const header = {
      token,
    };

    const requestMessage = new Message(
      getName(MessageEnum.RestAPIRequestMessage)
    );

    this.apiGenreSearchGetCall = requestMessage.messageId;
    requestMessage.addData(
      getName(MessageEnum.RestAPIResponceEndPointMessage),
      'bx_block_hashtags/genre_follower/system_genre'

    );



    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestHeaderMessage),
      JSON.stringify(header)
    );

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestMethodMessage),
      configJSON.httpGetType
    );

    runEngine.sendMessage(requestMessage.id, requestMessage);
  }


  handleFavList = async () => {

    this.setState({ loadingarray: true })
    const token = await getStorageData("USER_TOKEN")

    const header = {
      token,
    };

    const requestMessage = new Message(
      getName(MessageEnum.RestAPIRequestMessage)
    );

    this.getfavPostListApiCallid = requestMessage.messageId;
    requestMessage.addData(
      getName(MessageEnum.RestAPIResponceEndPointMessage),
      '/accounts/favourite_posts'

    );



    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestHeaderMessage),
      JSON.stringify(header)
    );

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestMethodMessage),
      configJSON.httpGetType
    );

    runEngine.sendMessage(requestMessage.id, requestMessage);
  }
  favGenrelistApi = async () => {
    const token = await StorageProvider?.get('USER_TOKEN')

    const header = {
      'Content-Type': 'multipart/form-data',
      token: token,
    }
    const requestMessage = new Message(
      getName(MessageEnum.RestAPIRequestMessage),
    )

    this.favgenrelistCallIdd = requestMessage.messageId

    requestMessage.addData(
      getName(MessageEnum.RestAPIResponceEndPointMessage),
      '/bx_block_hashtags/genre_follower/my_genres'
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestHeaderMessage),
      JSON.stringify(header),
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestMethodMessage),
      'GET',
    )

    runEngine.sendMessage(requestMessage.id, requestMessage)
    return true

  }


  _searchPlaylistFunction = async (e: any) => {
    this.setState({ loader: true, loaderPlaylist: true })
    const token = await getStorageData("USER_TOKEN");
    const access = await getStorageData("USER_TOKEN_SPOTIFY")
    let _userId: any = ''
    _userId = await getStorageData('USER_ID')
    const header = {
      'Content-Type': configJSON.categoryMultiApiContentType,
      token,
    };

    let formdata = new FormData()
    formdata.append('spotify_access_token', access)
    formdata.append('page', e)
    formdata.append('per_page',6)
   const requestMessage = new Message(
      getName(MessageEnum.RestAPIRequestMessage)
    );

    this.apiPlaylistSearchGetCall = requestMessage.messageId;
    requestMessage.addData(
      getName(MessageEnum.RestAPIResponceEndPointMessage),
      configJSON.getSpotifyPlaylist + _userId
    );



    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestHeaderMessage),
      JSON.stringify(header)
    );

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestBodyMessage),
      formdata,
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestMethodMessage),
      'POST',
    );

    runEngine.sendMessage(requestMessage.id, requestMessage);
  }
  _appleMusicPlaylist = async (appleid: any) => {
    console.log("I called first");
    
    const token = await StorageProvider?.get('USER_TOKEN');
    const apple_music_token = await getStorageData('APPLE_MUSIC_TOKEN');
    const apple_jwt = await getStorageData('APPLE_JWT_TOKEN')
    console.log('APPLE_MUSIC_TOKEN:  ', apple_music_token);

    const header = {
      'Content-Type': configJSON.categoryApiContentType,
      token: token,
    };
    const Data = {
      developer_token:apple_jwt,
      music_token: apple_music_token,
    
    };

    const requestMessage = new Message(
      getName(MessageEnum.RestAPIRequestMessage)
    );
    this.getAppleMusicplaylistApiCallId = requestMessage.messageId;
    requestMessage.addData(
      getName(MessageEnum.RestAPIResponceEndPointMessage),
      configJSON.getAppleMusicPlaylist,
    );
    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestHeaderMessage),
      JSON.stringify(header)
    );

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestMethodMessage),
      'POST'
    );
    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestBodyMessage),
      JSON.stringify(Data)
    );
    runEngine.sendMessage(requestMessage.id, requestMessage);

    return true;
  };

  getProfileFailureCallBack = (errorResponse: any) => {
    this.setState({ loading: false })
  }
  hastag = (e: any) => {
    this.props.navigation.navigate("FeedBlock", {
      index: 3,
      item: e,
      fromProfile:true
    })
  }
  getProflieApi = async () => {
    this.setState({ loading: true })
    const token = await getStorageData('USER_TOKEN')

    let _userId: any = ''
    _userId = await getStorageData('USER_ID')

    const header = {
      'Content-Type': configJSON.exampleApiContentType,
      token: token,
    }

    const requestMessage = new Message(
      getName(MessageEnum.RestAPIRequestMessage),
    )

    this.getProfileApiCallId = requestMessage.messageId

    requestMessage.addData(
      getName(MessageEnum.RestAPIResponceEndPointMessage),
      `accounts/get_profile/${_userId}`
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestHeaderMessage),
      JSON.stringify(header),
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestMethodMessage),
      'GET',
    )


    runEngine.sendMessage(requestMessage.id, requestMessage)
    return true
  }

  handleMenuIcon = () => {
    this.props.navigation.toggleDrawer()
  }

  handleRepost = async (itemID: any) => {

    this.setState({ loader: true, handleRefresh: true })
   
    const token = await getStorageData('USER_TOKEN')
    const _userId = await getStorageData('USER_ID')

    const formData = new FormData()
    formData.append('[data][post_id]', itemID)
    formData.append('[data][account_id]', _userId)
    formData.append('[data][message]', '')
    formData.append('token', token)

    // console.log('body of repost api==>>', formData)
    const header = {
      'Content-Type': 'multipart/form-data',
      token,
    }
    const requestMessage = new Message(
      getName(MessageEnum.RestAPIRequestMessage),
    )

    this.apiSendRepostId = requestMessage.messageId

    requestMessage.addData(
      getName(MessageEnum.RestAPIResponceEndPointMessage),
      configJSON.doRepostEndPoint,
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestHeaderMessage),
      JSON.stringify(header),
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestBodyMessage),
      formData,
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestMethodMessage),
      configJSON.httpPostType,
    )

    runEngine.sendMessage(requestMessage.id, requestMessage)

    return true
  }
  _checkPlayMusic = async (e: any) => {
    
    this.context.playDataAll(this.state.profileSongResponse);  

    const platform = this.context.platform
    const AppleMusic = await StorageProvider.get('APPLE_MUSIC_TOKEN')
    let songList = ['']
    songList.splice(0, 0, this.state.sonMedialUrl)
    this.context.playDataAll(this.props?.array);
    console.log("ewrwrww",this.context.playSongDataAll)
    this.context.indexIdData(this.props?.index)
    console.log("qazwsxedcrfv",this.context?.indexId)
    if (this.context.contextId !== this.state.indexId) {
      console.log('ONE')
      this.context.playData(false)
      this.context.contextIdData(this.state.indexId)
      this.context.songData(this.state.songDetails)
      this.setState({ songDuration: null })
      this.setState({ songDuration: null })

      if (platform === 'apple') {
        this.context.addPosition(this.state.itemIndex)
        try {
          await NativeModules.AppleMusicPlayer.configurePlayer(
            AppleMusic,
            songList, 0);

        } catch (error) {
          console.log(error, 'Error Of ISO Playback');
        }

      } else {
        SoundPlayer.playUrl(this.state.sonMedialUrl)
      }



    } else {
      if (this.context.contextId === this.state.indexId) {
        if (this.context.isplay) {
          console.log(this.context.isplay, "TWO")
          this.setState({ songDuration: null })
          this.context.playData(false)
          this.context.contextIdData(this.state.indexId)
          this.context.songData(this.state.songDetails)
          if (platform === 'apple') {
            this.context.addPosition(this.state.itemIndex)
            try {

              await NativeModules.AppleMusicPlayer.configurePlayer(
                AppleMusic,
                songList, 0);

            } catch (error) {
              console.log(error, 'Error Of ISO Playback');
            }

          } else {
            SoundPlayer.playUrl(this.state.sonMedialUrl)
          }


        } else {
          console.log(this.context.isplay, 'THREE')
          this.context.playData(true)
          this.context.contextIdData(this.state.indexId)
          this.context.songData(this.state.songDetails)

          if (platform === 'apple') {
            this.context.addPosition(this.state.itemIndex)
            try {
              await NativeModules.AppleMusicPlayer.pause();

            } catch (error) {
              console.log(error, 'Error Of ISO Playback');
            }

          } else {

            SoundPlayer.pause()
          }


        }
      }
      else {
        this.context.playData(true)
        this.context.contextIdData(this.state.indexId)
        this.context.songData(this.state.songDetails)
        if (platform === 'apple') {
          this.context.addPosition(this.state.itemIndex)
          try {
            await NativeModules.AppleMusicPlayer.pause();

          } catch (error) {
            console.log(error, 'Error Of ISO Playback');
          }

        } else {

          SoundPlayer.pause()
        }
      }

    }
    this.context.nextDisabled(true)
    let likedSongData = this.context.likedSongList?.filter((id: string) => id === this.state.selectedSongTrack_idInput)
    likedSongData?.length === 0 ?  this.context.liked(false) :  this.context.liked(true)
  }

  _handlePostMore = () => {
    if (this.state.totdalNumberOfPage >= (this.state.pageNo + 1)) { 
      this._searchPlaylistFunction(this.state.pageNo + 1)  
    }
  }
  navigateFollowing = () => {
    this.props.navigation.navigate("Following", {id: this.state.userIdFromApi})
  }

  navigateFollower = () => {
    this.props.navigation.navigate("Followers", {id: this.state.userIdFromApi})
  }
}
// Customizable Area End