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

Commit 9342550

Browse files
authored
Merge pull request #4555 from withspectrum/2.6.1
2.6.1
2 parents c972275 + 07345a8 commit 9342550

File tree

63 files changed

+1388
-1330
lines changed

Some content is hidden

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

63 files changed

+1388
-1330
lines changed

admin/src/views/communities/components/search/index.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import pure from 'recompose/pure';
55
import { connect } from 'react-redux';
66
import { withApollo } from 'react-apollo';
77
import { withRouter } from 'react-router';
8+
import { ESC, BACKSPACE, ARROW_DOWN, ARROW_UP } from 'src/helpers/keycodes';
89
import { Spinner } from '../../../../components/globals';
910
import { throttle } from '../../../../helpers/utils';
1011
import { SEARCH_COMMUNITIES_QUERY } from '../../../../api/queries';
@@ -99,7 +100,7 @@ class Search extends Component {
99100
);
100101

101102
// if person presses esc, clear all results, stop loading
102-
if (e.keyCode === 27) {
103+
if (e.keyCode === ESC) {
103104
this.setState({
104105
searchResults: [],
105106
searchIsLoading: false,
@@ -108,14 +109,12 @@ class Search extends Component {
108109
return;
109110
}
110111

111-
// backspace
112-
if (e.keyCode === 8) {
112+
if (e.keyCode === BACKSPACE) {
113113
if (searchString.length > 0) return;
114114
return input && input.focus();
115115
}
116116

117-
//escape
118-
if (e.keyCode === 27) {
117+
if (e.keyCode === ESC) {
119118
this.setState({
120119
searchResults: [],
121120
searchIsLoading: false,
@@ -124,8 +123,7 @@ class Search extends Component {
124123
return input && input.focus();
125124
}
126125

127-
// down
128-
if (e.keyCode === 40) {
126+
if (e.keyCode === ARROW_DOWN) {
129127
if (indexOfFocusedSearchResult === searchResults.length - 1) return;
130128
if (searchResults.length === 1) return;
131129

@@ -137,8 +135,7 @@ class Search extends Component {
137135
return;
138136
}
139137

140-
// up
141-
if (e.keyCode === 38) {
138+
if (e.keyCode === ARROW_UP) {
142139
// 1
143140
if (indexOfFocusedSearchResult === 0) return;
144141
if (searchResults.length === 1) return;
@@ -151,8 +148,7 @@ class Search extends Component {
151148
return;
152149
}
153150

154-
// enter
155-
if (e.keyCode === 13) {
151+
if (e.keyCode === ENTER) {
156152
if (!searchResults[indexOfFocusedSearchResult]) return;
157153
return this.goToCommunity(searchResults[indexOfFocusedSearchResult].slug);
158154
}
@@ -261,4 +257,9 @@ class Search extends Component {
261257
}
262258
}
263259

264-
export default compose(withApollo, withRouter, connect(), pure)(Search);
260+
export default compose(
261+
withApollo,
262+
withRouter,
263+
connect(),
264+
pure
265+
)(Search);

admin/src/views/users/components/search/index.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import pure from 'recompose/pure';
66
import { connect } from 'react-redux';
77
import { withApollo } from 'react-apollo';
88
import { withRouter } from 'react-router';
9+
import {
10+
ESC,
11+
BACKSPACE,
12+
ENTER,
13+
ARROW_DOWN,
14+
ARROW_UP,
15+
} from 'src/helpers/keycodes';
916
import { Spinner } from '../../../../components/globals';
1017
import { throttle } from '../../../../helpers/utils';
1118
import { searchUsersQuery } from 'shared/graphql/queries/search/searchUsers';
@@ -104,8 +111,7 @@ class Search extends React.Component<Props, State> {
104111
focusedSearchResult
105112
);
106113

107-
// if person presses esc, clear all results, stop loading
108-
if (e.keyCode === 27) {
114+
if (e.keyCode === ESC) {
109115
this.setState({
110116
searchResults: [],
111117
searchIsLoading: false,
@@ -114,15 +120,13 @@ class Search extends React.Component<Props, State> {
114120
return;
115121
}
116122

117-
// backspace
118-
if (e.keyCode === 8) {
123+
if (e.keyCode === BACKSPACE) {
119124
if (searchString.length > 0) return;
120125
// $FlowFixMe
121126
return input && input.focus();
122127
}
123128

124-
//escape
125-
if (e.keyCode === 27) {
129+
if (e.keyCode === ESC) {
126130
this.setState({
127131
searchResults: [],
128132
searchIsLoading: false,
@@ -132,8 +136,7 @@ class Search extends React.Component<Props, State> {
132136
return input && input.focus();
133137
}
134138

135-
// down
136-
if (e.keyCode === 40) {
139+
if (e.keyCode === ARROW_DOWN) {
137140
if (indexOfFocusedSearchResult === searchResults.length - 1) return;
138141
if (searchResults.length === 1) return;
139142

@@ -145,8 +148,7 @@ class Search extends React.Component<Props, State> {
145148
return;
146149
}
147150

148-
// up
149-
if (e.keyCode === 38) {
151+
if (e.keyCode === ARROW_UP) {
150152
// 1
151153
if (indexOfFocusedSearchResult === 0) return;
152154
if (searchResults.length === 1) return;
@@ -159,8 +161,7 @@ class Search extends React.Component<Props, State> {
159161
return;
160162
}
161163

162-
// enter
163-
if (e.keyCode === 13) {
164+
if (e.keyCode === ENTER) {
164165
if (!searchResults[indexOfFocusedSearchResult]) return;
165166
return this.goToUser(searchResults[indexOfFocusedSearchResult].username);
166167
}
@@ -269,4 +270,9 @@ class Search extends React.Component<Props, State> {
269270
}
270271
}
271272

272-
export default compose(withApollo, withRouter, connect(), pure)(Search);
273+
export default compose(
274+
withApollo,
275+
withRouter,
276+
connect(),
277+
pure
278+
)(Search);

analytics/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"rethinkhaberdashery": "^2.3.32",
2424
"sanitize-filename": "^1.6.1",
2525
"sha1": "^1.1.1",
26-
"source-map-support": "^0.5.9",
26+
"source-map-support": "^0.5.10",
2727
"toobusy-js": "^0.5.1"
2828
}
2929
}

analytics/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,10 @@ sha1@^1.1.1:
627627
charenc ">= 0.0.1"
628628
crypt ">= 0.0.1"
629629

630-
source-map-support@^0.5.9:
631-
version "0.5.9"
632-
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.9.tgz#41bc953b2534267ea2d605bccfa7bfa3111ced5f"
633-
integrity sha512-gR6Rw4MvUlYy83vP0vxoVNzM6t8MUXqNuRsuBmBHQDu1Fh6X015FrLdgoDKcNdkwGubozq0P4N0Q37UyFVr1EA==
630+
source-map-support@^0.5.10:
631+
version "0.5.10"
632+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.10.tgz#2214080bc9d51832511ee2bab96e3c2f9353120c"
633+
integrity sha512-YfQ3tQFTK/yzlGJuX8pTwa4tifQj4QS2Mj7UegOu8jAz59MqIiMGPXxQhVQiIMNzayuUSF/jEuVnfFF5JqybmQ==
634634
dependencies:
635635
buffer-from "^1.0.0"
636636
source-map "^0.6.0"

api/apollo-server.js

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const server = new ProtectedApolloServer({
6464
new Promise((res, rej) =>
6565
req.login(data, err => (err ? rej(err) : res()))
6666
),
67+
req,
6768
user: currentUser,
6869
};
6970
},

api/models/community.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export type EditCommunityInput = {
210210
website: string,
211211
file: Object,
212212
coverFile: Object,
213+
coverPhoto: string,
213214
communityId: string,
214215
},
215216
};
@@ -410,7 +411,8 @@ export const createCommunity = ({ input }: CreateCommunityInput, user: DBUser):
410411
// prettier-ignore
411412
export const editCommunity = ({ input }: EditCommunityInput, userId: string): Promise<DBCommunity> => {
412413
const { name, slug, description, website, file, coverFile, communityId } = input
413-
414+
let { coverPhoto } = input
415+
414416
return db
415417
.table('communities')
416418
.get(communityId)
@@ -433,11 +435,15 @@ export const editCommunity = ({ input }: EditCommunityInput, userId: string): Pr
433435

434436
// if no file was uploaded, update the community with new string values
435437
if (!file && !coverFile) {
438+
// if the coverPhoto was deleted, reset to default
439+
if (!coverPhoto) {
440+
({ coverPhoto } = getRandomDefaultPhoto())
441+
}
436442
return db
437443
.table('communities')
438444
.get(communityId)
439-
.update({ ...community }, { returnChanges: 'always' })
440-
.run()
445+
.update({ ...community, coverPhoto }, { returnChanges: 'always' })
446+
.run()
441447
.then(result => {
442448
// if an update happened
443449
if (result.replaced === 1) {
@@ -466,6 +472,10 @@ export const editCommunity = ({ input }: EditCommunityInput, userId: string): Pr
466472

467473
if (file || coverFile) {
468474
if (file && !coverFile) {
475+
// if the coverPhoto was deleted, reset to default
476+
if (!coverPhoto) {
477+
({ coverPhoto } = getRandomDefaultPhoto())
478+
}
469479
return uploadImage(file, 'communities', community.id).then(
470480
profilePhoto => {
471481
// update the community with the profilePhoto
@@ -477,6 +487,7 @@ export const editCommunity = ({ input }: EditCommunityInput, userId: string): Pr
477487
{
478488
...community,
479489
profilePhoto,
490+
coverPhoto
480491
},
481492
{ returnChanges: 'always' }
482493
)

api/mutations/message/addMessage.js

+12-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow
2-
import { markdownToDraft } from 'markdown-draft-js';
2+
import { stateFromMarkdown } from 'draft-js-import-markdown';
3+
import { convertToRaw } from 'draft-js';
34
import type { GraphQLContext } from '../../';
45
import UserError from '../../utils/UserError';
56
import { uploadImage } from '../../utils/file-storage';
@@ -17,6 +18,7 @@ import {
1718
canViewDMThread,
1819
} from '../../utils/permissions';
1920
import { trackQueue, calculateThreadScoreQueue } from 'shared/bull/queues';
21+
import { validateRawContentState } from '../../utils/validate-draft-js-input';
2022

2123
type Input = {
2224
message: {
@@ -87,7 +89,13 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
8789

8890
if (message.messageType === 'text') {
8991
message.content.body = JSON.stringify(
90-
markdownToDraft(message.content.body)
92+
convertToRaw(
93+
stateFromMarkdown(message.content.body, {
94+
parserOptions: {
95+
breaks: true,
96+
},
97+
})
98+
)
9199
);
92100
message.messageType = 'draftjs';
93101
}
@@ -110,7 +118,7 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
110118
'Please provide serialized raw DraftJS content state as content.body'
111119
);
112120
}
113-
if (!body.blocks || !Array.isArray(body.blocks) || !body.entityMap) {
121+
if (!validateRawContentState(body)) {
114122
trackQueue.add({
115123
userId: user.id,
116124
event: eventFailed,
@@ -120,32 +128,10 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
120128
},
121129
});
122130

123-
return new UserError(
131+
throw new UserError(
124132
'Please provide serialized raw DraftJS content state as content.body'
125133
);
126134
}
127-
if (
128-
body.blocks.some(
129-
({ type }) =>
130-
!type ||
131-
(type !== 'unstyled' &&
132-
type !== 'code-block' &&
133-
type !== 'blockquote')
134-
)
135-
) {
136-
trackQueue.add({
137-
userId: user.id,
138-
event: eventFailed,
139-
properties: {
140-
reason: 'invalid draftjs data',
141-
message,
142-
},
143-
});
144-
145-
return new UserError(
146-
'Invalid DraftJS block type specified. Supported block types: "unstyled", "code-block".'
147-
);
148-
}
149135
}
150136

151137
if (message.parentId) {

0 commit comments

Comments
 (0)