From 0b6b49d79c501d7fe2f8d700af5726cf09ab8e91 Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Fri, 26 Aug 2022 23:47:16 +0500 Subject: [PATCH] hide post from feed when mute/block and updated mute flow --- .../view/dropdownButtonView.tsx | 2 +- .../postCard/container/postCardContainer.js | 7 +- src/components/postCard/view/postCardView.js | 2 - .../container/postDropdownContainer.tsx | 100 +++--------------- .../container/postsListContainer.tsx | 25 +++-- src/config/locales/en-US.json | 3 +- src/constants/options/post.js | 1 - src/redux/reducers/accountReducer.ts | 5 +- 8 files changed, 33 insertions(+), 112 deletions(-) diff --git a/src/components/dropdownButton/view/dropdownButtonView.tsx b/src/components/dropdownButton/view/dropdownButtonView.tsx index 4b84e0a1a..e575f0636 100644 --- a/src/components/dropdownButton/view/dropdownButtonView.tsx +++ b/src/components/dropdownButton/view/dropdownButtonView.tsx @@ -83,7 +83,7 @@ const DropdownButtonView = ({ defaultIndex={selectedOptionIndex} defaultValue={defaultText} renderSeparator={() => null} - + showsVerticalScrollIndicator={false} renderRow={(rowData, rowID, highlighted) => renderDropdownRow( rowData, diff --git a/src/components/postCard/container/postCardContainer.js b/src/components/postCard/container/postCardContainer.js index fdca24b9e..8442cef8f 100644 --- a/src/components/postCard/container/postCardContainer.js +++ b/src/components/postCard/container/postCardContainer.js @@ -30,16 +30,14 @@ const PostCardContainer = ({ setImageHeight, pageType, showQuickReplyModal, - onLoadPosts, + mutes, }) => { const dispatch = useAppDispatch(); const [_content, setContent] = useState(content); const [reblogs, setReblogs] = useState([]); const activeVotes = get(_content, 'active_votes', []); - const [isMuted, setIsMuted] = useState( - currentAccount.mutes && currentAccount.mutes.indexOf(content.author) > -1, - ); + const [isMuted, setIsMuted] = useState(!!mutes && mutes.indexOf(content.author) > -1); useEffect(() => { let isCancelled = false; @@ -147,7 +145,6 @@ const PostCardContainer = ({ pageType={pageType} fetchPost={_fetchPost} showQuickReplyModal={_handleQuickReplyModal} - onLoadPosts={onLoadPosts} /> ); }; diff --git a/src/components/postCard/view/postCardView.js b/src/components/postCard/view/postCardView.js index eb94f5e75..93e12e6ba 100644 --- a/src/components/postCard/view/postCardView.js +++ b/src/components/postCard/view/postCardView.js @@ -46,7 +46,6 @@ const PostCardView = ({ setImageHeight, isMuted, pageType, - onLoadPosts, }) => { //local state to manage fake upvote if available const activeVotesCount = activeVotes ? activeVotes.length : 0; @@ -128,7 +127,6 @@ const PostCardView = ({ pageType={pageType} content={content} fetchPost={fetchPost} - onLoadPosts={onLoadPosts} isMuted={isMuted} /> diff --git a/src/components/postDropdown/container/postDropdownContainer.tsx b/src/components/postDropdown/container/postDropdownContainer.tsx index 0777080d2..2bf0ee77a 100644 --- a/src/components/postDropdown/container/postDropdownContainer.tsx +++ b/src/components/postDropdown/container/postDropdownContainer.tsx @@ -95,10 +95,6 @@ class PostDropdownContainer extends PureComponent { return _canUpdateCommunityPin && !_isPinnedInCommunity; case 'unpin-community': return _canUpdateCommunityPin && _isPinnedInCommunity; - case 'mute': - return !isMuted; - case 'unmute': - return isMuted; default: return true; } @@ -109,9 +105,10 @@ class PostDropdownContainer extends PureComponent { // Component Functions _handleOnDropdownSelect = async (index) => { - const { content, dispatch, intl, navigation, isMuted } = this.props; + const {currentAccount, content, dispatch, intl, navigation, isMuted } = this.props as any; + const username = content.author; + const isOwnProfile = !username || currentAccount.username === username; const { options } = this.state; - console.log('content : ', content); switch (options[index]) { case 'copy': @@ -183,35 +180,15 @@ class PostDropdownContainer extends PureComponent { }); break; case 'mute': - this._handleMuteUnmuteUser(!isMuted); - break; - case 'unmute': - this._handleMuteUnmuteUser(!isMuted); + !isOwnProfile && this._muteUser(); break; default: break; } }; - _handleMuteUnmuteUser = async (isMuteAction) => { - const { currentAccount, content } = this.props as any; - const username = content.author; - const isOwnProfile = !username || currentAccount.username === username; - console.log('isMuteAction,isOwnProfile : ', isMuteAction, isOwnProfile); - - if(!isOwnProfile){ - console.log('isMuteAction : ', isMuteAction); - - if (isMuteAction) { - this._muteUser(); - } else { - this._handleFollowUnfollowUser(); - } - } - - }; _muteUser = () => { - const { currentAccount, pinCode, dispatch, intl, content, onLoadPosts } = this.props as any; + const { currentAccount, pinCode, dispatch, intl, content } = this.props as any; const username = content.author; const follower = currentAccount.name; const following = username; @@ -227,7 +204,6 @@ class PostDropdownContainer extends PureComponent { currentAccount.mutes = [username, ...curMutes]; } dispatch(updateCurrentAccount(currentAccount)); - onLoadPosts(true); //fetch posts again after muting user dispatch( toastNotification( intl.formatMessage({ @@ -242,58 +218,8 @@ class PostDropdownContainer extends PureComponent { }; - _handleFollowUnfollowUser = async () => { - console.log('inside _handleFollowUnfollowUser'); - - const { currentAccount, pinCode, dispatch, intl, content, onLoadPosts } = this.props as any; - const username = content.author; - const follower = get(currentAccount, 'name', ''); - const following = username; - - let followAction; - const res = await getRelationship(currentAccount.name, username); - const _isFollowing = res && res.follows; - const _isMuted = res && res.ignores; - - if (_isMuted) { - followAction = followUser; - } - if(_isFollowing) { - followAction = unfollowUser; - } - - followAction(currentAccount, pinCode, { - follower, - following, - }) - .then(() => { - //means user is now being followed - if (!_isFollowing || _isMuted) { - const mutes = currentAccount.mutes || []; - const mutedIndex = mutes.indexOf(username); - if (mutedIndex >= 0) { - mutes.splice(mutedIndex, 1); - currentAccount.mutes = mutes; - dispatch(updateCurrentAccount(currentAccount)); - } - } - onLoadPosts(true); //fetch posts again after muting user - dispatch( - toastNotification( - intl.formatMessage({ - id: !_isFollowing || _isMuted ? 'alert.success_follow' : 'alert.success_unfollow', - }), - ), - ); - - }) - .catch((err) => { - this._profileActionDone({ error: err }); - }); - }; - _profileActionDone = ({ error = null }) => { - const { intl, dispatch, content } = this.props; + const { intl, dispatch, content } = this.props as any; this.setState({ isProfileLoading: false, @@ -314,7 +240,7 @@ class PostDropdownContainer extends PureComponent { }; _share = () => { - const { content } = this.props; + const { content } = this.props as any; const postUrl = getPostUrl(get(content, 'url')); Share.share({ @@ -323,7 +249,7 @@ class PostDropdownContainer extends PureComponent { }; _report = (url) => { - const { dispatch, intl } = this.props; + const { dispatch, intl } = this.props as any; const _onConfirm = () => { addReport('content', url) @@ -367,7 +293,7 @@ class PostDropdownContainer extends PureComponent { }; _addToBookmarks = () => { - const { content, dispatch, intl } = this.props; + const { content, dispatch, intl } = this.props as any; addBookmark(get(content, 'author'), get(content, 'permlink')) .then(() => { @@ -391,7 +317,7 @@ class PostDropdownContainer extends PureComponent { }; _reblog = () => { - const { content, currentAccount, dispatch, intl, isLoggedIn, pinCode } = this.props; + const { content, currentAccount, dispatch, intl, isLoggedIn, pinCode } = this.props as any; if (isLoggedIn) { reblog(currentAccount, pinCode, content.author, get(content, 'permlink', '')) .then(() => { @@ -475,7 +401,7 @@ class PostDropdownContainer extends PureComponent { } _redirectToReply = () => { - const { content, fetchPost, isLoggedIn, navigation } = this.props; + const { content, fetchPost, isLoggedIn, navigation } = this.props as any; if (isLoggedIn) { navigation.navigate({ @@ -491,7 +417,7 @@ class PostDropdownContainer extends PureComponent { }; _redirectToPromote = (routeName, from, redeemType) => { - const { content, isLoggedIn, navigation, dispatch, isPinCodeOpen } = this.props; + const { content, isLoggedIn, navigation, dispatch, isPinCodeOpen } = this.props as any; const params = { from, permlink: `${get(content, 'author')}/${get(content, 'permlink')}`, @@ -503,7 +429,7 @@ class PostDropdownContainer extends PureComponent { openPinCodeModal({ navigateTo: routeName, navigateParams: params, - }), + } as any) ); } else if (isLoggedIn) { navigation.navigate({ diff --git a/src/components/postsList/container/postsListContainer.tsx b/src/components/postsList/container/postsListContainer.tsx index 4d3cdd80d..371bff615 100644 --- a/src/components/postsList/container/postsListContainer.tsx +++ b/src/components/postsList/container/postsListContainer.tsx @@ -43,7 +43,8 @@ const postsListContainer = ({ ? state.posts.feedPosts : state.posts.otherPosts }); - + const mutes = useSelector((state) => state.account.currentAccount.mutes); + const scrollPosition = useSelector((state) => { return isFeedScreen ? state.posts.feedScrollPosition @@ -76,7 +77,6 @@ const postsListContainer = ({ }, [scrollPosition]) - const _setImageHeightInMap = (mapKey:string, height:number) => { if(mapKey && height){ setImageHeights(imageHeights.set(mapKey, height)); @@ -106,17 +106,19 @@ const postsListContainer = ({ const _renderItem = ({ item, index }:{item:any, index:number}) => { - const e = []; - + const e = [] as any; + if (index % 3 === 0) { const ix = index / 3 - 1; if (promotedPosts[ix] !== undefined) { const p = promotedPosts[ix]; - if (get(p, 'author', null) && posts && posts.filter((x) => x.permlink === p.permlink).length <= 0) { + let isMuted = mutes && mutes.indexOf(p.author) > -1; + + if (!isMuted && get(p, 'author', null) && posts && posts.filter((x) => x.permlink === p.permlink).length <= 0) { //get image height from cache if available const localId = p.author + p.permlink; - const imgHeight = imageHeights.get(localId) + const imgHeight = imageHeights.get(localId); e.push( ); } } } - if (get(item, 'author', null)) { + + let isMuted = mutes && mutes.indexOf(item.author) > -1; + if (!isMuted && get(item, 'author', null)) { //get image height from cache if available const localId = item.author + item.permlink; const imgHeight = imageHeights.get(localId) @@ -147,14 +151,13 @@ const postsListContainer = ({ setImageHeight = {_setImageHeightInMap} pageType={pageType} showQuickReplyModal={showQuickReplyModal} - onLoadPosts={onLoadPosts} + mutes={mutes} />, ); } return e; }; - - + return ( {({ isDarkTheme }) => ( diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 3c1fd628e..f6ce141e4 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -584,8 +584,7 @@ "pin-community":"Pin to community", "unpin-community":"Unpin from community", "edit-history": "Edit History", - "mute": "Mute / Block", - "unmute": "UnMute / UnBlock" + "mute": "Mute / Block" }, "deep_link": { "no_existing_user": "No existing user", diff --git a/src/constants/options/post.js b/src/constants/options/post.js index 9b2794a8d..eb87fe983 100644 --- a/src/constants/options/post.js +++ b/src/constants/options/post.js @@ -12,6 +12,5 @@ export default [ 'share', 'bookmarks', 'mute', - 'unmute', 'report', ]; diff --git a/src/redux/reducers/accountReducer.ts b/src/redux/reducers/accountReducer.ts index cdaf80ae5..d2f465411 100644 --- a/src/redux/reducers/accountReducer.ts +++ b/src/redux/reducers/accountReducer.ts @@ -93,13 +93,12 @@ export default function (state = initialState, action) { }; case UPDATE_CURRENT_ACCOUNT: - return { - ...state, + return Object.assign({}, state, { currentAccount: action.payload, isFetching: false, hasError: false, errorMessage: null, - }; + }); case UPDATE_UNREAD_ACTIVITY_COUNT: return {