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

Commit e128219

Browse files
authored
Merge pull request #4179 from withspectrum/2.4.57
2.4.57
2 parents b3a8c31 + 4b0fdd7 commit e128219

Some content is hidden

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

46 files changed

+4531
-1187
lines changed

.circleci/config.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,18 @@ jobs:
111111
- run: *start-web
112112
# Wait for the API and webserver to start
113113
- run: ./node_modules/.bin/wait-on http://localhost:3000 http://localhost:3001
114+
- run:
115+
name: Run Unit Tests
116+
command: yarn run test:ci
117+
- run:
118+
name: Install Cypress
119+
command: yarn run cypress:install
114120
- run:
115121
name: Run E2E Tests
116122
command: test $CYPRESS_RECORD_KEY && yarn run test:e2e -- --record || yarn run test:e2e
117123
- run:
118-
name: Build desktop apps
119-
command: yarn run build:desktop
124+
name: Test desktop apps
125+
command: yarn run test:desktop
120126

121127
# deploy_alpha:
122128
# <<: *js_defaults

.flowconfig

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@
1111
.*/node_modules/react-navigation
1212
.*/node_modules/reqwest
1313
.*/node_modules/sentry-expo
14-
1514
.*/node_modules/react-apollo
1615
.*/node_modules/dataloader
17-
18-
19-
[include]
20-
21-
[libs]
16+
<PROJECT_ROOT>/node_modules/*
2217

2318
[options]
2419
suppress_comment=.*\\$FlowFixMe
@@ -41,4 +36,4 @@ unclear-type=warn
4136
unsafe-getters-setters=error
4237

4338
[version]
44-
0.66.0
39+
0.66.0
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
exports.up = async function(r, conn) {
2+
const messages = await r
3+
.db('spectrum')
4+
.table('messages')
5+
.filter({ messageType: 'media' })
6+
.filter(row => row('timestamp').lt(r.epochTime(1540929600)))
7+
.filter(row => row('content')('body').match('spectrum.imgix.net'))
8+
.filter(row => row('content')('body').match('%20'))
9+
.filter(row => row.hasFields('deletedAt').not())
10+
.map(row => ({ id: row('id'), url: row('content')('body') }))
11+
.run(conn)
12+
.then(cursor => cursor.toArray());
13+
14+
const messagePromises = messages.map(async obj => {
15+
return await r
16+
.db('spectrum')
17+
.table('messages')
18+
.get(obj.id)
19+
.update({
20+
content: {
21+
body: decodeURIComponent(obj.url),
22+
},
23+
imageReplaced: new Date(),
24+
})
25+
.run(conn);
26+
});
27+
28+
return await Promise.all(messagePromises);
29+
};
30+
31+
exports.down = function(r, conn) {
32+
return Promise.resolve();
33+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
exports.up = async function(r, conn) {
2+
const threads = await r
3+
.db('spectrum')
4+
.table('threads')
5+
.filter(row => row('modifiedAt').lt(r.epochTime(1540929600)))
6+
.filter(row => row('content')('body').match('spectrum.imgix.net'))
7+
.filter(row => row('content')('body').match('%20'))
8+
.filter(row => row.hasFields('deletedAt').not())
9+
.map(row => ({ id: row('id'), body: row('content')('body') }))
10+
.run(conn)
11+
.then(cursor => cursor.toArray());
12+
13+
const threadPromises = threads.map(async obj => {
14+
const newBody = JSON.parse(obj.body);
15+
16+
const imageKeys = Object.keys(newBody.entityMap).filter(
17+
key => newBody.entityMap[key].type.toLowerCase() === 'image'
18+
);
19+
20+
const LEGACY_PREFIX = 'https://spectrum.imgix.net/';
21+
const hasLegacyPrefix = url => url.startsWith(LEGACY_PREFIX, 0);
22+
const stripLegacyPrefix = url => url.replace(LEGACY_PREFIX, '');
23+
24+
const processImageUrl = str => {
25+
if (str.indexOf(LEGACY_PREFIX) < 0) {
26+
return str;
27+
}
28+
if (str.indexOf('%20') < 0) {
29+
return str;
30+
}
31+
32+
const split = str.split('?');
33+
const imagePath = split[0];
34+
35+
const decoded = decodeURIComponent(imagePath);
36+
37+
const processed = hasLegacyPrefix(decoded)
38+
? stripLegacyPrefix(decoded)
39+
: decoded;
40+
41+
return processed;
42+
};
43+
44+
imageKeys.forEach((key, index) => {
45+
if (!newBody.entityMap[key]) {
46+
return;
47+
}
48+
49+
const { src } = newBody.entityMap[key].data;
50+
newBody.entityMap[key].data.src = processImageUrl(src);
51+
});
52+
53+
return await r
54+
.db('spectrum')
55+
.table('threads')
56+
.get(obj.id)
57+
.update({
58+
content: {
59+
body: JSON.stringify(newBody),
60+
},
61+
imageReplaced: new Date(),
62+
})
63+
.run(conn);
64+
});
65+
66+
return await Promise.all(threadPromises);
67+
};
68+
69+
exports.down = function(r, conn) {
70+
return Promise.resolve();
71+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
exports.up = async function(r, conn) {
2+
const communities = await r
3+
.db('spectrum')
4+
.table('communities')
5+
.filter(row => row('modifiedAt').lt(r.epochTime(1540929600)))
6+
.filter(row =>
7+
row('profilePhoto')
8+
.match('spectrum.imgix.net')
9+
.or(row('coverPhoto').match('spectrum.imgix.net'))
10+
)
11+
.filter(row =>
12+
row('profilePhoto')
13+
.match('%20')
14+
.or(row('coverPhoto').match('%20'))
15+
)
16+
.filter(row => row.hasFields('deletedAt').not())
17+
.map(row => ({
18+
id: row('id'),
19+
profilePhoto: row('profilePhoto'),
20+
coverPhoto: row('coverPhoto'),
21+
}))
22+
.run(conn)
23+
.then(cursor => cursor.toArray());
24+
25+
const communityPromises = communities.map(async obj => {
26+
const { profilePhoto, coverPhoto } = obj;
27+
28+
const LEGACY_PREFIX = 'https://spectrum.imgix.net/';
29+
const hasLegacyPrefix = url => url.startsWith(LEGACY_PREFIX, 0);
30+
const stripLegacyPrefix = url => url.replace(LEGACY_PREFIX, '');
31+
32+
const processImageUrl = str => {
33+
if (str.indexOf(LEGACY_PREFIX) < 0) {
34+
return str;
35+
}
36+
37+
if (str.indexOf('%20') < 0) {
38+
return str;
39+
}
40+
41+
const split = str.split('?');
42+
const imagePath = split[0];
43+
44+
const decoded = decodeURIComponent(imagePath);
45+
46+
const processed = hasLegacyPrefix(decoded)
47+
? stripLegacyPrefix(decoded)
48+
: decoded;
49+
50+
return processed;
51+
};
52+
53+
const newProfilePhoto = processImageUrl(profilePhoto);
54+
const newCoverPhoto = processImageUrl(coverPhoto);
55+
56+
return await r
57+
.db('spectrum')
58+
.table('communities')
59+
.get(obj.id)
60+
.update({
61+
coverPhoto: newCoverPhoto,
62+
profilePhoto: newProfilePhoto,
63+
imageReplaced: new Date(),
64+
})
65+
.run(conn);
66+
});
67+
68+
return await Promise.all(communityPromises);
69+
};
70+
71+
exports.down = function(r, conn) {
72+
return Promise.resolve();
73+
};
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
exports.up = async function(r, conn) {
2+
const users = await r
3+
.db('spectrum')
4+
.table('users')
5+
.filter(row => row('modifiedAt').lt(r.epochTime(1540929600)))
6+
.filter(row =>
7+
row.hasFields('coverPhoto').and(row.hasFields('profilePhoto'))
8+
)
9+
.filter(row =>
10+
row('profilePhoto')
11+
.match('spectrum.imgix.net')
12+
.or(row('coverPhoto').match('spectrum.imgix.net'))
13+
)
14+
.filter(row =>
15+
row('profilePhoto')
16+
.match('%20')
17+
.or(row('coverPhoto').match('%20'))
18+
)
19+
.filter(row => row.hasFields('deletedAt').not())
20+
.map(row => ({
21+
id: row('id'),
22+
profilePhoto: row('profilePhoto'),
23+
coverPhoto: row('coverPhoto'),
24+
}))
25+
.run(conn)
26+
.then(cursor => cursor.toArray());
27+
28+
const userPromises = users.map(async obj => {
29+
const { profilePhoto, coverPhoto } = obj;
30+
31+
const LEGACY_PREFIX = 'https://spectrum.imgix.net/';
32+
const hasLegacyPrefix = url => url.startsWith(LEGACY_PREFIX, 0);
33+
const stripLegacyPrefix = url => url.replace(LEGACY_PREFIX, '');
34+
35+
const processImageUrl = str => {
36+
if (str.indexOf(LEGACY_PREFIX) < 0) {
37+
return str;
38+
}
39+
40+
if (str.indexOf('%20') < 0) {
41+
return str;
42+
}
43+
44+
const split = str.split('?');
45+
const imagePath = split[0];
46+
47+
const decoded = decodeURIComponent(imagePath);
48+
49+
const processed = hasLegacyPrefix(decoded)
50+
? stripLegacyPrefix(decoded)
51+
: decoded;
52+
53+
return processed;
54+
};
55+
56+
const newProfilePhoto = processImageUrl(profilePhoto);
57+
const newCoverPhoto = processImageUrl(coverPhoto);
58+
59+
return await r
60+
.db('spectrum')
61+
.table('users')
62+
.get(obj.id)
63+
.update({
64+
coverPhoto: newCoverPhoto,
65+
profilePhoto: newProfilePhoto,
66+
imageReplaced: new Date(),
67+
})
68+
.run(conn);
69+
});
70+
71+
return await Promise.all(userPromises);
72+
};
73+
74+
exports.down = function(r, conn) {
75+
return Promise.resolve();
76+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
exports.up = async function(r, conn) {
2+
const LEGACY_PREFIX = 'https://s3.amazonaws.com/spectrum-chat/';
3+
4+
const communities = await r
5+
.db('spectrum')
6+
.table('communities')
7+
.filter(row =>
8+
row('profilePhoto')
9+
.match(LEGACY_PREFIX)
10+
.or(row('coverPhoto').match(LEGACY_PREFIX))
11+
)
12+
.filter(row => row.hasFields('deletedAt').not())
13+
.map(row => ({
14+
id: row('id'),
15+
profilePhoto: row('profilePhoto'),
16+
coverPhoto: row('coverPhoto'),
17+
}))
18+
.run(conn)
19+
.then(cursor => cursor.toArray());
20+
21+
const communityPromises = communities.map(async obj => {
22+
const { profilePhoto, coverPhoto } = obj;
23+
const hasLegacyPrefix = url => url.startsWith(LEGACY_PREFIX, 0);
24+
const stripLegacyPrefix = url => url.replace(LEGACY_PREFIX, '');
25+
26+
const processImageUrl = str => {
27+
if (str.indexOf(LEGACY_PREFIX) < 0) {
28+
return str;
29+
}
30+
31+
return stripLegacyPrefix(str);
32+
};
33+
34+
const newProfilePhoto = processImageUrl(profilePhoto);
35+
const newCoverPhoto = processImageUrl(coverPhoto);
36+
37+
return await r
38+
.db('spectrum')
39+
.table('communities')
40+
.get(obj.id)
41+
.update({
42+
coverPhoto: newCoverPhoto,
43+
profilePhoto: newProfilePhoto,
44+
awsStaticReplaced: new Date(),
45+
})
46+
.run(conn);
47+
});
48+
49+
return await Promise.all(communityPromises);
50+
};
51+
52+
exports.down = function(r, conn) {
53+
return Promise.resolve();
54+
};

api/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"engines": {
3+
"node": "9.x.x"
4+
},
25
"dependencies": {
36
"algoliasearch": "^3.30.0",
47
"apollo-engine": "^1.1.2",
@@ -12,7 +15,7 @@
1215
"babel-plugin-transform-flow-strip-types": "^6.22.0",
1316
"babel-plugin-transform-object-rest-spread": "^6.23.0",
1417
"babel-preset-env": "^1.7.0",
15-
"backpack-core": "^0.4.1",
18+
"backpack-core": "^0.8.1",
1619
"body-parser": "^1.18.3",
1720
"bull": "3.3.10",
1821
"casual": "^1.5.12",
@@ -112,7 +115,7 @@
112115
"serialize-javascript": "^1.5.0",
113116
"session-rethinkdb": "^2.0.0",
114117
"shortid": "^2.2.13",
115-
"slate": "^0.43.0",
118+
"slate": "^0.43.3",
116119
"slate-markdown": "0.1.0",
117120
"slugg": "^1.1.0",
118121
"string-replace-to-array": "^1.0.3",

api/utils/get-random-default-photo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const PALETTE = [
1717
export default () => {
1818
const color = faker.random.arrayElement(PALETTE);
1919
return {
20-
profilePhoto: `https://s3.amazonaws.com/spectrum-chat/default_images/profile-${color}.png`,
21-
coverPhoto: `https://s3.amazonaws.com/spectrum-chat/default_images/cover-${color}.svg`,
20+
profilePhoto: `/default_images/profile-${color}.png`,
21+
coverPhoto: `/default_images/cover-${color}.svg`,
2222
};
2323
};

0 commit comments

Comments
 (0)