mirror of
https://github.com/wassname/talk.git
synced 2026-06-29 16:00:54 +08:00
Better notifications
This commit is contained in:
@@ -14,10 +14,20 @@ import update from 'immutability-helper';
|
||||
import { handleFlaggedUsernameChange } from '../graphql';
|
||||
import { notify } from 'coral-framework/actions/notification';
|
||||
import { isFlaggedUserDangling } from '../utils';
|
||||
import t from 'coral-framework/services/i18n';
|
||||
|
||||
import FlaggedAccounts from '../components/FlaggedAccounts';
|
||||
import FlaggedUser from '../containers/FlaggedUser';
|
||||
|
||||
function whoChangedTheStatus(statusObject) {
|
||||
return statusObject.history[statusObject.history.length - 1].assigned_by
|
||||
.username;
|
||||
}
|
||||
|
||||
function whoFlagged(user) {
|
||||
return user.actions[user.actions.length - 1].user.username;
|
||||
}
|
||||
|
||||
class FlaggedAccountsContainer extends Component {
|
||||
subscriptions = [];
|
||||
|
||||
@@ -40,7 +50,12 @@ class FlaggedAccountsContainer extends Component {
|
||||
{ subscriptionData: { data: { usernameFlagged: user } } }
|
||||
) => {
|
||||
return handleFlaggedUsernameChange(prev, user, () => {
|
||||
this.props.notify('info', `user ${user.username} flagged`);
|
||||
const msg = t(
|
||||
'flagged_usernames.notify_flagged',
|
||||
whoFlagged(user),
|
||||
user.username
|
||||
);
|
||||
this.props.notify('info', msg);
|
||||
});
|
||||
},
|
||||
},
|
||||
@@ -51,7 +66,12 @@ class FlaggedAccountsContainer extends Component {
|
||||
{ subscriptionData: { data: { usernameApproved: user } } }
|
||||
) => {
|
||||
return handleFlaggedUsernameChange(prev, user, () => {
|
||||
this.props.notify('info', `user ${user.username} approved`);
|
||||
const msg = t(
|
||||
'flagged_usernames.notify_approved',
|
||||
whoChangedTheStatus(user.state.status.username),
|
||||
user.username
|
||||
);
|
||||
this.props.notify('info', msg);
|
||||
});
|
||||
},
|
||||
},
|
||||
@@ -62,7 +82,12 @@ class FlaggedAccountsContainer extends Component {
|
||||
{ subscriptionData: { data: { usernameRejected: user } } }
|
||||
) => {
|
||||
return handleFlaggedUsernameChange(prev, user, () => {
|
||||
this.props.notify('info', `user ${user.username} rejected`);
|
||||
const msg = t(
|
||||
'flagged_usernames.notify_rejected',
|
||||
whoChangedTheStatus(user.state.status.username),
|
||||
user.username
|
||||
);
|
||||
this.props.notify('info', msg);
|
||||
});
|
||||
},
|
||||
},
|
||||
@@ -73,7 +98,8 @@ class FlaggedAccountsContainer extends Component {
|
||||
{ subscriptionData: { data: { usernameChanged: user } } }
|
||||
) => {
|
||||
return handleFlaggedUsernameChange(prev, user, () => {
|
||||
this.props.notify('info', `user ${user.username} changed`);
|
||||
const msg = t('flagged_usernames.notify_changed', 'TODO', user.username);
|
||||
this.props.notify('info', msg);
|
||||
});
|
||||
},
|
||||
},
|
||||
@@ -187,10 +213,28 @@ const LOAD_MORE_QUERY = gql`
|
||||
${FlaggedUser.fragments.user}
|
||||
`;
|
||||
|
||||
const historyFields = `
|
||||
state {
|
||||
status {
|
||||
username {
|
||||
history {
|
||||
status
|
||||
assigned_by {
|
||||
id
|
||||
username
|
||||
}
|
||||
created_at
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const USERNAME_FLAGGED_SUBSCRIPTION = gql`
|
||||
subscription TalkAdmin_UsernameFlagged {
|
||||
usernameFlagged {
|
||||
...${getDefinitionName(FlaggedUser.fragments.user)}
|
||||
${historyFields}
|
||||
}
|
||||
}
|
||||
${FlaggedUser.fragments.user}
|
||||
@@ -200,6 +244,7 @@ const USERNAME_APPROVED_SUBSCRIPTION = gql`
|
||||
subscription TalkAdmin_UsernameApproved {
|
||||
usernameApproved {
|
||||
...${getDefinitionName(FlaggedUser.fragments.user)}
|
||||
${historyFields}
|
||||
}
|
||||
}
|
||||
${FlaggedUser.fragments.user}
|
||||
@@ -209,6 +254,7 @@ const USERNAME_REJECTED_SUBSCRIPTION = gql`
|
||||
subscription TalkAdmin_UsernameRejected {
|
||||
usernameRejected {
|
||||
...${getDefinitionName(FlaggedUser.fragments.user)}
|
||||
${historyFields}
|
||||
}
|
||||
}
|
||||
${FlaggedUser.fragments.user}
|
||||
@@ -218,6 +264,7 @@ const USERNAME_CHANGED_SUBSCRIPTION = gql`
|
||||
subscription TalkAdmin_UsernameChanged {
|
||||
usernameChanged {
|
||||
...${getDefinitionName(FlaggedUser.fragments.user)}
|
||||
${historyFields}
|
||||
}
|
||||
}
|
||||
${FlaggedUser.fragments.user}
|
||||
|
||||
@@ -22,13 +22,6 @@ export default withFragments({
|
||||
status {
|
||||
username {
|
||||
status
|
||||
history {
|
||||
status
|
||||
assigned_by {
|
||||
id
|
||||
}
|
||||
created_at
|
||||
}
|
||||
}
|
||||
banned {
|
||||
status
|
||||
|
||||
@@ -56,13 +56,15 @@ function decrementFlaggedUserCount(root) {
|
||||
* @return {Object} next state of the store
|
||||
*/
|
||||
export function handleFlaggedUsernameChange(root, user, notify) {
|
||||
// Check if change came from current user, if so ignore it.
|
||||
const lastChange =
|
||||
user.state.status.username.history[
|
||||
user.state.status.username.history.length - 1
|
||||
];
|
||||
if (lastChange.assigned_by.id === root.me.id) {
|
||||
return root;
|
||||
if (user.state.status.username.status !== 'SET') {
|
||||
// Check if change came from current user, if so ignore it.
|
||||
const lastChange =
|
||||
user.state.status.username.history[
|
||||
user.state.status.username.history.length - 1
|
||||
];
|
||||
if (lastChange.assigned_by.id === root.me.id) {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasFlaggedUser(root, user)) {
|
||||
|
||||
@@ -61,6 +61,11 @@ en:
|
||||
reaction: 'reaction'
|
||||
reactions: 'reactions'
|
||||
story: 'Story'
|
||||
flagged_usernames:
|
||||
notify_approved: '{0} approved username {1}'
|
||||
notify_rejected: '{0} rejected username {1}'
|
||||
notify_flagged: '{0} reported username {1}'
|
||||
notify_changed: 'user {0} changed his username to {1}'
|
||||
community:
|
||||
account_creation_date: "Account Creation Date"
|
||||
active: Active
|
||||
|
||||
Reference in New Issue
Block a user