diff --git a/client/coral-embed-stream/src/components/Stream.js b/client/coral-embed-stream/src/components/Stream.js
index 2297a295b..90fa0aca8 100644
--- a/client/coral-embed-stream/src/components/Stream.js
+++ b/client/coral-embed-stream/src/components/Stream.js
@@ -25,7 +25,7 @@ class Stream extends React.Component {
render() {
const {
- root: {asset, asset: {comments}, comment, myIgnoredUsers},
+ root: {asset, asset: {comments}, comment, me},
postComment,
addNotification,
postFlag,
@@ -58,8 +58,9 @@ class Stream extends React.Component {
const firstCommentDate = asset.comments[0]
? asset.comments[0].created_at
: new Date(Date.now() - 1000 * 60 * 60 * 24 * 7).toISOString();
- const commentIsIgnored = (comment) =>
- myIgnoredUsers && myIgnoredUsers.includes(comment.user.id);
+ const commentIsIgnored = (comment) => {
+ return me && me.ignoredUsers && me.ignoredUsers.find((u) => u.id === comment.user.id);
+ };
return (
{open
@@ -150,8 +151,8 @@ class Stream extends React.Component {
/>
{comments.map(
- (comment) =>
- (commentIsIgnored(comment)
+ (comment) => {
+ return (commentIsIgnored(comment)
?
: )
+ />
+ );
+ }
)}
{
+ return this.props.setCommentCountCache(commentCount);
+ });
}
this.countPoll = setInterval(() => {
this.getCounts(this.props.data.variables);
@@ -205,6 +208,9 @@ const fragments = {
}
me {
status
+ ignoredUsers {
+ id
+ }
}
...${getDefinitionName(Comment.fragments.root)}
}
diff --git a/client/coral-embed-stream/src/graphql/index.js b/client/coral-embed-stream/src/graphql/index.js
index 145098672..ccf6195f6 100644
--- a/client/coral-embed-stream/src/graphql/index.js
+++ b/client/coral-embed-stream/src/graphql/index.js
@@ -122,19 +122,40 @@ const extension = {
`,
},
mutations: {
- IgnoreUser: () => ({
-
- // TODO: don't rely on refetching.
- refetchQueries: [
- 'EmbedQuery', 'EmbedStreamProfileQuery',
- ],
+ IgnoreUser: ({variables}) => ({
+ updateQueries: {
+ EmbedQuery: (previousData, {mutationResult}) => {
+ const ignoredUserId = variables.id;
+ const response = mutationResult.data.ignoreUser;
+ if (ignoredUserId && !response.errors) {
+ const updated = update(previousData, {me: {ignoredUsers: {$push: [{
+ id: ignoredUserId,
+ __typename: 'User',
+ }]}}});
+ return updated;
+ }
+ return previousData;
+ }
+ }
}),
- StopIgnoringUser: () => ({
+ StopIgnoringUser: ({variables}) => ({
+ updateQueries: {
+ EmbedStreamProfileQuery: (previousData, {mutationResult}) => {
+ const noLongerIgnoredUserId = variables.id;
+ const response = mutationResult.data.stopIgnoringUser;
+ if (noLongerIgnoredUserId && !response.errors) {
- // TODO: don't rely on refetching.
- refetchQueries: [
- 'EmbedQuery', 'EmbedStreamProfileQuery',
- ],
+ // remove noLongerIgnoredUserId from ignoredUsers
+ const updated = update(previousData, {me: {ignoredUsers: {
+ $apply: (ignoredUsers) => {
+ return ignoredUsers.filter((u) => u.id !== noLongerIgnoredUserId);
+ }
+ }}});
+ return updated;
+ }
+ return previousData;
+ }
+ }
}),
PostComment: ({
variables: {comment: {asset_id, body, parent_id, tags = []}},
diff --git a/client/coral-framework/reducers/user.js b/client/coral-framework/reducers/user.js
index 2969665e3..bc40cf3ae 100644
--- a/client/coral-framework/reducers/user.js
+++ b/client/coral-framework/reducers/user.js
@@ -1,4 +1,4 @@
-import {Map, Set} from 'immutable';
+import {Map} from 'immutable';
import * as authActions from '../constants/auth';
import * as actions from '../constants/user';
import * as assetActions from '../constants/assets';
@@ -9,7 +9,6 @@ const initialState = Map({
settings: {},
myComments: [],
myAssets: [], // the assets from which myComments (above) originated
- ignoredUsers: Set(),
});
const purge = (user) => {
@@ -39,14 +38,6 @@ export default function user (state = initialState, action) {
return state.set('myAssets', action.assets);
case actions.LOGOUT_SUCCESS:
return initialState;
- case 'APOLLO_MUTATION_RESULT':
- switch (action.operationName) {
- case 'ignoreUser':
- return state.updateIn(['ignoredUsers'], (i) => i.add(action.variables.id));
- case 'stopIgnoringUser':
- return state.updateIn(['ignoredUsers'], (i) => i.delete(action.variables.id));
- }
- break;
}
return state;
}