diff --git a/API.js b/API.js index 661ff4c..693518c 100644 --- a/API.js +++ b/API.js @@ -194,7 +194,7 @@ const API = { async getMe() { if (!CurrentProfileData) if(!CurrentProfile) await this.isLoggedIn(); - CurrentProfileData = await this.getUserProfile(CurrentProfile); + CurrentProfileData = await this.getUserProfile(CurrentProfile, true); return CurrentProfileData; }, getMyProfiles() { diff --git a/App.js b/App.js index 756a935..5a060ef 100644 --- a/App.js +++ b/App.js @@ -23,6 +23,7 @@ import MenuView from './Views/Menu.js'; import ProfileSettings from './Views/ProfileSettings.js'; import InviteView from './Views/Invite.js'; import MediaView from './components/MediaView.js'; +import GlobalState from './contexts/GlobalState.js'; const Tab = createBottomTabNavigator(); @@ -107,9 +108,16 @@ const MainNavigation = () => { console.log(response); }); + const interval = setInterval(async () => { + if(await API.isLoggedIn()) + console.log("Updating me") + GlobalState.me = await API.getMe(); + }, 10000); + return () => { Notifications.removeNotificationSubscription(notificationListener.current); Notifications.removeNotificationSubscription(responseListener.current); + clearInterval(interval); }; }, []); @@ -232,14 +240,7 @@ export default function App() { {props.navigation.canGoBack() ? { props.navigation.goBack(); }} /> : <>} - ( - - )} mode="text" >EMI Fellowship - } titleStyle={{}}/> + {alert("Chats are comming soon.")}} /> {props.navigation.navigate("Search")}} /> {props.navigation.navigate("Notifications")}} /> diff --git a/Views/Feed.js b/Views/Feed.js index 5ae7a3c..4962ab2 100644 --- a/Views/Feed.js +++ b/Views/Feed.js @@ -40,8 +40,9 @@ let Feed = ({ navigation, route }) => { return navigation.navigate('Profile', { profileid: route.params.profileid }) } API.getMe().then((me) => { - if (subscribed) + if (subscribed){ GlobalState.me = me; + } }); console.log("Feed from cache") let cacheFeed = await getFeed() || []; diff --git a/components/Media.js b/components/Media.js index c573f6b..f282c58 100644 --- a/components/Media.js +++ b/components/Media.js @@ -1,11 +1,13 @@ import React, { useState, useEffect } from 'react'; import { View, TouchableHighlight, Image, StyleSheet, FlatList } from 'react-native'; -import { Button } from 'react-native-paper'; +import { Button, Text, ProgressBar } from 'react-native-paper'; import API from './../API.js'; import VideoPlayer from './VideoPlayer.js'; import VimeoPlayer from './VimeoPlayer.js'; import { WebView } from 'react-native-webview'; +import { useSnapshot } from 'valtio'; import GlobalState from '../contexts/GlobalState.js'; +import Moment from 'moment'; const videoIdF = (content) => { let vimeoTag = content.match(/@vimeo:[0-9]+/); @@ -54,6 +56,8 @@ const iframeTagF = (content) => { let Media = (props) => { + const gState = useSnapshot(GlobalState); + const viewer = gState.me; const imagesTag = imagesTagF(props.content); const imageStyle = imagesTag.length == 1 ? styles.image : styles.multipleImage; const videosId = videoIdF(props.content); @@ -93,6 +97,7 @@ let Media = (props) => { { //setLoaded(true) GlobalState.currentMedia = hlsUrl; + GlobalState.mediaPost = props.post; }}> {poster ? : @@ -117,6 +122,16 @@ let Media = (props) => { const renderImages = (({ item }) => { return (); }); + let progress = <>; + if(viewer.data && viewer.data[props.postId]) { + const percent = Math.round(viewer.data[props.postId].time / viewer.data[props.postId].duration * 100); + if(percent) + progress = + <> + {percent}% {Moment(viewer.data[props.postId].ts).fromNow()} + + ; + } return ( { @@ -143,6 +158,7 @@ let Media = (props) => { {video2} {iframe} {youtubeEmb} + {progress} ); } diff --git a/components/MediaView.js b/components/MediaView.js index d3b59c6..a9b5398 100644 --- a/components/MediaView.js +++ b/components/MediaView.js @@ -8,8 +8,10 @@ import VideoPlayer from './VideoPlayer'; const MediaView = (props) => { const gState = useSnapshot(GlobalState); const currentMedia = gState.currentMedia; + const mediaPost = gState.mediaPost; const [state, setState] = useState(''); const currentStyles = state === "min" ? styles.min : styles.float; + //console.log(mediaPost) return ( <> @@ -20,7 +22,8 @@ const MediaView = (props) => { }}> { opacity: 0.9 }} icon={"close"} color="#fff" onPress={()=>{ GlobalState.currentMedia = ''; + GlobalState.mediaPost = {}; }}> { {cleanContent} - + : {i18n.t("message.news")} diff --git a/components/VideoPlayer.js b/components/VideoPlayer.js index 51a5053..5420c97 100644 --- a/components/VideoPlayer.js +++ b/components/VideoPlayer.js @@ -5,7 +5,7 @@ import API from '../API'; import { useSnapshot } from 'valtio'; import GlobalState from '../contexts/GlobalState.js'; -const VideoPlayer = ({ videosFiles, postId, poster, videoUrl, videoStyle }) => { +const VideoPlayer = ({ videosFiles, postId, profileId, poster, videoUrl, videoStyle }) => { const gState = useSnapshot(GlobalState); const viewer = gState.me; const video = React.useRef(null); @@ -28,7 +28,23 @@ const VideoPlayer = ({ videosFiles, postId, poster, videoUrl, videoStyle }) => { if(!viewer.data[postId]) return 0; console.log(postId + " loaded") video.current.setPositionAsync(viewer.data[postId].time*1000); + video.current.presentFullscreenPlayer(); }; + + //console.log("status", status) + if(postId && status.isPlaying){ + const ts = new Date(); + const newData = { + watched: status.didJustFinish, + time: Math.round(status.positionMillis/1000), + ts: ts.getTime(), + duration: Math.round(status.durationMillis/1000), + postId: postId, + profileId: profileId, + }; + console.log(postId, newData); + API.setDataValue(postId, newData); + } return (