Merge pull request #2256 from ecency/nt/pin-from-feed

Nt/pin from feed
This commit is contained in:
Feruz M 2022-04-13 07:01:31 +03:00 committed by GitHub
commit b3bce84840
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 37 additions and 53 deletions

View File

@ -26,6 +26,7 @@ import { useAppSelector } from '../../../hooks';
import { getUnreadNotificationCount } from '../../../providers/ecency/ecency'; import { getUnreadNotificationCount } from '../../../providers/ecency/ecency';
import { decryptKey } from '../../../utils/crypto'; import { decryptKey } from '../../../utils/crypto';
import { getUser as getEcencyUser} from '../../../providers/ecency/ePoint'; import { getUser as getEcencyUser} from '../../../providers/ecency/ePoint';
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
const AccountsBottomSheetContainer = ({ navigation }) => { const AccountsBottomSheetContainer = ({ navigation }) => {
const intl = useIntl(); const intl = useIntl();
@ -109,6 +110,7 @@ const AccountsBottomSheetContainer = ({ navigation }) => {
_currentAccount.mutes = await getMutes(_currentAccount.username); _currentAccount.mutes = await getMutes(_currentAccount.username);
_currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username); _currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username);
dispatch(updateCurrentAccount(_currentAccount)); dispatch(updateCurrentAccount(_currentAccount));
dispatch(fetchSubscribedCommunities(_currentAccount.username))
} }
catch(error){ catch(error){

View File

@ -30,7 +30,6 @@ const PostCardContainer = ({
setImageHeight, setImageHeight,
pageType, pageType,
showQuickReplyModal, showQuickReplyModal,
userCommunityRole,
}) => { }) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -145,7 +144,6 @@ const PostCardContainer = ({
setImageHeight={setImageHeight} setImageHeight={setImageHeight}
isMuted={isMuted} isMuted={isMuted}
pageType={pageType} pageType={pageType}
userCommunityRole={userCommunityRole}
fetchPost={_fetchPost} fetchPost={_fetchPost}
showQuickReplyModal={_handleQuickReplyModal} showQuickReplyModal={_handleQuickReplyModal}
/> />

View File

@ -44,7 +44,6 @@ const PostCardView = ({
setImageHeight, setImageHeight,
isMuted, isMuted,
pageType, pageType,
userCommunityRole,
}) => { }) => {
//local state to manage fake upvote if available //local state to manage fake upvote if available
const activeVotesCount = activeVotes ? activeVotes.length : 0; const activeVotesCount = activeVotes ? activeVotes.length : 0;
@ -122,12 +121,7 @@ const PostCardView = ({
<Icon style={styles.pushPinIcon} size={20} name="pin" iconType="MaterialCommunityIcons" /> <Icon style={styles.pushPinIcon} size={20} name="pin" iconType="MaterialCommunityIcons" />
)} )}
<View style={styles.dropdownWrapper}> <View style={styles.dropdownWrapper}>
<PostDropdown <PostDropdown pageType={pageType} content={content} fetchPost={fetchPost} />
pageType={pageType}
userCommunityRole={userCommunityRole}
content={content}
fetchPost={fetchPost}
/>
</View> </View>
</View> </View>
<View style={styles.postBodyWrapper}> <View style={styles.postBodyWrapper}>

View File

@ -35,7 +35,7 @@ class PostDropdownContainer extends PureComponent {
super(props); super(props);
this.state = { this.state = {
options:OPTIONS options: OPTIONS
}; };
} }
@ -67,19 +67,25 @@ class PostDropdownContainer extends PureComponent {
} }
}; };
_initOptions = ({content, currentAccount, pageType, userCommunityRole} = this.props) => { _initOptions = ({ content, currentAccount, pageType, subscribedCommunities } = this.props) => {
//check if post is owned by current user or not, if so pinned or not //check if post is owned by current user or not, if so pinned or not
const _canUpdateBlogPin = !!pageType && !!content && !!currentAccount && currentAccount.name === content.author const _canUpdateBlogPin = !!pageType && !!content && !!currentAccount && currentAccount.name === content.author
const _isPinnedInProfile = !!content && content.stats?.is_pinned_blog; const _isPinnedInProfile = !!content && content.stats?.is_pinned_blog;
//check community pin update eligibility //check community pin update eligibility
const _canUpdateCommunityPin = pageType === 'community' && !!content && content.community const _canUpdateCommunityPin = subscribedCommunities.data && !!content && content.community
&& ['owner', 'admin', 'mod'].includes(userCommunityRole); ? subscribedCommunities.data.reduce((role, subscription) => {
if (content.community === subscription[0]) {
return ['owner', 'admin', 'mod'].includes(subscription[2]);
}
return role;
}, false) : false;
const _isPinnedInCommunity = !!content && content.stats?.is_pinned; const _isPinnedInCommunity = !!content && content.stats?.is_pinned;
//cook options list based on collected flags //cook options list based on collected flags
const options = OPTIONS.filter((option)=>{ const options = OPTIONS.filter((option) => {
switch(option){ switch (option) {
case 'pin-blog': case 'pin-blog':
return _canUpdateBlogPin && !_isPinnedInProfile; return _canUpdateBlogPin && !_isPinnedInProfile;
case 'unpin-blog': case 'unpin-blog':
@ -159,7 +165,7 @@ class PostDropdownContainer extends PureComponent {
this._updatePinnedPostCommunity(); this._updatePinnedPostCommunity();
break; break;
case 'unpin-community': case 'unpin-community':
this._updatePinnedPostCommunity({unpinPost:true}); this._updatePinnedPostCommunity({ unpinPost: true });
break; break;
default: default:
break; break;
@ -315,7 +321,7 @@ class PostDropdownContainer extends PureComponent {
await pinCommunityPost(currentAccount, pinCode, content.community, content.author, content.permlink, unpinPost); await pinCommunityPost(currentAccount, pinCode, content.community, content.author, content.permlink, unpinPost);
dispatch(toastNotification(intl.formatMessage({ id: 'alert.successful' }))); dispatch(toastNotification(intl.formatMessage({ id: 'alert.successful' })));
}catch(err){ } catch (err) {
console.warn("Failed to update pin status of community post", err); console.warn("Failed to update pin status of community post", err);
Alert.alert( Alert.alert(
intl.formatMessage({ intl.formatMessage({
@ -402,6 +408,7 @@ const mapStateToProps = (state) => ({
currentAccount: state.account.currentAccount, currentAccount: state.account.currentAccount,
pinCode: state.application.pin, pinCode: state.application.pin,
isPinCodeOpen: state.application.isPinCodeOpen, isPinCodeOpen: state.application.isPinCodeOpen,
subscribedCommunities: state.communities.subscribedCommunities,
}); });
export default withNavigation(connect(mapStateToProps)(injectIntl(PostDropdownContainer))); export default withNavigation(connect(mapStateToProps)(injectIntl(PostDropdownContainer)));

View File

@ -17,7 +17,6 @@ interface postsListContainerProps extends FlatListProps<any> {
isLoading:boolean; isLoading:boolean;
isRefreshing:boolean; isRefreshing:boolean;
pageType:'main'|'profile'|'ownProfile'|'community'; pageType:'main'|'profile'|'ownProfile'|'community';
userCommunityRole?:string;
showQuickReplyModal:(post:any)=>void; showQuickReplyModal:(post:any)=>void;
} }
@ -30,7 +29,6 @@ const postsListContainer = ({
isRefreshing, isRefreshing,
isLoading, isLoading,
pageType, pageType,
userCommunityRole,
showQuickReplyModal, showQuickReplyModal,
...props ...props
}:postsListContainerProps, ref) => { }:postsListContainerProps, ref) => {
@ -147,7 +145,6 @@ const postsListContainer = ({
imageHeight={imgHeight} imageHeight={imgHeight}
setImageHeight = {_setImageHeightInMap} setImageHeight = {_setImageHeightInMap}
pageType={pageType} pageType={pageType}
userCommunityRole={userCommunityRole}
showQuickReplyModal={showQuickReplyModal} showQuickReplyModal={showQuickReplyModal}
/>, />,
); );

View File

@ -17,7 +17,6 @@ export const TabbedPosts = ({
tabContentOverrides, tabContentOverrides,
imagesToggleEnabled, imagesToggleEnabled,
stackedTabs, stackedTabs,
userCommunityRole,
onTabChange, onTabChange,
...props ...props
}:TabbedPostsProps) => { }:TabbedPostsProps) => {
@ -74,7 +73,6 @@ export const TabbedPosts = ({
pageType={pageType} pageType={pageType}
filterScrollRequest={filterScrollRequest} filterScrollRequest={filterScrollRequest}
onScrollRequestProcessed={_onScrollRequestProcessed} onScrollRequestProcessed={_onScrollRequestProcessed}
userCommunityRole={userCommunityRole}
{...props} {...props}
/> />
) )

View File

@ -15,7 +15,6 @@ export interface TabbedPostsProps {
imagesToggleEnabled?:boolean, imagesToggleEnabled?:boolean,
stackedTabs:boolean, stackedTabs:boolean,
pinnedPermlink?:string, pinnedPermlink?:string,
userCommunityRole?:string,
onTabChange:(index:number)=>void onTabChange:(index:number)=>void
handleOnScroll:()=>void, handleOnScroll:()=>void,
} }
@ -60,7 +59,6 @@ export interface TabMeta {
forceLoadPosts:boolean, forceLoadPosts:boolean,
filterScrollRequest:string, filterScrollRequest:string,
pinnedPermlink?:string, pinnedPermlink?:string,
userCommunityRole?:string,
onScrollRequestProcessed:()=>void onScrollRequestProcessed:()=>void
handleOnScroll:()=>void; handleOnScroll:()=>void;
} }

View File

@ -33,7 +33,6 @@ const TabContent = ({
feedUsername, feedUsername,
tag, tag,
pinnedPermlink, pinnedPermlink,
userCommunityRole,
onScrollRequestProcessed, onScrollRequestProcessed,
handleOnScroll, handleOnScroll,
...props ...props
@ -47,9 +46,12 @@ const TabContent = ({
const isAnalytics = useSelector((state) => state.application.isAnalytics); const isAnalytics = useSelector((state) => state.application.isAnalytics);
const nsfw = useSelector((state) => state.application.nsfw); const nsfw = useSelector((state) => state.application.nsfw);
const isConnected = useSelector((state) => state.application.isConnected); const isConnected = useSelector((state) => state.application.isConnected);
const {name:username, about:{profile:{pinned}}} = useSelector((state) => state.account.currentAccount); const currentAccount = useSelector((state) => state.account.currentAccount);
const initPosts = useSelector((state) => state.posts.initPosts) const initPosts = useSelector((state) => state.posts.initPosts)
const username = currentAccount.username;
const curPinned = currentAccount.about?.pinned;
//state //state
const [posts, setPosts] = useState([]); const [posts, setPosts] = useState([]);
@ -72,6 +74,8 @@ const TabContent = ({
sessionUserRef.current = sessionUser; sessionUserRef.current = sessionUser;
//side effects //side effects
useEffect(() => { useEffect(() => {
@ -101,13 +105,11 @@ const TabContent = ({
}, [filterScrollRequest]) }, [filterScrollRequest])
useEffect(()=>{ useEffect(()=>{
if(pageType === 'ownProfile' && pinned !== pinnedPermlink ){ if(pageType === 'ownProfile' && curPinned !== pinnedPermlink ){
// setPinnedPermlink(pinnedPermlink)
// alert("This is called")
_scrollToTop(); _scrollToTop();
_loadPosts({shouldReset:true, _pinnedPermlink:pinned}) _loadPosts({shouldReset:true, _pinnedPermlink:curPinned})
} }
},[pinned]) },[curPinned])
const _cleanup = () => { const _cleanup = () => {
@ -359,7 +361,6 @@ const TabContent = ({
isLoading={tabMeta.isLoading} isLoading={tabMeta.isLoading}
ListEmptyComponent={_renderEmptyContent} ListEmptyComponent={_renderEmptyContent}
pageType={pageType} pageType={pageType}
userCommunityRole={userCommunityRole}
showQuickReplyModal={_showQuickReplyModal} showQuickReplyModal={_showQuickReplyModal}
/> />
<ScrollTopPopup <ScrollTopPopup

View File

@ -3,7 +3,6 @@ import sha256 from 'crypto-js/sha256';
import Config from 'react-native-config'; import Config from 'react-native-config';
import get from 'lodash/get'; import get from 'lodash/get';
import { Alert } from 'react-native';
import { getDigitPinCode, getMutes, getUser } from './dhive'; import { getDigitPinCode, getMutes, getUser } from './dhive';
import { getUser as getEcencyUser } from '../ecency/ePoint'; import { getUser as getEcencyUser } from '../ecency/ePoint';
import { import {

View File

@ -107,6 +107,7 @@ import parseVersionNumber from '../../../utils/parseVersionNumber';
import { getTimeFromNow, setMomentLocale } from '../../../utils/time'; import { getTimeFromNow, setMomentLocale } from '../../../utils/time';
import parseAuthUrl from '../../../utils/parseAuthUrl'; import parseAuthUrl from '../../../utils/parseAuthUrl';
import { purgeExpiredCache } from '../../../redux/actions/cacheActions'; import { purgeExpiredCache } from '../../../redux/actions/cacheActions';
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
// Workaround // Workaround
let previousAppState = 'background'; let previousAppState = 'background';
@ -764,7 +765,7 @@ class ApplicationContainer extends Component {
accountData.mutes = await getMutes(realmObject.username); accountData.mutes = await getMutes(realmObject.username);
accountData.ecencyUserData = await getEcencyUser(realmObject.username); accountData.ecencyUserData = await getEcencyUser(realmObject.username);
dispatch(updateCurrentAccount(accountData)); dispatch(updateCurrentAccount(accountData));
dispatch(fetchSubscribedCommunities(realmObject.username));
this._connectNotificationServer(accountData.name); this._connectNotificationServer(accountData.name);
} catch (err) { } catch (err) {
Alert.alert( Alert.alert(
@ -945,6 +946,7 @@ class ApplicationContainer extends Component {
_currentAccount.mutes = await getMutes(_currentAccount.username); _currentAccount.mutes = await getMutes(_currentAccount.username);
_currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username); _currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username);
dispatch(updateCurrentAccount(_currentAccount)); dispatch(updateCurrentAccount(_currentAccount));
dispatch(fetchSubscribedCommunities(_currentAccount.username));
}; };
_handleWelcomeModalButtonPress = () => { _handleWelcomeModalButtonPress = () => {

View File

@ -13,7 +13,6 @@ import ROUTES from '../../../constants/routeNames';
const CommunityContainer = ({ children, navigation, currentAccount, pinCode, isLoggedIn }) => { const CommunityContainer = ({ children, navigation, currentAccount, pinCode, isLoggedIn }) => {
const [data, setData] = useState(null); const [data, setData] = useState(null);
const [isSubscribed, setIsSubscribed] = useState(false); const [isSubscribed, setIsSubscribed] = useState(false);
const [userRole, setUserRole] = useState('guest');
const tag = get(navigation, 'state.params.tag'); const tag = get(navigation, 'state.params.tag');
const dispatch = useDispatch(); const dispatch = useDispatch();
const intl = useIntl(); const intl = useIntl();
@ -31,25 +30,11 @@ const CommunityContainer = ({ children, navigation, currentAccount, pinCode, isL
useEffect(() => { useEffect(() => {
if (data) { if (data) {
//check and set user role //check and set user role
let _hasTeamRole = false;
if (data.team && currentAccount) {
const member = data.team.find((m) => m[0] === currentAccount.username);
const role = member ? member[1] : userRole;
_hasTeamRole = !!member;
setUserRole(role);
}
getSubscriptions(currentAccount.username) getSubscriptions(currentAccount.username)
.then((result) => { .then((result) => {
if (result) { if (result) {
const _isSubscribed = result.some((item) => item[0] === data.name); const _isSubscribed = result.some((item) => item[0] === data.name);
setIsSubscribed(_isSubscribed); setIsSubscribed(_isSubscribed);
if (_isSubscribed && !_hasTeamRole) {
//if userRole default value is not overwritten,
//means user is not a part of community core team, so setting as member
setUserRole('member');
}
} }
}) })
.catch((e) => { .catch((e) => {
@ -112,7 +97,6 @@ const CommunityContainer = ({ children, navigation, currentAccount, pinCode, isL
handleNewPostButtonPress: _handleNewPostButtonPress, handleNewPostButtonPress: _handleNewPostButtonPress,
isSubscribed, isSubscribed,
isLoggedIn, isLoggedIn,
userRole,
}) })
); );
}; };

View File

@ -43,7 +43,6 @@ const CommunityScreen = ({ navigation }) => {
handleNewPostButtonPress, handleNewPostButtonPress,
isSubscribed, isSubscribed,
isLoggedIn, isLoggedIn,
userRole,
}) => ( }) => (
<View style={styles.container}> <View style={styles.container}>
<BasicHeader <BasicHeader
@ -117,7 +116,6 @@ const CommunityScreen = ({ navigation }) => {
selectedOptionIndex={_getSelectedIndex()} selectedOptionIndex={_getSelectedIndex()}
tag={tag} tag={tag}
pageType="community" pageType="community"
userCommunityRole={userRole}
/> />
</View> </View>
</View> </View>

View File

@ -34,6 +34,7 @@ import ROUTES from '../../../constants/routeNames';
// Component // Component
import LoginScreen from '../screen/loginScreen'; import LoginScreen from '../screen/loginScreen';
import persistAccountGenerator from '../../../utils/persistAccountGenerator'; import persistAccountGenerator from '../../../utils/persistAccountGenerator';
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
/* /*
* Props Name Description Value * Props Name Description Value
@ -65,6 +66,7 @@ class LoginContainer extends PureComponent {
const persistAccountData = persistAccountGenerator(result); const persistAccountData = persistAccountGenerator(result);
dispatch(updateCurrentAccount({ ...result })); dispatch(updateCurrentAccount({ ...result }));
dispatch(fetchSubscribedCommunities(username));
dispatch(addOtherAccount({ ...persistAccountData })); dispatch(addOtherAccount({ ...persistAccountData }));
dispatch(loginAction(true)); dispatch(loginAction(true));
dispatch(setInitPosts([])); dispatch(setInitPosts([]));

View File

@ -44,6 +44,7 @@ import { encryptKey, decryptKey } from '../../../utils/crypto';
// Component // Component
import PinCodeScreen from '../screen/pinCodeScreen'; import PinCodeScreen from '../screen/pinCodeScreen';
import { getUnreadNotificationCount } from '../../../providers/ecency/ecency'; import { getUnreadNotificationCount } from '../../../providers/ecency/ecency';
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
class PinCodeContainer extends Component { class PinCodeContainer extends Component {
constructor(props) { constructor(props) {
@ -322,6 +323,7 @@ class PinCodeContainer extends Component {
_currentAccount.mutes = await getMutes(_currentAccount.username); _currentAccount.mutes = await getMutes(_currentAccount.username);
_currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username); _currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username);
dispatch(updateCurrentAccount({ ..._currentAccount })); dispatch(updateCurrentAccount({ ..._currentAccount }));
dispatch(fetchSubscribedCommunities(_currentAccount.username));
dispatch(closePinCodeModal()); dispatch(closePinCodeModal());
} }

View File

@ -15,6 +15,7 @@ import { login as loginAction, openPinCodeModal } from '../../redux/actions/appl
// Constants // Constants
import { default as ROUTES } from '../../constants/routeNames'; import { default as ROUTES } from '../../constants/routeNames';
import persistAccountGenerator from '../../utils/persistAccountGenerator'; import persistAccountGenerator from '../../utils/persistAccountGenerator';
import { fetchSubscribedCommunities } from '../../redux/actions/communitiesAction';
class HiveSigner extends PureComponent { class HiveSigner extends PureComponent {
constructor(props) { constructor(props) {
@ -45,6 +46,7 @@ class HiveSigner extends PureComponent {
const persistAccountData = persistAccountGenerator(result); const persistAccountData = persistAccountGenerator(result);
dispatch(updateCurrentAccount({ ...result })); dispatch(updateCurrentAccount({ ...result }));
dispatch(fetchSubscribedCommunities(result.username));
dispatch(addOtherAccount({ ...persistAccountData })); dispatch(addOtherAccount({ ...persistAccountData }));
dispatch(loginAction(true)); dispatch(loginAction(true));