Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4077 from withspectrum/2.4.43
Browse files Browse the repository at this point in the history
2.4.43
  • Loading branch information
brianlovin authored Oct 19, 2018
2 parents 0e5c074 + b10fd0d commit b99b58f
Show file tree
Hide file tree
Showing 29 changed files with 848 additions and 460 deletions.
1 change: 1 addition & 0 deletions api/models/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ const createChannel = ({ input }: CreateChannelInput, userId: string): Promise<D
slug,
isPrivate,
isDefault: isDefault ? true : false,
memberCount: 1,
},
{ returnChanges: true }
)
Expand Down
3 changes: 2 additions & 1 deletion api/models/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ export const createCommunity = ({ input }: CreateCommunityInput, user: DBUser):
modifiedAt: null,
creatorId: user.id,
administratorEmail: user.email,
isPrivate
isPrivate,
memberCount: 1,
},
{ returnChanges: true }
)
Expand Down
2 changes: 2 additions & 0 deletions api/models/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ export const publishThread = (
isPublished: true,
isLocked: false,
edits: [],
reactionCount: 0,
messageCount: 0,
}),
{ returnChanges: true }
)
Expand Down
57 changes: 33 additions & 24 deletions api/models/usersSettings.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
const { db } = require('./db');
import { events } from 'shared/analytics';
import { trackQueue } from 'shared/bull/queues';
import type { DBUserSettings } from 'shared/types';

