feedblockcontroller
unknown
plain_text
2 years ago
72 kB
8
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 { Alert, Platform, BackHandler, AppState } from 'react-native'
import { runEngine } from '../../../../framework/src/RunEngine'
import { spotifyLogout } from '../../../../framework/src/Helpers'
import { CommonContext } from '../../../../components/src/CommonContextProvider'
import {
ActionCable,
Cable,
} from '@kesha-antonov/react-native-action-cable'
import SoundPlayer from 'react-native-sound-player'
import { getStorageData, setStorageData } from '../../../../framework/src/Utilities'
import Apptheme from '../../../HamburgerMenu/src/Apptheme';
import OneSignal from 'react-native-onesignal'
import {
auth as SpotifyAuth,
remote,
ApiScope,
} from 'react-native-spotify-remote';
import { chatBaseURL } from './FeedBlock'
export const configJSON = require('../config')
export interface Props {
navigation: any
id: string
route: any
}
interface S {
cableCon: any;
notificationcableCon: any;
index:number;
showfeed: boolean
showCreatepost: boolean
progress: any
indeterminate: boolean
loading: boolean
isSelected: boolean
storydata: any
guideList: boolean
eventList: boolean
exhibitionList: boolean
enablePasswordField: boolean
checkedRememberMe: boolean
placeHolderEmail: string
placeHolderPassword: string
imgPasswordVisible: any
labelHeader: string
btnTxtLogin: string
labelRememberMe: string
btnTxtSocialLogin: string
labelOr: string
showGenre: any
showTrending: boolean;
feedPostList: any
showStory: boolean
showStory1: boolean;
showDotsModal: boolean
showReportModal: boolean
toggleStar: boolean
likePostId: any
reportList: any
getAllPostCommentList: any
handleRefresh: any
getReportList: any
getPostRepostList: any
userDetails: any
userHandleName: any
loader: boolean
currentSongTitle: any
currSongArtist: any
currSongArtwork: any
play: boolean
pause: boolean
isapple: boolean
itemData: any
isPlaying: boolean
fullSongDetails: any;
Musicindex: number;
songImage: any;
isLastPlayed: boolean;
userProfilePic: any;
userProfileUpload: any;
takeAPicture: any;
showModal: boolean;
Artist: string;
bandname: string;
streaming_type: string;
img_path: any;
storyimageurl: any;
storymediaurl: any;
storybandname: any;
storyartist: any;
storyStreaming_type: any;
audiofile: any;
storyarray: any;
profilepicture: any;
lastPlayedSong: any;
isFetching: boolean;
postPageNuber: number;
isLoading: boolean;
totdalNumberOfPage: number;
noMorePosts: boolean,
isPostFooterLoading: boolean;
contextData: boolean;
contextId: number;
refState: any;
sondDetails: any;
songImageUrl: string;
isPlayFinished: boolean;
playUrl: string;
isPlayingContext: boolean;
hidestory: boolean;
spotifyUri: string;
storyuserdata: any;
selectedRadio: any;
hardwareBackAlert: boolean;
fullstoryArray: any;
popularity: string;
time: string
Clickedstory: boolean;
songDuration: any;
playbackPosition: any;
sliderValue: number;
sliderDuration: number;
duration: number;
showMainGenre: boolean;
hashTagId: any;
hastagName: string;
isFollowing: boolean;
vibestationsArray: any;
subscribeArray: any;
ourStationArray: any;
showNotification: boolean;
message: string;
platform: string;
showTrendingFilter: boolean;
showGenreFilter: boolean;
selectedtab: string;
showisFollowingGenre: boolean;
passeditem: any;
showFeedFilter: boolean;
showRadioFilter: boolean;
featureList: any;
timefilter: string;
popularityfilter: string;
contentfilter: string;
feedloading: boolean;
deletePostId: any;
pageNo: any;
actionCable1: any;
notificationActionCable1: any;
trendingArray: any;
GenretagList: any;
routes: any;
tabs:string
}
interface SS {
id: any
}
export default class FeedBlockController extends BlockComponent<Props, S, SS> {
actionCable: any;
repostNotificationAPIcall: any;
StationlistCallId: any;
backHandler: any
isHomeFocusState: boolean
getNewTokenForSpotify: any;
timeOfSeek: any
unfollowingGenre: any;
followingGenre: any;
apiEmailLoginCallId: string = ''
validationApiCallId: string = ''
getPostListApiCallId: any
getEndPostListApiCallId: any
getPostListApiForRefreshCallId: any
spotifyLikedSongList: any
getPostRepostListCallId: any
createLikeApiCallId: any
createDisLikeApiCallId: any
getReportListApiCallId: any
deleteCommentApiCallId: any
getStoryAccountListApiCallId: any
deletePostApiCallId: any
ReportPostApiCallId: any
apiSendRepostId: any
apiSendStoryId: any
getStoryListApiCallId: any
refScrollToTop: any;
focusListener: any;
aRef: any
pauseInterval: any;
_onFinishedPlayingSubscription: any;
_onFinishedLoadingSubscription: any;
_onFinishedLoadingFileSubscription: any;
_onFinishedLoadingURLSubscription: any;
apiFeedApi: any;
emailReg: RegExp
labelTitle: string = ''
RBSheet: any
RBSheet1: any
spotifyConfig: any
getSpotifyRefreshToken: any;
apiSongsTrendingPost: any;
genrelistCallId: any;
static contextType = CommonContext;
// Customizable Area End
constructor(props: Props) {
super(props)
this.receive = this.receive.bind(this)
// Customizable Area Start
this.subScribedMessages = [
getName(MessageEnum.CountryCodeMessage),
getName(MessageEnum.RestAPIResponceMessage),
getName(MessageEnum.ReciveUserCredentials),
]
this.state = {
message: '',
cableCon: null,
notificationcableCon: null,
vibestationsArray: [],
subscribeArray: [],
ourStationArray: [],
actionCable1: [],
notificationActionCable1: [],
showfeed: false,
showCreatepost: false,
isHomeFocusState: true,
progress: 0,
indeterminate: false,
loading: false,
guideList: false,
eventList: false,
exhibitionList: false,
enablePasswordField: true,
checkedRememberMe: false,
placeHolderEmail: configJSON.placeHolderEmail,
placeHolderPassword: configJSON.placeHolderPassword,
imgPasswordVisible: configJSON.imgPasswordVisible,
labelHeader: configJSON.labelHeader,
btnTxtLogin: configJSON.btnTxtLogin,
labelRememberMe: configJSON.labelRememberMe,
btnTxtSocialLogin: configJSON.btnTxtSocialLogin,
labelOr: configJSON.labelOr,
showDotsModal: false,
showReportModal: false,
showStory: true,
showStory1: false,
songImage: '',
storydata: [
],
showGenre: false,
showTrending: false,
feedPostList: [],
isSelected: false,
toggleStar: false,
getPostRepostList: [],
likePostId: 0,
reportList: [],
getAllPostCommentList: [],
handleRefresh: false,
getReportList: [],
userHandleName: '',
userDetails: [],
loader: false,
currentSongTitle: '',
currSongArtist: '',
currSongArtwork: '',
play: false,
pause: true,
isapple: false,
itemData: null,
isPlaying: false,
fullSongDetails: {},
Musicindex: -1,
isLastPlayed: true,
userProfileUpload: '',
userProfilePic: '',
takeAPicture: '',
showModal: false,
Artist: '',
bandname: '',
streaming_type: '',
img_path: '',
storyimageurl: "",
storymediaurl: "",
storybandname: "",
storyartist: "",
storyStreaming_type: "",
audiofile: '',
storyarray: [],
profilepicture: '',
lastPlayedSong: '',
isFetching: false,
postPageNuber: 1,
isLoading: false,
totdalNumberOfPage: 15,
noMorePosts: false,
isPostFooterLoading: false,
contextData: true,
contextId: -1,
refState: [],
sondDetails: [],
songImageUrl: '',
isPlayFinished: false,
isPlayingContext: false,
storyuserdata: [],
hidestory: false,
spotifyUri: '',
hardwareBackAlert: false,
selectedRadio: [],
Clickedstory: false,
popularity: 'top',
time: 'today',
content: 'following',
fullstoryArray: [],
songDuration: null,
playbackPosition: null,
sliderValue: 0,
sliderDuration: 0,
duration: 0,
showMainGenre: false,
hashTagId: 0,
hastagName: '',
isFollowing: false,
showNotification: false,
platform: '',
showTrendingFilter: false,
selectedtab: 'Feed',
showisFollowingGenre: false,
passeditem: [],
showGenreFilter: false,
showFeedFilter: false,
showRadioFilter: false,
featureList: [{ id: 1 }, { id: 2 }],
timefilter: 'today',
popularityfilter: 'new',
contentfilter: 'following',
feedloading: false,
deletePostId: '',
pageNo: 1,
trendingArray: [],
GenretagList: [],
index: 0,
routes: [
{ key: 'first', title: 'First' },
{ key: 'second', title: 'Second' },
],
tabs:'featured'
}
this.spotifyConfig = {
clientID: '3470398eb99c475389fd4f93148674f2',
redirectURL: 'com.VibeSocialMusic://EmailAccountLoginBlock',
scopes: [
ApiScope.PlaylistReadPrivateScope,
ApiScope.PlaylistReadCollaborativeScope,
ApiScope.PlaylistModifyPublicScope,
ApiScope.PlaylistModifyPrivateScope,
ApiScope.UserFollowReadScope,
ApiScope.UserFollowModifyScope,
ApiScope.UserLibraryReadScope,
ApiScope.UserLibraryModifyScope,
ApiScope.UserReadEmailScope,
ApiScope.UserReadPrivateScope,
ApiScope.UserTopReadScope,
ApiScope.UGCImageUploadScope,
ApiScope.StreamingScope,
ApiScope.AppRemoteControlScope,
ApiScope.UserReadPlaybackStateScope,
ApiScope.UserReadPlaybackPosition,
ApiScope.UserModifyPlaybackStateScope,
],
}
this.emailReg = new RegExp('')
this.labelTitle = configJSON.labelTitle
runEngine.attachBuildingBlock(this as IBlock, this.subScribedMessages)
}
// componentDidUpdate(previousProps) {
// if (previousProps.navigation?.state?.params !== this.props?.navigation?.state?.params) {
// if (this.props.navigation?.state?.params?.index == 3) {
// this.setState({
// showfeed: false,
// guideList: false,
// eventList: true,
// exhibitionList: false,
// showGenre: true,
// showTrending: false,
// showStory: false,
// showisFollowingGenre: true,
// passeditem: this.props?.navigation?.state?.params?.item !== undefined && this.props?.navigation?.state?.params?.item !== null ? this.props?.navigation?.state?.params?.item : null
// })
// }
// else {
// this.StationlistApi()
// }
// }
// this._getlocationPermision()
// if (this.context.isHomeFocus !== this.state.isHomeFocusState) {
// if (!this.context.isHomeFocus) {
// BackHandler.removeEventListener('hardwareBackPress', this.handleOpen)
// }
// }
// }
async componentDidMount() {
this.getPostListApi()
this.GenrelistApi()
this._fetchSongsTrendingApi()
// this._notificationCheckActionCableConnect()
// this._spotifyToken()
// this._checkActionCableConnect()
// this.getLikedSongList()
// this.getSpotifyTokenForHours()
// if (this.props.navigation?.state?.params?.index == 1) {
// this.setState({
// showfeed: true,
// guideList: true,
// eventList: false,
// exhibitionList: false,
// showGenre: false,
// showTrending: false,
// showStory: false,
// })
// }
// if (this.props.navigation?.state?.params?.index == 3) {
// this.setState({
// showfeed: false,
// guideList: false,
// eventList: true,
// exhibitionList: false,
// showGenre: true,
// showTrending: false,
// showStory: false,
// })
// }
// const platform = await getStorageData('PLATFORM')
// this.setState({ platform: platform })
// this.setState({ feedPostList: [] })
// this.setState({ isLoading: true })
// this.setState({ postPageNuber: 1 })
// this.setState({ storyuserdata: [] })
// this.setState({ loading: true })
// this.setState({ isPlayingContext: !this.context.isplay })
// this.StationlistApi()
// this.getPostListApi()
// this._getMusicT_info()
// this.getReportListApi()
// this.getUserData()
// this.getPostRepost()
// this.handleplatform()
// this.GenrelistApi()
// this.context.homeFocusFunction(true)
// this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleOpen)
// this._onFinishedPlayingSubscription = SoundPlayer.addEventListener('FinishedPlaying', ({ success }) => {
// this.context.playData(!this.context.isplay)
// this.context.isLastPlayedData(true)
// this.setState({ contextData: !this.state.contextData })
// this.setState({ isPlayFinished: true })
// })
// AppState.addEventListener('change', this._handleAppStateChange);
// this.setState({ showNotification: false })
// this.setState({ message: '' })
// this.focusListener = this.props.navigation.addListener('didFocus', () => {
// if (this.props.navigation?.state?.params?.index !== undefined && this.props.navigation?.state?.params?.index === 7) {
// this.Quotednotification()
// }
// if (this.props.navigation?.state?.params?.index !== undefined && this.props.navigation?.state?.params?.index === 5) {
// this.setState({
// message: 'Post Successful',
// showfeed: true,
// guideList: true,
// eventList: false,
// exhibitionList: false,
// showGenre: false,
// showTrending: false,
// showStory: false,
// showNotification: true,
// postPageNuber: 1,
// feedPostList: []
// })
// setTimeout(() => {
// this.setState({ message: '', showNotification: false })
// }, 5000)
// this.getPostListApi()
// }
// if (this.props.navigation?.state?.params?.index !== undefined && this.props.navigation?.state?.params?.index === 10) {
// this.setState({
// showfeed: false,
// guideList: false,
// eventList: false,
// exhibitionList: false,
// showGenre: false,
// showTrending: false,
// showStory: true,
// showNotification: false
// })
// }
// })
}
async receive(from: string, message: Message) {
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.StationlistCallId !== null &&
this.StationlistCallId ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.StationlistCallId = null;
const responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage)
);
if (responseJson && !responseJson.errors) {
this.setState({
vibestationsArray:
responseJson.vibe_stations.data.length > 0
? responseJson.vibe_stations.data.reverse()
: [],
});
this.context.addVibeStations(responseJson.vibe_stations.data.reverse())
this.setState({ loader: false });
} else if (responseJson.errors) {
this.setState({
vibestationsArray: [],
ourStationArray: [],
subscribeArray: [],
});
this.setState({ loader: false });
} else {
this.parseApiErrorResponse(responseJson.data);
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.getNewTokenForSpotify != null &&
this.getNewTokenForSpotify === message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage)
);
if (responseJson !== undefined && responseJson?.errors === undefined) {
// console.log(responseJson.data.attributes.spotify_access_token, "spotify_access_token")
this._spotifyAccessToken(responseJson)
} else {
var errorReponse = message.getData(
getName(MessageEnum.RestAPIResponceErrorMessage)
);
console.log(responseJson)
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.apiSendRepostId !== null &&
this.apiSendRepostId ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.apiSendRepostId = null
this.setState({ loader: false })
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson && !responseJson.errors && !responseJson?.data?.errors) {
this.notification()
} else if (responseJson?.errors) {
this.setState({ loader: false })
} else {
this.setState({ loader: false })
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) {
var feedList = this.state.feedPostList
var filterData = feedList.filter((feed: any) => feed.id !== this.state.deletePostId)
this.setState({ feedPostList: filterData, deletePostId: '' })
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.ReportPostApiCallId != null &&
this.ReportPostApiCallId === message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage)
);
if (responseJson !== undefined && responseJson?.errors === undefined) {
console.log("report", responseJson)
// you have response
} else {
var errorReponse = message.getData(
getName(MessageEnum.RestAPIResponceErrorMessage)
);
this.parseApiCatchErrorResponse(errorReponse);
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.getPostRepostListCallId !== null &&
this.getPostRepostListCallId ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.getPostRepostListCallId = null
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (
responseJson &&
!responseJson?.errors &&
!responseJson?.data?.errors
) {
this.handlePostRepostResponseSuccessCallback(responseJson)
} else if (responseJson?.errors) {
this.setState({ loader: false })
} else {
this.parseApiErrorResponse(responseJson.data)
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.getReportListApiCallId !== null &&
this.getReportListApiCallId ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.getReportListApiCallId = null
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson && !responseJson.errors && !responseJson.data.errors) {
this.setState({ getReportList: responseJson.data })
await setStorageData('REPORTLIST', JSON.stringify(responseJson.data))
} else if (responseJson.errors) {
console.log("getReportListApiCallId Error")
} else {
this.parseApiErrorResponse(responseJson.data)
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.getPostListApiCallId !== null &&
this.getPostListApiCallId ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.getPostListApiCallId = null
let responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson && !responseJson.errors && !responseJson.data.errors) {
this.setState({ isPostFooterLoading: false })
this.setState({ feedloading: false, feedPostList: [] })
this.setState({
feedPostList: responseJson?.data ? responseJson.data : [],
handleRefresh: false,
})
this.setState({ loader: false })
this.setState({ isFetching: false })
this.setState({ isLoading: false })
this.setState({ totdalNumberOfPage: responseJson.meta.total_pages })
this.setState({ isPostFooterLoading: false })
} else if (responseJson.errors) {
this.setState({ noMorePosts: true })
this.setState({ isPostFooterLoading: false })
this.setState({ loader: false })
this.setState({ feedloading: false })
} else {
this.setState({ noMorePosts: true })
this.setState({ isPostFooterLoading: false })
this.setState({ loader: false })
this.parseApiErrorResponse(responseJson.data)
this.setState({ feedloading: false })
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.getEndPostListApiCallId !== null &&
this.getEndPostListApiCallId ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.getEndPostListApiCallId = null
let responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson && !responseJson.errors && !responseJson.data.errors) {
this.setState({ isPostFooterLoading: false })
this.setState({ feedloading: false, postPageNuber: this.state.postPageNuber + 1 })
this.setState({
feedPostList: responseJson?.data ? this.state.feedPostList.concat(responseJson.data) : [],
handleRefresh: false,
})
this.setState({ loader: false })
this.setState({ isFetching: false })
this.setState({ isLoading: false })
this.setState({ totdalNumberOfPage: responseJson.meta.total_pages })
this.setState({ isPostFooterLoading: false })
} else if (responseJson.errors) {
this.setState({ noMorePosts: true })
this.setState({ isPostFooterLoading: false })
this.setState({ loader: false })
this.setState({ feedloading: false })
} else {
this.setState({ noMorePosts: true })
this.setState({ isPostFooterLoading: false })
this.setState({ loader: false })
this.parseApiErrorResponse(responseJson.data)
this.setState({ feedloading: false })
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.getPostListApiForRefreshCallId !== null &&
this.getPostListApiForRefreshCallId ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.getPostListApiForRefreshCallId = null
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson && !responseJson.errors && !responseJson.data.errors) {
this.setState({ feedloading: false })
this.setState({ totdalNumberOfPage: responseJson?.meta?.total_pages })
this.setState({
feedPostList: responseJson?.data,
handleRefresh: false,
})
this.setState({ loader: false })
this.setState({ isFetching: false })
this.setState({ isLoading: false })
this.setState({ isPostFooterLoading: true })
} else if (responseJson.errors) {
console.log('Post Api Error')
this.setState({ loader: false })
this.setState({ feedloading: false })
} else {
this.setState({ loader: false })
this.parseApiErrorResponse(responseJson.data)
this.setState({ feedloading: false })
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.apiFeedApi !== null &&
this.apiFeedApi ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.apiFeedApi = null
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson && !responseJson.errors && !responseJson.data.errors) {
this.setState({ feedloading: false, feedPostList: [] })
this.setState({
feedPostList: responseJson?.data ? responseJson.data : [],
handleRefresh: false,
loader: false
})
this.setState({ totdalNumberOfPage: responseJson?.meta?.total_pages })
this.context.playDataAll(responseJson?.data ? responseJson.data : [])
} else if (responseJson.errors) {
console.log('Post Api Error')
this.setState({ loader: false })
this.setState({ feedloading: false })
} else {
this.setState({ loader: false })
this.setState({ feedloading: false })
this.parseApiErrorResponse(responseJson.data)
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.repostNotificationAPIcall !== null &&
this.repostNotificationAPIcall ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.repostNotificationAPIcall = null
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson && !responseJson.errors && !responseJson.data.errors) {
// alert('notificationsend')
} else {
this.setState({ loader: false })
this.parseApiErrorResponse(responseJson.data)
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.spotifyLikedSongList !== null &&
this.spotifyLikedSongList ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.spotifyLikedSongList = null
let responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson && responseJson.data) {
if (responseJson?.data.length > 0) {
this.context.likedSongListData(responseJson.data[0].items)
}
}
else if (responseJson.data.error) {
if (responseJson.data.error.message === "The access token expired") {
const session = await SpotifyAuth.authorize(this.spotifyConfig)
await setStorageData("USER_TOKEN_SPOTIFY", session.accessToken)
this.getLikedSongList()
}
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.getSpotifyRefreshToken !== null &&
this.getSpotifyRefreshToken ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.getSpotifyRefreshToken = null
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson && !responseJson.errors) {
await setStorageData('USER_TOKEN_SPOTIFY', responseJson.accessToken.accessToken)
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.apiSongsTrendingPost !== null &&
this.apiSongsTrendingPost ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.apiSongsTrendingPost = null
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson) {
this.setState({ trendingArray: [] })
this.setState({ trendingArray: responseJson.data, loader: false })
this.context.playDataAll(responseJson?.data ? responseJson.data : [])
} else if (responseJson.errors) {
} else {
this.parseApiErrorResponse(responseJson.data)
}
}
if (
getName(MessageEnum.RestAPIResponceMessage) === message.id &&
this.genrelistCallId !== null &&
this.genrelistCallId ===
message.getData(getName(MessageEnum.RestAPIResponceDataMessage))
) {
this.genrelistCallId = null
var responseJson = message.getData(
getName(MessageEnum.RestAPIResponceSuccessMessage),
)
if (responseJson && !responseJson.errors) {
this.setState({ GenretagList: responseJson.data })
} else if (responseJson.errors) {
this.setState({ GenretagList: [] })
} else {
this.parseApiErrorResponse(responseJson.data)
this.setState({ loader: false })
}
}
}
handleTrending = async () => {
this.setState({ showTrendingFilter: !this.state.showTrendingFilter })
}
handleGenre = async () => {
this.setState({ showGenreFilter: !this.state.showGenreFilter })
}
handleFeed = async () => {
this.setState({ showFeedFilter: !this.state.showFeedFilter })
}
handleRadio = async () => {
this.setState({ showFeedFilter: !this.state.showFeedFilter })
}
handleplatform = async () => {
const platform = await getStorageData('PLATFORM')
this.setState({ platform: platform })
console.log("ddddd", platform)
}
async componentWillUnmount() {
// this._onFinishedPlayingSubscription.remove()
// this._onFinishedLoadingSubscription.remove()
// this._onFinishedLoadingURLSubscription.remove()
// this._onFinishedLoadingFileSubscription.remove()
// this.focusListener.remove()
BackHandler.removeEventListener('hardwareBackPress', this.handleOpen)
}
playPauseSong = () => {
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)
}
}
hastag = (e: any) => {
this.setState({ hashTagId: e.attributes.id })
this.setState({ hastagName: e.attributes.name })
this.setState({ isFollowing: e.attributes.is_following })
this.props.navigation.navigate("FeedBlock", {
index: 3,
item: e
})
this.setState({
showfeed: false,
guideList: false,
eventList: true,
exhibitionList: false,
showGenre: true,
showTrending: false,
showStory: false,
showisFollowingGenre: true,
passeditem: e !== undefined && e !== null ? e : null
})
}
handleSearch = () => {
this.context.homeFocusFunction(false)
this.props.navigation.navigate('ElasticSearch')
}
refreshnotification = async (id: any) => {
console.log("repost", id);
const token = await getStorageData('USER_TOKEN')
const headers = {
"Content-Type": "application/json",
token
};
const getLikeNotifyValidation = new Message(
getName(MessageEnum.RestAPIRequestMessage)
);
this.repostNotificationAPIcall = getLikeNotifyValidation.messageId;
getLikeNotifyValidation.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
"bx_block_notifications/app_notifications"
// configJSON.accountsEndPoint
);
getLikeNotifyValidation.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(headers)
);
getLikeNotifyValidation.addData(
getName(MessageEnum.RestAPIRequestMethodMessage),
"POST"
);
const Data = {
"notification": {
// id of person who will receive the notificaiton
"notification_type": "repost", // post, like, play, comment, repost, tag, follow, message,like_comment
"post_id": id, // null if post doesn't exists
"comment_id": null, // null if comment doesn't exists
"app_url": "app/post/10/comment/13" // to easily navigate to the screen in app
}
}
getLikeNotifyValidation.addData(
getName(MessageEnum.RestAPIRequestBodyMessage),
JSON.stringify(Data)
);
runEngine.sendMessage(getLikeNotifyValidation.id, getLikeNotifyValidation);
}
_getlocationPermision = async () => {
if (Platform.OS === "ios") {
// requestLocationPermission()
} else {
}
}
_spotifyAccessToken = async (e: string,) => {
try {
let Spotifytoken = await e?.data?.attributes?.spotify_access_token
await setStorageData('USER_TOKEN_SPOTIFY', Spotifytoken)
console.log("refresh token done", Spotifytoken)
} catch (error) {
alert(error)
}
}
handleSearchPage = () => {
this.props.navigation.navigate("GenreElasticSearch", {
id: this.state.hashTagId,
name: this.state.hastagName,
following: this.state.isFollowing
})
}
handleOpen = () => {
console.log('checking handle open');
this.setState({ hardwareBackAlert: true })
return true
}
handleClose = (status: any) => {
if (status == 'yes') {
this.handleHardwareBackButton()
}
this.setState({ hardwareBackAlert: false })
}
handleHardwareBackButton = () => {
console.log('logOutCheck');
BackHandler.exitApp()
}
handlePostRepostResponseSuccessCallback = async (responseJson: any) => {
this.setState({
getPostRepostList: responseJson?.data,
loader: false,
handleRefresh: false,
})
}
getUserData = async () => {
let data = await getStorageData('USER_DETAILS')
data = JSON.parse(data)
this.setState({ profilepicture: data.profile_pic_url ? data.profile_pic_url : '' })
}
StationlistApi = async () => {
this.setState({ loader: true });
const token = await getStorageData("USER_TOKEN");
const header = {
"Content-Type": configJSON.categoryMultiApiContentType,
token: token,
};
const requestMessage = new Message(
getName(MessageEnum.RestAPIRequestMessage)
);
this.StationlistCallId = requestMessage.messageId;
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
configJSON.doRadioEndPoint + `?page=${this.state.pageNo}&per_page=500000`
);
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header)
);
requestMessage.addData(
getName(MessageEnum.RestAPIRequestMethodMessage),
configJSON.httpGetType
);
runEngine.sendMessage(requestMessage.id, requestMessage);
return true;
};
handleRepost = async (itemID: any) => {
this.refreshnotification(itemID)
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
}
handlecommentScreen = (e: any) => {
this.context.homeFocusFunction(false),
this.props.navigation.navigate('FeedCardCommentScreen', {
commentId: e?.attributes?.id,
itemData: e?.attributes
})
}
bottomBarclass = (value: any) => {
this.setState({ showCreatepost: value })
}
getPostListApi = async () => {
this.setState({ postPageNuber: 1 })
const _token = await getStorageData('USER_TOKEN')
this.setState({ feedloading: true })
const header = {
'Content-Type': configJSON.categoryApiContentType,
token: _token,
}
const requestMessage = new Message(
getName(MessageEnum.RestAPIRequestMessage),
)
this.getPostListApiCallId = requestMessage.messageId
let filterUrl = ""
if (this.state.popularityfilter === 'top')
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber}&per_page=10&filter_by=${this.state.timefilter}&popularity=${this.state.popularityfilter}&content=${this.state.contentfilter}`
else
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber}&per_page=10&popularity=${this.state.popularityfilter}&content=${this.state.contentfilter}`
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
`${filterUrl}`
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header),
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestMethodMessage),
configJSON.httpGetType,
)
runEngine.sendMessage(requestMessage.id, requestMessage)
return true
}
getEndpostListApi = async () => {
const _token = await getStorageData('USER_TOKEN')
const header = {
'Content-Type': configJSON.categoryApiContentType,
token: _token,
}
const requestMessage = new Message(
getName(MessageEnum.RestAPIRequestMessage),
)
this.getEndPostListApiCallId = requestMessage.messageId
let filterUrl = ""
if (this.state.popularityfilter === 'top')
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber + 1}&per_page=10&filter_by=${this.state.timefilter}&popularity=${this.state.popularityfilter}&content=${this.state.contentfilter}`
else
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber + 1}&per_page=10&popularity=${this.state.popularityfilter}&content=${this.state.contentfilter}`
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
`${filterUrl}`
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header),
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestMethodMessage),
configJSON.httpGetType,
)
runEngine.sendMessage(requestMessage.id, requestMessage)
return true
}
getPostListApiForRefresh = async () => {
const _token = await getStorageData('USER_TOKEN')
const header = {
'Content-Type': configJSON.categoryApiContentType,
token: _token,
}
const requestMessage = new Message(
getName(MessageEnum.RestAPIRequestMessage),
)
this.getPostListApiForRefreshCallId = requestMessage.messageId
let filterUrl = ""
if (this.state.popularityfilter === 'top')
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber}&per_page=10&filter_by=${this.state.timefilter}&popularity=${this.state.popularityfilter}&content=${this.state.contentfilter}`
else
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber}&per_page=10&popularity=${this.state.popularityfilter}&content=${this.state.contentfilter}`
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
`${filterUrl}`
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header),
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestMethodMessage),
configJSON.httpGetType,
)
runEngine.sendMessage(requestMessage.id, requestMessage)
return true
}
getfilterPostListApi = async (time: any) => {
const _token = await getStorageData('USER_TOKEN')
this.setState({ feedloading: true })
const header = {
'Content-Type': configJSON.categoryApiContentType,
token: _token,
}
const requestMessage = new Message(
getName(MessageEnum.RestAPIRequestMessage),
)
this.getPostListApiCallId = requestMessage.messageId
let filterUrl = ""
if (this.state.popularityfilter === 'top')
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber + 1}&per_page=10&filter_by=${this.state.timefilter}&popularity=${this.state.popularityfilter}&content=${this.state.contentfilter}`
else
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber + 1}&per_page=10&popularity=${this.state.popularityfilter}&content=${this.state.contentfilter}`
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
`${filterUrl}`
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header),
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestMethodMessage),
configJSON.httpGetType,
)
runEngine.sendMessage(requestMessage.id, requestMessage)
return true
}
_handleAppStateChange = (nextAppState: any) => {
if (nextAppState === 'inactive') {
console.log('App has come to the foreground!')
// this.pause()
}
else {
console.log('background ')
// this.pause()
}
}
notification = () => {
this.setState({ showNotification: true })
this.setState({ message: 'Post Replayed' })
setTimeout(() => {
this.setState({ message: '' })
}, 5000);
}
Quotednotification = () => {
this.setState({ showNotification: true })
this.setState({ message: 'Quoted & Replayed' })
setTimeout(() => {
this.setState({ message: '' })
}, 5000);
}
clearInterval = () => {
setTimeout(() => {
this.setState({ showNotification: false })
this.setState({ message: '' })
}, 5000);
console.log("wfnwrifrsdssdsddsw", this.state.showNotification)
}
onRefresh1 = () => {
this.setState({ isLoading: true })
this.setState({ postPageNuber: 1 })
this.setState({ loading: true })
this.setState({ isPlayingContext: !this.context.isplay })
this.getPostListApi() // main
this._getMusicT_info()
this.getReportListApi()
this.getUserData()
this.getPostRepost()
this._onFinishedPlayingSubscription = SoundPlayer.addEventListener('FinishedPlaying', ({ success }) => {
console.log('finished playing', success)
this.context.playData(!this.context.isplay)
this.context.isLastPlayedData(true)
this.setState({ contextData: !this.state.contextData })
this.setState({ isPlayFinished: true })
})
}
//get list of Post and Repost from Feed
getPostRepost = async () => {
const _token = await getStorageData('USER_TOKEN')
this.setState({
loader: true,
})
const header = {
'Content-Type': 'application/json',
token: _token,
}
const requestMessage = new Message(
getName(MessageEnum.RestAPIRequestMessage),
)
this.getPostRepostListCallId = requestMessage.messageId
let filterUrl = ""
if (this.state.popularityfilter == 'top')
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber + 1}&per_page=10&filter_by=${this.state.timefilter}&popularity=${this.state.popularityfilter}&content=${this.state.contentfilter}`
else
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber + 1}&per_page=10&popularity=${this.state.popularityfilter}&content=${this.state.contentfilter}`
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
`${filterUrl}`,
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header),
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestMethodMessage),
configJSON.httpGetType,
)
runEngine.sendMessage(requestMessage.id, requestMessage)
return true
}
editpost = (item: any) => {
this.context.homeFocusFunction(false)
this.props.navigation.navigate('EditPostBlock', {
editpostdata: item,
})
}
playsong = (e: any) => {
this.context.playDataAll(JSON.stringify(this.state.feedPostList));
if (this.context.contextId !== this.context?.playSongDataAll[e].id) {
this.context.playData(false)
this.context.contextIdData(this.context?.playSongDataAll[e].id)
if (this.context?.playSongDataAll[e].attributes.post_type === 'post') {
this.context.playData(
{
songName: this.context?.playSongDataAll[e].attributes?.name,
artistName: this.context?.playSongDataAll[e].attributes?.artist_name,
songImageUrl: this.context?.playSongDataAll[e].attributes?.spotify_post_image_url ? this.context?.playSongDataAll[e].attributes?.spotify_post_image_url : '',
songMediaUrl: this.context?.playSongDataAll[e].attributes?.spotify_post_media_url,
bandName: this.context?.playSongDataAll[e].attributes?.band_name ? this.context?.playSongDataAll[e].attributes?.band_name : '',
liked: this.context?.playSongDataAll[e].attributes?.liked,
spotify_post_id: this.context?.playSongDataAll[e].attributes?.spotify_post_id ? this.context?.playSongDataAll[e].attributes?.spotify_post_id : ''
}
)
} else if (this.context?.playSongDataAll[e].attributes.post_type === 'repost') {
this.context.playData(
{
songName: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.name,
artistName: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.artist_name,
songImageUrl: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.spotify_post_image_url ? this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.spotify_post_image_url : '',
songMediaUrl: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.spotify_post_media_url,
bandName: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.band_name ? this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.band_name : '',
liked: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.liked,
spotify_post_id: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.spotify_post_id ? this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.spotify_post_id : ''
})
}
} else if (this.context.contextId === this.context?.playSongDataAll[e].id) {
this.context.playData(true)
this.context.contextIdData(this.context?.playSongDataAll[e].id)
if (this.context?.playSongDataAll[e].attributes.post_type === 'post') {
this.context.playData(
{
songName: this.context?.playSongDataAll[e].attributes?.name,
artistName: this.context?.playSongDataAll[e].attributes?.artist_name,
songImageUrl: this.context?.playSongDataAll[e].attributes?.spotify_post_image_url ? this.context?.playSongDataAll[e].attributes?.spotify_post_image_url : '',
songMediaUrl: this.context?.playSongDataAll[e].attributes?.spotify_post_media_url,
bandName: this.context?.playSongDataAll[e].attributes?.band_name ? this.context?.playSongDataAll[e].attributes?.band_name : '',
liked: this.context?.playSongDataAll[e].attributes?.liked,
spotify_post_id: this.context?.playSongDataAll[e].attributes?.spotify_post_id ? this.context?.playSongDataAll[e].attributes?.spotify_post_id : ''
}
)
} else if (this.context?.playSongDataAll[e].attributes.post_type === 'repost') {
this.context.playData(
{
songName: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.name,
artistName: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.artist_name,
songImageUrl: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.spotify_post_image_url ? this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.spotify_post_image_url : '',
songMediaUrl: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.spotify_post_media_url,
bandName: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.band_name ? this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.band_name : '',
liked: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.liked,
spotify_post_id: this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.spotify_post_id ? this.context?.playSongDataAll[e].attributes?.post?.data?.attributes?.spotify_post_id : ''
})
}
}
}
_increasePlayCount = async (e: any) => {
const token = await getStorageData('USER_TOKEN')
const header = {
"Content-Type": configJSON.categoryApiContentType,
token
};
const httpBody = {
"id": e
}
const requestMessage = new Message(getName(MessageEnum.RestAPIRequestMessage));
this.apiEmailLoginCallId = requestMessage.messageId;
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
'song_played'
);
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header)
);
requestMessage.addData(
getName(MessageEnum.RestAPIRequestBodyMessage),
JSON.stringify(httpBody)
);
requestMessage.addData(getName(MessageEnum.RestAPIRequestMethodMessage), configJSON.httpPostType);
runEngine.sendMessage(requestMessage.id, requestMessage);
}
deleteAlert = () => {
this.setState({
message: 'Post Deleted',
showfeed: true,
guideList: true,
eventList: false,
exhibitionList: false,
showGenre: false,
showTrending: false,
showStory: false,
showNotification: true
})
setTimeout(() => {
this.setState({ message: '' })
}, 5000)
}
handleDeleteFeedPost = async (deletePostId: any) => {
this.setState({ deletePostId: deletePostId })
const _postId = deletePostId
const _token = await getStorageData('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
}
handleHideFeedpost = async (hideId: any) => {
var feedList = this.state.feedPostList
var filterData = feedList.filter((feed: any) => feed.id !== hideId)
this.setState({ feedPostList: filterData })
this.setState({ showNotification: true, message: 'Post is hided' })
setTimeout(() => {
this.setState({ message: '', showNotification: false })
}, 5000)
}
handleReportApi = async (reportId: any, reportItem: any) => {
const _token = await getStorageData('USER_TOKEN')
this.setState({ loader: true })
const header = {
'Content-Type': 'application/json',
token: _token,
}
var formData = new FormData();
formData.append('data[post_id]', reportItem?.attributes?.id)
formData.append('data[report_id]', reportId.item.attributes.id)
formData.append('data[description]', reportId.item.attributes.name)
formData.append('token', _token)
const requestMessage = new Message(
getName(MessageEnum.RestAPIRequestMessage),
)
this.ReportPostApiCallId = requestMessage.messageId
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
configJSON.reportEndPoint,
)
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
}
getReportListApi = async () => {
const _token = await getStorageData('USER_TOKEN')
const header = {
'Content-Type': 'application/json',
token: _token,
}
const requestMessage = new Message(
getName(MessageEnum.RestAPIRequestMessage),
)
this.getReportListApiCallId = requestMessage.messageId
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
configJSON.getReportListApiEndPoint,
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header),
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestMethodMessage),
configJSON.httpGetType,
)
runEngine.sendMessage(requestMessage.id, requestMessage)
return true
}
_getMusicT_info = async () => {
const lastPlayed = await getStorageData('LAST_PLAYED_SONG')
if (lastPlayed !== null) {
const lastPlayedParsed = await JSON.parse(lastPlayed)
if (lastPlayedParsed !== null) {
this.setState({ isLastPlayed: true })
// console.log('lastPlayed', lastPlayed)
this.setState({
currentSongTitle: lastPlayedParsed.songName,
currSongArtist: lastPlayedParsed.artistName,
})
}
}
}
handleMenuIcon = () => {
this.props.navigation.toggleDrawer()
}
saveFilterState = (time: any, popularity: any, content: any) => {
this.setState({ timefilter: time, popularityfilter: popularity, contentfilter: content })
}
_fetchGenreApi = async (time: any, popularity: any, content: any) => {
this.setState({ postPageNuber: 1, feedloading: true })
const token = await getStorageData('USER_TOKEN')
const header = {
"Content-Type": configJSON.categoryApiContentType,
token
};
let filterUrl = ""
if (popularity == 'top')
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber}&per_page=10&filter_by=${time}&popularity=${popularity}&content=${content}`
else
filterUrl = `bx_block_posts/post_feed?page=${this.state.postPageNuber}&per_page=10&popularity=${popularity}&content=${content}`
const requestMessage = new Message(getName(MessageEnum.RestAPIRequestMessage));
this.apiFeedApi = requestMessage.messageId;
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
`${filterUrl}`
);
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header)
);
requestMessage.addData(getName(MessageEnum.RestAPIRequestMethodMessage),
configJSON.httpGetType);
runEngine.sendMessage(requestMessage.id, requestMessage);
}
onRefresh = () => {
console.log("me call hua");
this.props.navigation.navigate('FeedBlock', { index: 1 })
this.setState({
showfeed: true,
guideList: true,
eventList: false,
exhibitionList: false,
showGenre: false,
showTrending: false,
showStory: false,
})
this.setState({ isFetching: true, feedloading: true, postPageNuber: 1 });
this.getPostListApi()
}
playerIcon = () => { this.state.platform === 'apple' ? Apptheme.getapplemusic() : Apptheme.getspotifyhomeicon() }
onRefreshVicon = () => {
this.props.navigation.navigate('FeedBlock', { index: 1 })
this.setState({
showfeed: true,
guideList: true,
eventList: false,
exhibitionList: false,
showGenre: false,
showTrending: false,
showStory: false,
})
this.setState({ isFetching: true, feedloading: true, postPageNuber: 1 });
this.getPostListApiForRefresh()
}
handlerepostnavigation = () => {
this.setState({
showfeed: true,
guideList: true,
})
}
navigateToProfile = async (e, f) => {
const userdetaildata = await getStorageData('USER_ID')
console.log(userdetaildata, 'userdetaildata')
if (userdetaildata == e) {
console.log('same user')
this.context.homeFocusFunction(false)
this.props.navigation.navigate('MyProfile')
} else {
console.log('different user')
this.context.homeFocusFunction(false)
this.props.navigation.navigate('CustomisableUserProfiles3', {
anotherProfileId:
e,
anotherProfileEmail:
f
}
)
}
}
_handlePostMore = () => {
if (this.state.totdalNumberOfPage >= (this.state.postPageNuber + 1)) {
this.setState({ isPostFooterLoading: true })
this.getEndpostListApi()
} else (
this.setState({ noMorePosts: true, isPostFooterLoading: false })
)
}
pause = async () => {
console.log('pause function is called')
let song = await remote.getPlayerState()
// this.setState({ songDuration: song.playbackPosition })
console.log(song.playbackPosition, 'player state')
this.context.seekDurationData(song.playbackPosition)
this.context.totalDurationData(song.track.duration)
await remote.pause();
if (this.pauseInterval) {
clearInterval(this.pauseInterval);
}
// this.pauseInterval = setInterval(async () => {
// await remote.playUri('spotify:artist:1fbo6ce8Pg6ZPWlpE3OkfQ')
// // await remote.setRepeatMode(true)
// await remote.resume();
// await remote.pause();
// }, 15000);
}
_getLastPlayedSong = async () => {
const lastPlayed = await getStorageData('LAST_PLAYED_SONG')
if (lastPlayed !== null) {
const lastPlayedParsed = await JSON.parse(lastPlayed)
if (lastPlayedParsed !== null) {
this.setState({ isLastPlayed: true })
this.setState({ itemData: lastPlayedParsed.attributes })
this.setState({ currentSongTitle: lastPlayedParsed.attributes.name })
this.setState({ currSongArtist: lastPlayedParsed.attributes.artist_name })
this.setState({ songImage: lastPlayedParsed.attributes.spotify_post_image_url })
this.setState({ pause: false })
this.setState({ isapple: false })
SoundPlayer.playUrl(lastPlayedParsed.attributes.spotify_post_media_url)
SoundPlayer.pause()
} else {
this.setState({ isLastPlayed: false })
}
} else {
console.log('test')
}
}
play = async (songUri: string) => {
console.log("rngr", songUri)
if (this.pauseInterval) {
console.log('interval present')
clearInterval(this.pauseInterval);
}
if (songUri !== null) {
await remote.playUri(songUri);
if (this.state.songDuration !== null) {
await remote.seek(this.state.songDuration);
}
this.context.songUriData(songUri)
// this.setState({ songName: songUri })
} else {
alert("Data is Empty")
}
console.log(songUri, "song URI")
// await remote.playUri(songUri);
}
_spotifySignout = async () => {
Alert.alert('Alert', 'to run spotify song you need to logout?', [
{
text: 'Cancel',
onPress: () => {
null
},
},
{
text: 'OK',
onPress: () => {
this.context.addData('light')
spotifyLogout()
this.props.navigation.replace('EmailAccountLoginBlock')
}
}
])
}
musicT = async (songs: any, id: number, details: any, uri: any) => {
this.setState({ spotifyUri: uri })
console.log("wenfw", this.state.spotifyUri)
await remote.isConnectedAsync().then(async (isConnected: any) => {
if (isConnected) {
if (this.context.contextId !== id) {
console.log('ONE')
this.context.playData(false)
this.context.contextIdData(id)
this.context.songData(details)
this.setState({ songDuration: null })
this.play(uri)
} else {
if (this.context.contextId === id) {
if (this.context.isplay) {
console.log(this.context.isplay, "TWO")
this.setState({ songDuration: null })
this.context.playData(false)
this.context.contextIdData(id)
this.context.songData(details)
this.play(this.state.spotifyUri)
} else {
console.log(this.context.isplay, 'THREE')
this.context.playData(true)
this.context.contextIdData(id)
this.context.songData(details)
this.pause()
}
}
else {
this.context.playData(true)
this.context.contextIdData(id)
this.context.songData(details)
this.pause()
}
}
}
else {
this._spotifySignout()
}
}).catch((err: any) => {
console.log('Player not ready', err)
this._spotifySignout()
})
}
_checkNotification = () => {
OneSignal.setNotificationWillShowInForegroundHandler(notificationReceivedEvent => {
let notification = notificationReceivedEvent.getNotification();
const data = notification.additionalData
if (data.response.type === 'normal notification') {
console.log('normal notification', this.context.normalCount)
this.context.NormalCountData(this.context.normalCount + 1)
} else {
this.context.MessageCountData(this.context.MessageCount + 1)
}
console.log("additionalData: ", JSON.stringify(data.response.type));
// Complete with null means don't show a notification.
notificationReceivedEvent.complete(notification);
});
//Method for handling notifications opened
OneSignal.setNotificationOpenedHandler(notification => {
if (this.context.MessageCount > 0) {
this.context.MessageCountData(this.context.MessageCount - 1)
} else {
this.context.NormalCountData(this.context.normalCount - 1)
}
});
}
_notificationCheckActionCableConnect = async () => {
const token = await getStorageData('USER_TOKEN')
this.actionCable = ActionCable.createConsumer(`wss://${chatBaseURL}/cable?token=${token}`)
const cable = new Cable({
channel: `AppNotificationsChannel`,
})
this.setState({ notificationcableCon: cable });
this.setState({ notificationActionCable1: this.actionCable })
const channel = cable.setChannel(
`AppNotificationsChannel`,
// channel name to which we will pass data from Rails app with `stream_from`
this.actionCable.subscriptions.create({
channel: `AppNotificationsChannel`, // from Rails app app/channels/chat_channel.rb
// chat_id:8
})
);
channel
.on("received", (e: any) => {
console.log('normal notification count', e)
//
if (e && e !== undefined) {
this.context.NormalCountData(e?.unread_notification_count)
}
}
)
.on("connected", (e: any) => console.log(e, "AppNotificationsChannel Notification from server is connected"))
.on("rejected", (e: any) => console.log(e, "rejected"))
.on("disconnected", (e) => {
console.log("disconnect", e);
this.actionCable.disconnect();
});
}
_checkActionCableConnect = async () => {
const token = await getStorageData('USER_TOKEN')
this.actionCable = ActionCable.createConsumer(`wss://${chatBaseURL}/cable?token=${token}`)
const cable = new Cable({
channel: `UnreadCountsChannel`,
})
this.setState({ cableCon: cable });
this.setState({ actionCable1: this.actionCable })
const channel = cable.setChannel(
`UnreadCountsChannel`,
// channel name to which we will pass data from Rails app with `stream_from`
this.actionCable.subscriptions.create({
channel: `UnreadCountsChannel`, // from Rails app app/channels/chat_channel.rb
// chat_id:8
})
);
channel
.on("received", (e: any) => {
// this._onRecieved(e)
console.log('bheja mari', e)
//
if (e && e !== undefined) {
this.context.MessageCountData(e?.unread_messages_count)
}
}
)
.on("connected", (e: any) => console.log(e, "UnreadCountsChannel from server is connected"))
.on("rejected", (e: any) => console.log(e, "rejected"))
.on("disconnected", (e) => {
console.log("disconnect", e);
this.actionCable.disconnect();
});
}
sharePostNotification = () => {
this.setState({ showNotification: true, message: 'Message Sent' })
setTimeout(() => {
this.setState({ message: '', showNotification: false })
}, 5000)
}
_spotifyToken = async () => {
const spotify = await getStorageData('USER_TOKEN_SPOTIFY');
if (spotify === null) {
this.props.navigation.navigate('StreamingAccount3')
}
}
getLikedSongList = async () => {
const token = await getStorageData('USER_TOKEN')
const spotify = await getStorageData('USER_TOKEN_SPOTIFY');
const header = {
token
};
const requestMessage = new Message(getName(MessageEnum.RestAPIRequestMessage));
this.spotifyLikedSongList = requestMessage.messageId;
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
configJSON.likedTracksList + spotify
);
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header)
);
requestMessage.addData(
getName(MessageEnum.RestAPIRequestMethodMessage ),
'GET'
);
runEngine.sendMessage(requestMessage.id, requestMessage)
}
getSpotifyTokenForHours = async () => {
}
getAccessTokenAPI = async () => {
const token = await getStorageData('USER_TOKEN')
const header = {
'Content-Type': 'application/json',
token
}
const requestMessage = new Message(
getName(MessageEnum.RestAPIRequestMessage),
)
this.getSpotifyRefreshToken = requestMessage.messageId
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
'/refresh'
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header)
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestMethodMessage),
'POST',
)
runEngine.sendMessage(requestMessage.id, requestMessage)
return true
}
_fetchSongsTrendingApi = async () => {
this.setState({ loader: true })
const token = await getStorageData('USER_TOKEN')
const header = {
"Content-Type": "application/json",
token
};
const requestMessage = new Message(getName(MessageEnum.RestAPIRequestMessage));
this.apiSongsTrendingPost = requestMessage.messageId;
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
configJSON.trendingApiEndPoint
);
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header)
);
requestMessage.addData(getName(MessageEnum.RestAPIRequestMethodMessage), configJSON.httpGetType);
runEngine.sendMessage(requestMessage.id, requestMessage);
}
GenrelistApi = async () => {
this.setState({ loader: true })
const token = await getStorageData('USER_TOKEN')
const header = {
'Content-Type': 'multipart/form-data',
token: token,
}
const requestMessage = new Message(
getName(MessageEnum.RestAPIRequestMessage),
)
this.genrelistCallId = requestMessage.messageId
let filterUrl = ''
if (this.state.popularityfilter == 'top')
filterUrl = `bx_block_posts/genre_feed/${this.state.popularityfilter}?filter_by=${this.state.timefilter}&content=${this.state.contentfilter}&page=${this.state.postPageNuber}`
else
filterUrl = `bx_block_posts/genre_feed/${this.state.popularityfilter}?&content=${this.state.contentfilter}&page=${this.state.postPageNuber}`
requestMessage.addData(
getName(MessageEnum.RestAPIResponceEndPointMessage),
`${filterUrl}`
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestHeaderMessage),
JSON.stringify(header),
)
requestMessage.addData(
getName(MessageEnum.RestAPIRequestMethodMessage),
configJSON.httpGetType,
)
runEngine.sendMessage(requestMessage.id, requestMessage)
return true
}
toggleTabsButtons = (index: any) => {
if (index == 0) {
this.setState({
tabs:'featured'
});
} else if (index == 1) {
this.setState({
tabs:'feed'
});
} else if (index == 2) {
this.setState({
tabs:'genre'
});
} else if (index == 3) {
this.setState({
tabs:'trending'
});
} else if (index == 4) {
this.setState({
tabs:'filter'
});
if (this.state.eventList) {
this.setState({ showGenreFilter: !this.state.showGenreFilter });
}
if (this.state.showfeed) {
this.setState({ showFeedFilter: !this.state.showFeedFilter });
}
if (this.state.showTrending) {
this.setState({ showTrendingFilter: true });
}
}
};
_getData = (e) => {
console.log(e)
}
handlecontent = (e:any) => {
this.setState({tabs:'featured'})
console.log(e,"e")
}
handlepopularity = (e:any) => {
console.log(e)
this.setState({popularityfilter:e})
}
handletime = (e:any) => {
console.log(e)
this.setState({timefilter:e})
}
filterApply = (e:any) => {
this.setState({tabs:'featured'})
}
close = () => {
this.setState({tabs:'featured'})
}
}
// Customizable Area EndEditor is loading...