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 #4966 from withspectrum/3.0.0
Browse files Browse the repository at this point in the history
3.0.0
  • Loading branch information
brianlovin authored Mar 26, 2019
2 parents 01bbf16 + fed0de5 commit f97aa8e
Show file tree
Hide file tree
Showing 572 changed files with 16,559 additions and 21,990 deletions.
12 changes: 10 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: 'eslint:recommended',
extends: ['eslint:recommended', 'plugin:react/recommended'],
parser: 'babel-eslint',
env: {
es6: true,
Expand All @@ -16,10 +16,18 @@ module.exports = {
rules: {
'no-undef': 0,
'no-console': ['warn', { allow: ['warn', 'error'] }],
'no-unused-vars': 0,
'no-unused-vars': 1,
'no-empty': 0,
'no-useless-escape': 1,
'no-fallthrough': 1,
'no-extra-boolean-cast': 1,
'react/prop-types': 0,
'react/no-deprecated': 0,
'react/display-name': 0,
'react/no-find-dom-node': 1,
'react/no-unescaped-entities': 'warn',
'react/no-string-refs': 'warn',
'react/jsx-no-target-blank': 'warn',
'react/no-children-prop': 0,
},
};
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ desktop/release
public/uploads
cypress/screenshots/
cypress/videos/
cacert
cacert
2 changes: 1 addition & 1 deletion analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"amplitude": "^3.5.0",
"aws-sdk": "^2.409.0",
"aws-sdk": "^2.426.0",
"bull": "3.3.10",
"datadog-metrics": "^0.8.1",
"debug": "^4.1.1",
Expand Down
8 changes: 4 additions & 4 deletions analytics/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ asynckit@^0.4.0:
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=

aws-sdk@^2.409.0:
version "2.409.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.409.0.tgz#d017060ba9e005487c68dc34a592af74d916f295"
integrity sha512-QV6j9zBQq/Kz8BqVOrJ03ABjMKtErXdUT1YdYEljoLQZimpzt0ZdQwJAsoZIsxxriOJgrqeZsQUklv9AFQaldQ==
aws-sdk@^2.426.0:
version "2.426.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.426.0.tgz#cf17361c987daf518f945218f06135fbc1a3690d"
integrity sha512-S4nmIhF/6iYeVEmKUWVG03zo1sw3zELoAPGqBKIZ3isrXbxkFXdP2cgIQxqi37zwWXSqaxt0xjeXVOMLzN6vSg==
dependencies:
buffer "4.9.1"
events "1.1.1"
Expand Down
38 changes: 29 additions & 9 deletions api/apollo-server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// @flow
const debug = require('debug')('api:graphql');
import { ApolloServer } from 'apollo-server-express';
import responseCachePlugin from 'apollo-server-plugin-response-cache';
import depthLimit from 'graphql-depth-limit';
import costAnalysis from 'graphql-cost-analysis';
import { RedisCache } from 'apollo-server-cache-redis';
import { config } from 'shared/cache/redis';
import createLoaders from './loaders';
import createErrorFormatter from './utils/create-graphql-error-formatter';
import schema from './schema';
import { setUserOnline } from 'shared/db/queries/user';
import { statsd } from 'shared/statsd';
import { getUserIdFromReq } from './utils/session-store';
import UserError from './utils/UserError';
import type { DBUser } from 'shared/types';
Expand Down Expand Up @@ -55,6 +60,7 @@ const server = new ProtectedApolloServer({
req.statsdTags = {
graphqlOperationName: req.body.operationName || 'unknown_operation',
};
debug(req.body.operationName || 'unknown_operation');
const loaders = createLoaders();
let currentUser = req.user && !req.user.bannedAt ? req.user : null;

Expand All @@ -70,20 +76,17 @@ const server = new ProtectedApolloServer({
},
subscriptions: {
path: '/websocket',
onOperation: (_: any, params: Object) => {
const errorFormatter = createErrorFormatter();
params.formatError = errorFormatter;
return params;
},
onDisconnect: rawSocket => {
statsd.increment('websocket.connections', -1);
return getUserIdFromReq(rawSocket.upgradeReq)
.then(id => id && setUserOnline(id, false))
.catch(err => {
console.error(err);
});
},
onConnect: (connectionParams, rawSocket) =>
getUserIdFromReq(rawSocket.upgradeReq)
onConnect: (connectionParams, rawSocket) => {
statsd.increment('websocket.connections', 1);
return getUserIdFromReq(rawSocket.upgradeReq)
.then(id => (id ? setUserOnline(id, true) : null))
.then(user => {
return {
Expand All @@ -96,7 +99,8 @@ const server = new ProtectedApolloServer({
return {
loaders: createLoaders({ cache: false }),
};
}),
});
},
},
playground: process.env.NODE_ENV !== 'production' && {
settings: {
Expand All @@ -118,8 +122,24 @@ const server = new ProtectedApolloServer({
maxFileSize: 25 * 1024 * 1024, // 25MB
engine: false,
tracing: false,
cacheControl: false,
validationRules: [depthLimit(10)],
cacheControl: {
calculateHttpHeaders: false,
// Cache everything for at least a minute since we only cache public responses
defaultMaxAge: 60,
},
cache: new RedisCache({
...config,
prefix: 'apollo-cache:',
}),
plugins: [
responseCachePlugin({
sessionId: ({ context }) => (context.user ? context.user.id : null),
// Only cache public responses
shouldReadFromCache: ({ context }) => !context.user,
shouldWriteToCache: ({ context }) => !context.user,
}),
],
});

export default server;
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
exports.up = function(r, conn) {
return Promise.all([
r
.table('usersCommunities')
.update(
{
lastSeen: r
.table('users')
.get(r.row('userId'))('lastSeen')
.default(r.row('lastSeen')),
},
{
nonAtomic: true,
}
)
.run(conn),
r
.table('communities')
.update(
{
lastActive: r
.table('threads')
.between(
[r.row('communityId'), r.minval],
[r.row('communityId'), r.maxval],
{
index: 'communityIdAndLastActive',
leftBound: 'open',
rightBound: 'open',
}
)
.orderBy({ index: r.desc('communityIdAndLastActive') })
.limit(1)('lastActive')
.default(r.row('createdAt')),
},
{
nonAtomic: true,
}
)
.run(conn),
]);
};

exports.down = function(r, conn) {
return Promise.all([
r
.table('usersCommunities')
.update({
lastSeen: r.literal(),
})
.run(conn),
r
.table('communities')
.update({
lastActive: r.literal(),
})
.run(conn),
]);
};
18 changes: 18 additions & 0 deletions api/migrations/seed/default/channelSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const constants = require('./constants');
const { PAYMENTS_PRIVATE_CHANNEL_ID } = constants;

module.exports = [
{
id: 1,
channelId: PAYMENTS_PRIVATE_CHANNEL_ID,
joinSettings: {
tokenJoinEnabled: true,
token: 'abc',
},
slackSettings: {
botLinks: {
threadCreated: null,
},
},
},
];
15 changes: 15 additions & 0 deletions api/migrations/seed/default/communities.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
DELETED_COMMUNITY_ID,
PRIVATE_COMMUNITY_ID,
SINGLE_CHANNEL_COMMUNITY_ID,
PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID,
} = constants;

module.exports = [
Expand Down Expand Up @@ -81,4 +82,18 @@ module.exports = [
slug: 'single',
memberCount: 1,
},
{
id: PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID,
createdAt: new Date(DATE),
isPrivate: true,
name: 'private community with join token',
description: 'private community with join token',
website: 'https://spectrum.chat',
profilePhoto:
'https://spectrum.imgix.net/communities/-Kh6RfPYjmSaIWbkck8i/Twitter Profile.png.0.6225566835336693',
coverPhoto:
'https://spectrum.imgix.net/communities/-Kh6RfPYjmSaIWbkck8i/Twitter Header.png.0.3303118636071434',
slug: 'private-join',
memberCount: 1,
},
];
54 changes: 54 additions & 0 deletions api/migrations/seed/default/communitySettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const constants = require('./constants');
const {
PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID,
PAYMENTS_COMMUNITY_ID,
} = constants;

module.exports = [
{
id: 1,
communityId: PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID,
brandedLogin: {
isEnabled: false,
message: null,
},
slackSettings: {
connectedAt: null,
connectedBy: null,
teamName: null,
teamId: null,
scope: null,
token: null,
invitesSentAt: null,
invitesMemberCount: null,
invitesCustomMessage: null,
},
joinSettings: {
tokenJoinEnabled: true,
token: 'abc',
},
},
{
id: 2,
communityId: PAYMENTS_COMMUNITY_ID,
brandedLogin: {
isEnabled: false,
message: null,
},
slackSettings: {
connectedAt: null,
connectedBy: null,
teamName: null,
teamId: null,
scope: null,
token: null,
invitesSentAt: null,
invitesMemberCount: null,
invitesCustomMessage: null,
},
joinSettings: {
tokenJoinEnabled: true,
token: 'abc',
},
},
];
4 changes: 4 additions & 0 deletions api/migrations/seed/default/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ const COMMUNITY_MODERATOR_USER_ID = '9';
// this user is only a member of one community, and that community only has
// one channel - use for testing the composer community+channel selection
const SINGLE_CHANNEL_COMMUNITY_USER_ID = '10';
const NEW_USER_ID = '11';

// communities
const SPECTRUM_COMMUNITY_ID = '1';
const PAYMENTS_COMMUNITY_ID = '2';
const DELETED_COMMUNITY_ID = '3';
const PRIVATE_COMMUNITY_ID = '4';
const SINGLE_CHANNEL_COMMUNITY_ID = '5';
const PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID = '6';

// channels
const SPECTRUM_GENERAL_CHANNEL_ID = '1';
Expand All @@ -53,6 +55,8 @@ module.exports = {
CHANNEL_MODERATOR_USER_ID,
COMMUNITY_MODERATOR_USER_ID,
SINGLE_CHANNEL_COMMUNITY_USER_ID,
PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID,
NEW_USER_ID,
SPECTRUM_COMMUNITY_ID,
PAYMENTS_COMMUNITY_ID,
DELETED_COMMUNITY_ID,
Expand Down
6 changes: 4 additions & 2 deletions api/migrations/seed/default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const defaultMessages = require('./messages');
const defaultReactions = require('./reactions');
const defaultUsersNotifications = require('./usersNotifications');
const defaultNotifications = require('./notifications');
const defaultCommunitySettings = require('./communitySettings');
const defaultChannelSettings = require('./channelSettings');

module.exports = {
constants,
Expand All @@ -30,7 +32,7 @@ module.exports = {
defaultUsersSettings,
defaultNotifications,
defaultUsersNotifications,
defaultCommunitySettings: [],
defaultChannelSettings: [],
defaultCommunitySettings,
defaultChannelSettings,
defaultReactions,
};
15 changes: 15 additions & 0 deletions api/migrations/seed/default/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
CHANNEL_MODERATOR_USER_ID,
COMMUNITY_MODERATOR_USER_ID,
SINGLE_CHANNEL_COMMUNITY_USER_ID,
NEW_USER_ID,
DATE,
} = constants;

Expand Down Expand Up @@ -143,4 +144,18 @@ module.exports = [
createdAt: new Date(DATE),
lastSeen: new Date(DATE),
},
{
id: NEW_USER_ID,
name: 'New user',
description: 'Just joined spectrum',
website: '',
username: null,
profilePhoto:
'https://pbs.twimg.com/profile_images/848823167699230721/-9CbPtto_bigger.jpg',
coverPhoto:
'https://pbs.twimg.com/profile_banners/17106008/1491444958/1500x500',
email: 'hi@newuser.io',
createdAt: new Date(DATE),
lastSeen: new Date(DATE),
},
];
Loading

0 comments on commit f97aa8e

Please sign in to comment.