export const createNewUsersSettings = (userId: string): Promise<Object> => {
export const createNewUsersSettings = (
userId: string
): Promise<DBUserSettings> => {
return db
.table('usersSettings')
.insert({
userId,
notifications: {
types: {
newMessageInThreads: {
email: true,
},
newMention: {
email: true,
},
newDirectMessage: {
email: true,
},
newThreadCreated: {
email: true,
},
dailyDigest: {
email: true,
},
weeklyDigest: {
email: true,
.insert(
{
userId,
notifications: {
types: {
newMessageInThreads: {
email: true,
},
newMention: {
email: true,
},
newDirectMessage: {
email: true,
},
newThreadCreated: {
email: true,
},
dailyDigest: {
email: true,
},
weeklyDigest: {
email: true,
},
},
},
},
})
.run();
{ returnChanges: 'always' }
)
.run()
.then(res => res.changes[0].new_val);
};

export const getUsersSettings = (userId: string): Promise<Object> => {
Expand All @@ -42,6 +49,8 @@ export const getUsersSettings = (userId: string): Promise<Object> => {
if (results && results.length > 0) {
// if the user already has a relationship with the thread we don't need to do anything, return
return results[0];
} else {
return null;
}
});
};
Expand Down
6 changes: 3 additions & 3 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"draft-js-prism-plugin": "0.1.1",
"draftjs-to-markdown": "^0.4.2",
"emoji-regex": "^6.1.1",
"express": "^4.16.3",
"express": "^4.16.4",
"express-session": "^1.15.2",
"faker": "^4.1.0",
"find-with-regex": "^1.1.3",
Expand All @@ -47,8 +47,8 @@
"graphql-depth-limit": "^1.1.0",
"graphql-log": "0.1.2",
"graphql-tools": "3.0.0",
"helmet": "^3.13.0",
"highlight.js": "^9.10.0",
"helmet": "^3.14.0",
"highlight.js": "^9.13.1",
"history": "^4.6.1",
"hoist-non-react-statics": "^2.5.5",
"host-validation": "^1.2.0",
Expand Down
46 changes: 22 additions & 24 deletions api/queries/channel/channelPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,29 @@
import type { GraphQLContext } from '../../';
import type { DBChannel } from 'shared/types';

export default (root: DBChannel, _: any, { user, loaders }: GraphQLContext) => {
export default async (
root: DBChannel,
_: any,
{ user, loaders }: GraphQLContext
) => {
const channelId = root.id;
const defaultPermissions = {
isOwner: false,
isMember: false,
isModerator: false,
isBlocked: false,
isPending: false,
receiveNotifications: false,
};

if (!channelId || !user) {
return {
isOwner: false,
isMember: false,
isModerator: false,
isBlocked: false,
isPending: false,
receiveNotifications: false,
};
return defaultPermissions;
}
return loaders.userPermissionsInChannel
.load([user.id, channelId])
.then(res => {
if (!res) {
return {
isOwner: false,
isMember: false,
isModerator: false,
isBlocked: false,
isPending: false,
receiveNotifications: false,
};
}
return res;
});

const permissions = await loaders.userPermissionsInChannel.load([
user.id,
channelId,
]);

return permissions || defaultPermissions;
};
31 changes: 21 additions & 10 deletions api/queries/channel/communityPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@
import type { GraphQLContext } from '../../';
import type { DBChannel } from 'shared/types';

export default (root: DBChannel, _: any, { user, loaders }: GraphQLContext) => {
export default async (
root: DBChannel,
_: any,
{ user, loaders }: GraphQLContext
) => {
const communityId = root.id || root.communityId;
const defaultPermissions = {
isOwner: false,
isMember: false,
isModerator: false,
isBlocked: false,
isPending: false,
receiveNotifications: false,
};

if (!communityId || !user) {
return {
isOwner: false,
isMember: false,
isModerator: false,
isBlocked: false,
isPending: false,
receiveNotifications: false,
};
return defaultPermissions;
}
return loaders.userPermissionsInCommunity.load([user.id, communityId]);

const permissions = await loaders.userPermissionsInCommunity.load([
user.id,
communityId,
]);
return permissions || defaultPermissions;
};
8 changes: 4 additions & 4 deletions api/queries/channel/metaData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import type { GraphQLContext } from '../../';
import type { DBChannel } from 'shared/types';
import Raven from 'shared/raven';

// NOTE(@mxstbr): metaData.threads is deprecated and not shown anywhere in the UI
// so we always return 0
export default async (
{ id, memberCount }: DBChannel,
_: any,
{ loaders }: GraphQLContext
) => {
const [threads] = await Promise.all([loaders.channelThreadCount.load(id)]);

if (typeof memberCount === 'number') {
return {
threads: threads ? threads.reduction : 0,
threads: 0,
members: memberCount || 1,
};
}
Expand All @@ -28,6 +28,6 @@ export default async (
.then(
res => (res && Array.isArray(res.reduction) ? res.reduction.length : 0)
),
threads: threads ? threads.reduction : 0,
threads: 0,
};
};
27 changes: 22 additions & 5 deletions api/queries/community/communityPermissions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
// @flow
import type { DBCommunity } from 'shared/types';
import type { GraphQLContext } from '../../';
import { DEFAULT_USER_COMMUNITY_PERMISSIONS } from '../../models/usersCommunities';

export default (
export default async (
{ id }: DBCommunity,
_: any,
{ user, loaders }: GraphQLContext
) => {
if (!id || !user) return {};
return loaders.userPermissionsInCommunity
.load([user.id, id])
.then(result => (result ? result : {}));
const defaultPermissions = {
...DEFAULT_USER_COMMUNITY_PERMISSIONS,
userId: null,
communityId: null,
};

if (!id || !user) return defaultPermissions;

const permissions = await loaders.userPermissionsInCommunity.load([
user.id,
id,
]);

const fallbackPermissions = {
...defaultPermissions,
userId: user.id,
communityId: id,
};

return permissions || fallbackPermissions;
};
11 changes: 8 additions & 3 deletions api/queries/user/settings.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// @flow
import type { GraphQLContext } from '../../';
import type { DBUser } from 'shared/types';
import { getUsersSettings } from '../../models/usersSettings';
import {
getUsersSettings,
createNewUsersSettings,
} from '../../models/usersSettings';
import UserError from '../../utils/UserError';

export default (_: DBUser, __: any, { user }: GraphQLContext) => {
export default async (_: DBUser, __: any, { user }: GraphQLContext) => {
if (!user) return new UserError('You must be signed in to continue.');
return getUsersSettings(user.id);
const settings = await getUsersSettings(user.id);
if (settings) return settings;
return await createNewUsersSettings(user.id);
};
1 change: 1 addition & 0 deletions api/types/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Channel = /* GraphQL */ `
type ChannelMetaData {
threads: Int
@deprecated(reason: "metaData.threads is deprecated and always returns 0")
members: Int
}
Expand Down
2 changes: 1 addition & 1 deletion api/types/CommunityMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const CommunityMember = /* GraphQL */ `
}
extend type Query {
communityMember(userId: String!, communityId: String!): CommunityMember
communityMember(userId: ID!, communityId: ID!): CommunityMember
}
input AddCommunityMemberInput {
Expand Down
2 changes: 1 addition & 1 deletion api/types/DirectMessageThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const DirectMessageThread = /* GraphQL */ `
after: String
): DirectMessagesConnection! @cost(complexity: 1, multipliers: ["first"])
participants: [ParticipantInfo]! @cost(complexity: 1)
snippet: String! @cost(complexity: 2)
snippet: String @cost(complexity: 2)
threadLastActive: Date!
}
Expand Down
Loading

0 comments on commit b99b58f

Please sign in to comment.