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

Commit f97aa8e

Browse files
authored
Merge pull request #4966 from withspectrum/3.0.0
3.0.0
2 parents 01bbf16 + fed0de5 commit f97aa8e

File tree

572 files changed

+16559
-21990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

572 files changed

+16559
-21990
lines changed

Diff for: .eslintrc.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
extends: 'eslint:recommended',
2+
extends: ['eslint:recommended', 'plugin:react/recommended'],
33
parser: 'babel-eslint',
44
env: {
55
es6: true,
@@ -16,10 +16,18 @@ module.exports = {
1616
rules: {
1717
'no-undef': 0,
1818
'no-console': ['warn', { allow: ['warn', 'error'] }],
19-
'no-unused-vars': 0,
19+
'no-unused-vars': 1,
2020
'no-empty': 0,
2121
'no-useless-escape': 1,
2222
'no-fallthrough': 1,
2323
'no-extra-boolean-cast': 1,
24+
'react/prop-types': 0,
25+
'react/no-deprecated': 0,
26+
'react/display-name': 0,
27+
'react/no-find-dom-node': 1,
28+
'react/no-unescaped-entities': 'warn',
29+
'react/no-string-refs': 'warn',
30+
'react/jsx-no-target-blank': 'warn',
31+
'react/no-children-prop': 0,
2432
},
2533
};

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ desktop/release
3434
public/uploads
3535
cypress/screenshots/
3636
cypress/videos/
37-
cacert
37+
cacert

Diff for: analytics/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"dependencies": {
77
"amplitude": "^3.5.0",
8-
"aws-sdk": "^2.409.0",
8+
"aws-sdk": "^2.426.0",
99
"bull": "3.3.10",
1010
"datadog-metrics": "^0.8.1",
1111
"debug": "^4.1.1",

Diff for: analytics/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ asynckit@^0.4.0:
1414
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
1515
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=
1616

17-
aws-sdk@^2.409.0:
18-
version "2.409.0"
19-
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.409.0.tgz#d017060ba9e005487c68dc34a592af74d916f295"
20-
integrity sha512-QV6j9zBQq/Kz8BqVOrJ03ABjMKtErXdUT1YdYEljoLQZimpzt0ZdQwJAsoZIsxxriOJgrqeZsQUklv9AFQaldQ==
17+
aws-sdk@^2.426.0:
18+
version "2.426.0"
19+
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.426.0.tgz#cf17361c987daf518f945218f06135fbc1a3690d"
20+
integrity sha512-S4nmIhF/6iYeVEmKUWVG03zo1sw3zELoAPGqBKIZ3isrXbxkFXdP2cgIQxqi37zwWXSqaxt0xjeXVOMLzN6vSg==
2121
dependencies:
2222
buffer "4.9.1"
2323
events "1.1.1"

Diff for: api/apollo-server.js

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// @flow
2+
const debug = require('debug')('api:graphql');
23
import { ApolloServer } from 'apollo-server-express';
4+
import responseCachePlugin from 'apollo-server-plugin-response-cache';
35
import depthLimit from 'graphql-depth-limit';
46
import costAnalysis from 'graphql-cost-analysis';
7+
import { RedisCache } from 'apollo-server-cache-redis';
8+
import { config } from 'shared/cache/redis';
59
import createLoaders from './loaders';
610
import createErrorFormatter from './utils/create-graphql-error-formatter';
711
import schema from './schema';
812
import { setUserOnline } from 'shared/db/queries/user';
13+
import { statsd } from 'shared/statsd';
914
import { getUserIdFromReq } from './utils/session-store';
1015
import UserError from './utils/UserError';
1116
import type { DBUser } from 'shared/types';
@@ -55,6 +60,7 @@ const server = new ProtectedApolloServer({
5560
req.statsdTags = {
5661
graphqlOperationName: req.body.operationName || 'unknown_operation',
5762
};
63+
debug(req.body.operationName || 'unknown_operation');
5864
const loaders = createLoaders();
5965
let currentUser = req.user && !req.user.bannedAt ? req.user : null;
6066

@@ -70,20 +76,17 @@ const server = new ProtectedApolloServer({
7076
},
7177
subscriptions: {
7278
path: '/websocket',
73-
onOperation: (_: any, params: Object) => {
74-
const errorFormatter = createErrorFormatter();
75-
params.formatError = errorFormatter;
76-
return params;
77-
},
7879
onDisconnect: rawSocket => {
80+
statsd.increment('websocket.connections', -1);
7981
return getUserIdFromReq(rawSocket.upgradeReq)
8082
.then(id => id && setUserOnline(id, false))
8183
.catch(err => {
8284
console.error(err);
8385
});
8486
},
85-
onConnect: (connectionParams, rawSocket) =>
86-
getUserIdFromReq(rawSocket.upgradeReq)
87+
onConnect: (connectionParams, rawSocket) => {
88+
statsd.increment('websocket.connections', 1);
89+
return getUserIdFromReq(rawSocket.upgradeReq)
8790
.then(id => (id ? setUserOnline(id, true) : null))
8891
.then(user => {
8992
return {
@@ -96,7 +99,8 @@ const server = new ProtectedApolloServer({
9699
return {
97100
loaders: createLoaders({ cache: false }),
98101
};
99-
}),
102+
});
103+
},
100104
},
101105
playground: process.env.NODE_ENV !== 'production' && {
102106
settings: {
@@ -118,8 +122,24 @@ const server = new ProtectedApolloServer({
118122
maxFileSize: 25 * 1024 * 1024, // 25MB
119123
engine: false,
120124
tracing: false,
121-
cacheControl: false,
122125
validationRules: [depthLimit(10)],
126+
cacheControl: {
127+
calculateHttpHeaders: false,
128+
// Cache everything for at least a minute since we only cache public responses
129+
defaultMaxAge: 60,
130+
},
131+
cache: new RedisCache({
132+
...config,
133+
prefix: 'apollo-cache:',
134+
}),
135+
plugins: [
136+
responseCachePlugin({
137+
sessionId: ({ context }) => (context.user ? context.user.id : null),
138+
// Only cache public responses
139+
shouldReadFromCache: ({ context }) => !context.user,
140+
shouldWriteToCache: ({ context }) => !context.user,
141+
}),
142+
],
123143
});
124144

125145
export default server;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
exports.up = function(r, conn) {
2+
return Promise.all([
3+
r
4+
.table('usersCommunities')
5+
.update(
6+
{
7+
lastSeen: r
8+
.table('users')
9+
.get(r.row('userId'))('lastSeen')
10+
.default(r.row('lastSeen')),
11+
},
12+
{
13+
nonAtomic: true,
14+
}
15+
)
16+
.run(conn),
17+
r
18+
.table('communities')
19+
.update(
20+
{
21+
lastActive: r
22+
.table('threads')
23+
.between(
24+
[r.row('communityId'), r.minval],
25+
[r.row('communityId'), r.maxval],
26+
{
27+
index: 'communityIdAndLastActive',
28+
leftBound: 'open',
29+
rightBound: 'open',
30+
}
31+
)
32+
.orderBy({ index: r.desc('communityIdAndLastActive') })
33+
.limit(1)('lastActive')
34+
.default(r.row('createdAt')),
35+
},
36+
{
37+
nonAtomic: true,
38+
}
39+
)
40+
.run(conn),
41+
]);
42+
};
43+
44+
exports.down = function(r, conn) {
45+
return Promise.all([
46+
r
47+
.table('usersCommunities')
48+
.update({
49+
lastSeen: r.literal(),
50+
})
51+
.run(conn),
52+
r
53+
.table('communities')
54+
.update({
55+
lastActive: r.literal(),
56+
})
57+
.run(conn),
58+
]);
59+
};

Diff for: api/migrations/seed/default/channelSettings.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const constants = require('./constants');
2+
const { PAYMENTS_PRIVATE_CHANNEL_ID } = constants;
3+
4+
module.exports = [
5+
{
6+
id: 1,
7+
channelId: PAYMENTS_PRIVATE_CHANNEL_ID,
8+
joinSettings: {
9+
tokenJoinEnabled: true,
10+
token: 'abc',
11+
},
12+
slackSettings: {
13+
botLinks: {
14+
threadCreated: null,
15+
},
16+
},
17+
},
18+
];

Diff for: api/migrations/seed/default/communities.js

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
DELETED_COMMUNITY_ID,
88
PRIVATE_COMMUNITY_ID,
99
SINGLE_CHANNEL_COMMUNITY_ID,
10+
PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID,
1011
} = constants;
1112

1213
module.exports = [
@@ -81,4 +82,18 @@ module.exports = [
8182
slug: 'single',
8283
memberCount: 1,
8384
},
85+
{
86+
id: PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID,
87+
createdAt: new Date(DATE),
88+
isPrivate: true,
89+
name: 'private community with join token',
90+
description: 'private community with join token',
91+
website: 'https://spectrum.chat',
92+
profilePhoto:
93+
'https://spectrum.imgix.net/communities/-Kh6RfPYjmSaIWbkck8i/Twitter Profile.png.0.6225566835336693',
94+
coverPhoto:
95+
'https://spectrum.imgix.net/communities/-Kh6RfPYjmSaIWbkck8i/Twitter Header.png.0.3303118636071434',
96+
slug: 'private-join',
97+
memberCount: 1,
98+
},
8499
];

Diff for: api/migrations/seed/default/communitySettings.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const constants = require('./constants');
2+
const {
3+
PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID,
4+
PAYMENTS_COMMUNITY_ID,
5+
} = constants;
6+
7+
module.exports = [
8+
{
9+
id: 1,
10+
communityId: PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID,
11+
brandedLogin: {
12+
isEnabled: false,
13+
message: null,
14+
},
15+
slackSettings: {
16+
connectedAt: null,
17+
connectedBy: null,
18+
teamName: null,
19+
teamId: null,
20+
scope: null,
21+
token: null,
22+
invitesSentAt: null,
23+
invitesMemberCount: null,
24+
invitesCustomMessage: null,
25+
},
26+
joinSettings: {
27+
tokenJoinEnabled: true,
28+
token: 'abc',
29+
},
30+
},
31+
{
32+
id: 2,
33+
communityId: PAYMENTS_COMMUNITY_ID,
34+
brandedLogin: {
35+
isEnabled: false,
36+
message: null,
37+
},
38+
slackSettings: {
39+
connectedAt: null,
40+
connectedBy: null,
41+
teamName: null,
42+
teamId: null,
43+
scope: null,
44+
token: null,
45+
invitesSentAt: null,
46+
invitesMemberCount: null,
47+
invitesCustomMessage: null,
48+
},
49+
joinSettings: {
50+
tokenJoinEnabled: true,
51+
token: 'abc',
52+
},
53+
},
54+
];

Diff for: api/migrations/seed/default/constants.js

+4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ const COMMUNITY_MODERATOR_USER_ID = '9';
2020
// this user is only a member of one community, and that community only has
2121
// one channel - use for testing the composer community+channel selection
2222
const SINGLE_CHANNEL_COMMUNITY_USER_ID = '10';
23+
const NEW_USER_ID = '11';
2324

2425
// communities
2526
const SPECTRUM_COMMUNITY_ID = '1';
2627
const PAYMENTS_COMMUNITY_ID = '2';
2728
const DELETED_COMMUNITY_ID = '3';
2829
const PRIVATE_COMMUNITY_ID = '4';
2930
const SINGLE_CHANNEL_COMMUNITY_ID = '5';
31+
const PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID = '6';
3032

3133
// channels
3234
const SPECTRUM_GENERAL_CHANNEL_ID = '1';
@@ -53,6 +55,8 @@ module.exports = {
5355
CHANNEL_MODERATOR_USER_ID,
5456
COMMUNITY_MODERATOR_USER_ID,
5557
SINGLE_CHANNEL_COMMUNITY_USER_ID,
58+
PRIVATE_COMMUNITY_WITH_JOIN_TOKEN_ID,
59+
NEW_USER_ID,
5660
SPECTRUM_COMMUNITY_ID,
5761
PAYMENTS_COMMUNITY_ID,
5862
DELETED_COMMUNITY_ID,

Diff for: api/migrations/seed/default/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const defaultMessages = require('./messages');
1414
const defaultReactions = require('./reactions');
1515
const defaultUsersNotifications = require('./usersNotifications');
1616
const defaultNotifications = require('./notifications');
17+
const defaultCommunitySettings = require('./communitySettings');
18+
const defaultChannelSettings = require('./channelSettings');
1719

1820
module.exports = {
1921
constants,
@@ -30,7 +32,7 @@ module.exports = {
3032
defaultUsersSettings,
3133
defaultNotifications,
3234
defaultUsersNotifications,
33-
defaultCommunitySettings: [],
34-
defaultChannelSettings: [],
35+
defaultCommunitySettings,
36+
defaultChannelSettings,
3537
defaultReactions,
3638
};

Diff for: api/migrations/seed/default/users.js

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
CHANNEL_MODERATOR_USER_ID,
1111
COMMUNITY_MODERATOR_USER_ID,
1212
SINGLE_CHANNEL_COMMUNITY_USER_ID,
13+
NEW_USER_ID,
1314
DATE,
1415
} = constants;
1516

@@ -143,4 +144,18 @@ module.exports = [
143144
createdAt: new Date(DATE),
144145
lastSeen: new Date(DATE),
145146
},
147+
{
148+
id: NEW_USER_ID,
149+
name: 'New user',
150+
description: 'Just joined spectrum',
151+
website: '',
152+
username: null,
153+
profilePhoto:
154+
'https://pbs.twimg.com/profile_images/848823167699230721/-9CbPtto_bigger.jpg',
155+
coverPhoto:
156+
'https://pbs.twimg.com/profile_banners/17106008/1491444958/1500x500',
157+
158+
createdAt: new Date(DATE),
159+
lastSeen: new Date(DATE),
160+
},
146161
];

0 commit comments

Comments
 (0)