mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-20 20:01:56 +03:00
hide post from feed when mute/block and updated mute flow
This commit is contained in:
parent
088e958b90
commit
0b6b49d79c
@ -83,7 +83,7 @@ const DropdownButtonView = ({
|
||||
defaultIndex={selectedOptionIndex}
|
||||
defaultValue={defaultText}
|
||||
renderSeparator={() => null}
|
||||
|
||||
showsVerticalScrollIndicator={false}
|
||||
renderRow={(rowData, rowID, highlighted) =>
|
||||
renderDropdownRow(
|
||||
rowData,
|
||||
|
@ -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}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
@ -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}
|
||||
/>
|
||||
</View>
|
||||
|
@ -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({
|
||||
|
@ -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(
|
||||
<PostCard
|
||||
@ -127,13 +129,15 @@ const postsListContainer = ({
|
||||
pageType={pageType}
|
||||
setImageHeight = {_setImageHeightInMap}
|
||||
showQuickReplyModal={showQuickReplyModal}
|
||||
onLoadPosts={onLoadPosts}
|
||||
mutes={mutes}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
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 (
|
||||
<ThemeContainer>
|
||||
{({ isDarkTheme }) => (
|
||||
|
@ -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",
|
||||
|
@ -12,6 +12,5 @@ export default [
|
||||
'share',
|
||||
'bookmarks',
|
||||
'mute',
|
||||
'unmute',
|
||||
'report',
|
||||
];
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user