Skip to content

Commit

Permalink
get collection name from typename on nova:subscribe, add missing impo…
Browse files Browse the repository at this point in the history
…rt on previous commit
  • Loading branch information
xavxyz committed Feb 10, 2017
1 parent 6833b35 commit c33ebd5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/nova-lib/lib/modules/apollo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ApolloClient, { createNetworkInterface } from 'apollo-client';
import 'isomorphic-fetch';
import { getSetting } from './settings.js';

const defaultNetworkInterfaceConfig = {
path: '/graphql',
Expand Down
2 changes: 1 addition & 1 deletion packages/nova-subscribe/lib/components/SubscribeTo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const subscribeMutationContainer = ({documentType, actionName}) => graphql(gql`

const SubscribeTo = props => {

const documentType = `${props.document.__typename.toLowerCase()}s`;
const documentType = Utils.getCollectionNameFromTypename(props.document.__typename);

const withSubscribeMutations = ['Subscribe', 'Unsubscribe'].map(actionName => subscribeMutationContainer({documentType, actionName}));

Expand Down
5 changes: 3 additions & 2 deletions packages/nova-subscribe/lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Users from 'meteor/nova:users';
import { Utils } from 'meteor/nova:core';

Users.isSubscribedTo = (user, document) => {
// return user && document && document.subscribers && document.subscribers.indexOf(user._id) !== -1;

if (!user || !document) {
// should return an error
return false;
}

const { __typename, _id: itemId } = document;
const documentType = __typename + 's';
const documentType = Utils.capitalize(Utils.getCollectionNameFromTypename(__typename));

if (user.subscribedItems && user.subscribedItems[documentType]) {
return !!user.subscribedItems[documentType].find(subscribedItems => subscribedItems.itemId === itemId);
Expand Down

0 comments on commit c33ebd5

Please sign in to comment.