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

Commit

Permalink
Merge pull request #2560 from withspectrum/2.1.3
Browse files Browse the repository at this point in the history
2.1.3
  • Loading branch information
brianlovin authored Mar 12, 2018
2 parents 26e1394 + 872c592 commit aba3d7f
Show file tree
Hide file tree
Showing 54 changed files with 1,405 additions and 256 deletions.
4 changes: 1 addition & 3 deletions admin/src/views/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { usersQuery } from '../../api/queries';
import { displayLoadingState } from '../../components/loading';
import Chart from '../../components/spark-line';
import getGrowthPerDay from '../../utils/get-growth-per-day';
import Search from './components/search';
// import Search from './components/search';
import UserContainer from './containers/user';

class UsersViewIndex extends Component {
Expand All @@ -23,14 +23,12 @@ class UsersViewIndex extends Component {
if (match.params.username) {
return (
<View>
<Search />
<UserContainer username={match.params.username} />
</View>
);
} else {
return (
<View>
<Search />
<Chart height={128} data={userGrowth} />
</View>
);
Expand Down
50 changes: 8 additions & 42 deletions athena/utils/push-notifications/send-web-push-notification.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,17 @@
// @flow
const debug = require('debug')('athena:utils:web-push');
import webPush from 'web-push';
import sendWebPush from 'shared/send-web-push-notification';
import { removeSubscription } from '../../models/web-push-subscription';

try {
webPush.setVapidDetails(
'https://spectrum.chat',
process.env.VAPID_PUBLIC_KEY,
process.env.VAPID_PRIVATE_KEY
);
console.log('Web push notifications enabled!');
} catch (err) {}

export const sendWebPushNotification = (
subscription: any,
payload: Object | string,
options?: ?Object
): Promise<Object> => {
if (!subscription || !payload) {
debug(
'No subscription or payload provided to sendWebPushNotification, not pushing anything.'
);
return Promise.resolve({});
}
if (process.env.NODE_ENV === 'development') {
debug('not sending web push notification in development');
return Promise.resolve({});
} else {
debug('send web push notification');
}

const pl =
typeof payload === 'string'
? payload
: JSON.stringify({
...payload,
raw: undefined,
});
return webPush
.sendNotification(subscription, pl, {
TTL: 86400, // Default TTL: One day
...options,
})
.catch(err => {
if (err.statusCode === 410 && err.endpoint) {
debug(`old subscription found (${err.endpoint}), removing`, err);
return removeSubscription(err.endpoint);
}
});
): Promise<?Object> => {
return sendWebPush(subscription, payload, options).catch(err => {
if (err.statusCode === 410 && err.endpoint) {
debug(`old subscription found (${err.endpoint}), removing`, err);
return removeSubscription(err.endpoint);
}
});
};
9 changes: 7 additions & 2 deletions config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ module.exports = function override(config, env) {
// Don't return the cached index.html for API requests or /auth pages
if (url.pathname.indexOf('/api') === 0) return;
if (url.pathname.indexOf('/auth') === 0) return;
return new URL('https://spectrum.chat/index.html');
try {
return new URL('/index.html', url);
// TODO: Fix this properly instead of ignoring errors
} catch (err) {
return;
}
},
requestType: ['navigate'],
requestType: ['navigate', 'same-origin'],
},
],
ServiceWorker: {
Expand Down
18 changes: 3 additions & 15 deletions hyperion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Loadable from 'react-loadable';
import path from 'path';
import { getUser } from 'iris/models/user';
import Raven from 'shared/raven';
import toobusy from 'toobusy-js';
import toobusy from 'shared/middlewares/toobusy';

const PORT = process.env.PORT || 3006;

Expand All @@ -18,6 +18,8 @@ const app = express();
// Trust the now proxy
app.set('trust proxy', true);

app.use(toobusy);

if (process.env.NODE_ENV === 'development') {
const logging = require('shared/middlewares/logging');
app.use(logging);
Expand All @@ -29,20 +31,6 @@ if (process.env.NODE_ENV === 'production' && !process.env.FORCE_DEV) {
app.use(raven);
}

// middleware which blocks requests when we're too busy
app.use(
(req: express$Request, res: express$Response, next: express$NextFunction) => {
if (toobusy()) {
res.status(503);
res.send(
'It looks like Spectrum is very busy right now, please try again in a minute.'
);
} else {
next();
}
}
);

// Cross origin request support
import cors from 'shared/middlewares/cors';
app.use(cors);
Expand Down
52 changes: 39 additions & 13 deletions iris/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,12 @@ import { createServer } from 'http';
import express from 'express';
import Raven from 'shared/raven';
import { ApolloEngine } from 'apollo-engine';
import toobusy from 'shared/middlewares/toobusy';
import { init as initPassport } from './authentication.js';
import type { DBUser } from 'shared/types';

const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3001;

// const engine = new ApolloEngine({
// logging: {
// level: 'WARN',
// },
// apiKey: process.env.APOLLO_ENGINE_API_KEY,
// // Only send perf data to the remote server in production
// reporting: {
// disabled: process.env.NODE_ENV !== 'production',
// hostname: process.env.NOW_URL || undefined,
// privateHeaders: ['authorization', 'Authorization', 'AUTHORIZATION'],
// },
// });

// Initialize authentication
initPassport();

Expand All @@ -37,6 +25,9 @@ const app = express();
// Trust the now proxy
app.set('trust proxy', true);

// Return the request if the server is too busy
app.use(toobusy);

// Send all responses as gzip
app.use(compression());

Expand All @@ -49,6 +40,28 @@ app.use('/auth', authRoutes);
import apiRoutes from './routes/api';
app.use('/api', apiRoutes);

// $FlowIssue
app.use(
(
err: Error,
req: express$Request,
res: express$Response,
next: express$NextFunction
) => {
if (err) {
console.error(err);
res
.status(500)
.send(
'Oops, something went wrong! Our engineers have been alerted and will fix this asap.'
);
Raven.captureException(err);
} else {
return next();
}
}
);

import type { Loader } from './loaders/types';
export type GraphQLContext = {
user: DBUser,
Expand All @@ -64,6 +77,19 @@ import createSubscriptionsServer from './routes/create-subscription-server';
const subscriptionsServer = createSubscriptionsServer(server, '/websocket');

// Start API wrapped in Apollo Engine
// const engine = new ApolloEngine({
// logging: {
// level: 'WARN',
// },
// apiKey: process.env.APOLLO_ENGINE_API_KEY,
// // Only send perf data to the remote server in production
// reporting: {
// disabled: process.env.NODE_ENV !== 'production',
// hostname: process.env.NOW_URL || undefined,
// privateHeaders: ['authorization', 'Authorization', 'AUTHORIZATION'],
// },
// });

// engine.listen({
// port: PORT,
// httpServer: server,
Expand Down
6 changes: 6 additions & 0 deletions iris/loaders/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getCommunitiesMemberCounts,
getCommunitiesChannelCounts,
} from '../models/community';
import { getCommunitiesSettings } from '../models/communitySettings';
import { getCommunitiesRecurringPayments } from '../models/recurringPayment';
import createLoader from './create-loader';

Expand Down Expand Up @@ -32,6 +33,11 @@ export const __createCommunityChannelCountLoader = createLoader(
'group'
);

export const __createCommunitySettingsLoader = createLoader(
communityIds => getCommunitiesSettings(communityIds),
'group'
);

export default () => {
throw new Error(
'⚠️ Do not import loaders directly, get them from the GraphQL context instead! ⚠️'
Expand Down
2 changes: 2 additions & 0 deletions iris/loaders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
__createCommunityRecurringPaymentsLoader,
__createCommunityMemberCountLoader,
__createCommunityChannelCountLoader,
__createCommunitySettingsLoader,
} from './community';
import {
__createDirectMessageThreadLoader,
Expand Down Expand Up @@ -61,6 +62,7 @@ const createLoaders = (options?: DataLoaderOptions) => ({
communityRecurringPayments: __createCommunityRecurringPaymentsLoader(options),
communityChannelCount: __createCommunityChannelCountLoader(options),
communityMemberCount: __createCommunityMemberCountLoader(options),
communitySettings: __createCommunitySettingsLoader(options),
directMessageThread: __createDirectMessageThreadLoader(options),
directMessageParticipants: __createDirectMessageParticipantsLoader(options),
directMessageSnippet: __createDirectMessageSnippetLoader(options),
Expand Down
21 changes: 21 additions & 0 deletions iris/migrations/20180309144845-create-community-settings-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

exports.up = function(r, conn) {
return r
.tableCreate('communitySettings')
.run(conn)
.then(() =>
r
.table('communitySettings')
.indexCreate('communityId', r.row('communityId'))
.run(conn)
)
.catch(err => {
console.log(err);
throw err;
});
};

exports.down = function(r, conn) {
return Promise.all([r.tableDrop('communitySettings').run(conn)]);
};
90 changes: 90 additions & 0 deletions iris/models/communitySettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// @flow
const { db } = require('./db');
import type { DBCommunitySettings } from 'shared/types';
import { getCommunityById } from './community';

const defaultSettings = {
brandedLogin: {
isEnabled: false,
message: null,
},
};

export const getCommunitySettings = (id: string) => {
return db
.table('communitySettings')
.getAll(id, { index: 'communityId' })
.run()
.then(data => {
if (!data || data.length === 0) {
return defaultSettings;
}
return data[0];
});
};

export const getCommunitiesSettings = (
communityIds: Array<string>
): Promise<?DBCommunitySettings> => {
return db
.table('communitySettings')
.getAll(...communityIds, { index: 'communityId' })
.group('communityId')
.run();
};

export const createCommunitySettings = (id: string) => {
return db
.table('communitySettings')
.insert({
communityId: id,
brandedLogin: {
isEnabled: false,
message: null,
},
})
.run()
.then(async () => await getCommunityById(id));
};

export const enableCommunityBrandedLogin = (id: string) => {
return db
.table('communitySettings')
.getAll(id, { index: 'communityId' })
.update({
brandedLogin: {
isEnabled: true,
},
})
.run()
.then(async () => await getCommunityById(id));
};

export const disableCommunityBrandedLogin = (id: string) => {
return db
.table('communitySettings')
.getAll(id, { index: 'communityId' })
.update({
brandedLogin: {
isEnabled: false,
},
})
.run()
.then(async () => await getCommunityById(id));
};

export const updateCommunityBrandedLoginMessage = (
id: string,
message: ?string
) => {
return db
.table('communitySettings')
.getAll(id, { index: 'communityId' })
.update({
brandedLogin: {
message: message,
},
})
.run()
.then(async () => await getCommunityById(id));
};
2 changes: 1 addition & 1 deletion iris/models/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const IS_PROD = !process.env.FORCE_DEV && process.env.NODE_ENV === 'production';
const DEFAULT_CONFIG = {
// Connect to the test database when, well, testing
db: !process.env.TEST_DB ? 'spectrum' : 'testing',
max: 100, // Maximum number of connections, default is 1000
max: 500, // Maximum number of connections, default is 1000
buffer: 5, // Minimum number of connections open at any given moment, default is 50
timeoutGb: 60 * 1000, // How long should an unused connection stick around, default is an hour, this is a minute
pingInterval: 300, // Ping the connection every 5 minutes (300 seconds) to keep it alive and prevent rethinkdbdash#192
Expand Down
2 changes: 1 addition & 1 deletion iris/models/slackImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const generateOAuthToken = (code: string, redirect_uri: string) => {
'https://slack.com/api/oauth.access',
querystring.stringify({
code: code,
scope: 'users:read.email,users:read,admin',
scope: 'users:read.email,users:read,admin,chat:write',
client_id: '201769987287.200380534417',
client_secret: SLACK_SECRET,
redirect_uri,
Expand Down
Loading

0 comments on commit aba3d7f

Please sign in to comment.