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

Commit 73303e8

Browse files
committed
Merge branch 'alpha' of github.com:withspectrum/spectrum into 2.8.4
2 parents a2f8f2d + f9a0a43 commit 73303e8

File tree

24 files changed

+327
-107
lines changed

24 files changed

+327
-107
lines changed

api/mutations/directMessageThread/createDirectMessageThread.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import type { FileUpload } from 'shared/types';
1717
import { events } from 'shared/analytics';
1818
import { trackQueue } from 'shared/bull/queues';
1919
import { isAuthedResolver as requireAuth } from '../../utils/permissions';
20-
import { messageTypeObj } from 'shared/draft-utils/process-message-content';
21-
import type { MessageType } from 'shared/draft-utils/process-message-content';
20+
import { messageTypeObj } from 'shared/draft-utils/message-types';
21+
import type { MessageType } from 'shared/draft-utils/message-types';
2222

2323
export type CreateDirectMessageThreadInput = {
2424
input: {

api/mutations/message/addMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { validateRawContentState } from '../../utils/validate-draft-js-input';
2222
import processMessageContent, {
2323
messageTypeObj,
2424
} from 'shared/draft-utils/process-message-content';
25-
import type { MessageType } from 'shared/draft-utils/process-message-content';
25+
import type { MessageType } from 'shared/draft-utils/message-types';
2626

2727
type Input = {
2828
message: {

api/mutations/message/editMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { validateRawContentState } from '../../utils/validate-draft-js-input';
1919
import processMessageContent, {
2020
messageTypeObj,
2121
} from 'shared/draft-utils/process-message-content';
22-
import type { MessageType } from 'shared/draft-utils/process-message-content';
22+
import type { MessageType } from 'shared/draft-utils/message-types';
2323

2424
type Args = {
2525
input: {

api/queries/thread/channel.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,16 @@
22
import type { GraphQLContext } from '../../';
33
import type { DBThread } from 'shared/types';
44

5-
export default ({ channelId }: DBThread, _: any, { loaders }: GraphQLContext) =>
6-
loaders.channel.load(channelId);
5+
export default async (root: DBThread, _: any, ctx: GraphQLContext) => {
6+
const { channelId, id } = root;
7+
const { loaders } = ctx;
8+
const channel = await loaders.channel.load(channelId);
9+
if (!channel) {
10+
console.error(
11+
'User queried thread of non-existent/deleted channel: ',
12+
channelId
13+
);
14+
console.error('Thread queried: ', id);
15+
}
16+
return channel;
17+
};

api/queries/thread/community.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
import type { GraphQLContext } from '../../';
33
import type { DBThread } from 'shared/types';
44

5-
export default (
6-
{ communityId }: DBThread,
7-
_: any,
8-
{ loaders }: GraphQLContext
9-
) => loaders.community.load(communityId);
5+
export default async (root: DBThread, _: any, ctx: GraphQLContext) => {
6+
const { communityId, id } = root;
7+
const { loaders } = ctx;
8+
const community = await loaders.community.load(communityId);
9+
if (!community) {
10+
console.error(
11+
'User queried thread of non-existent/deleted community: ',
12+
communityId
13+
);
14+
console.error('Thread queried: ', id);
15+
}
16+
return community;
17+
};

flow-typed/npm/snarkdown_vx.x.x.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// flow-typed signature: 8f063755e65f032485439ac4cefffded
2+
// flow-typed version: <<STUB>>/snarkdown_vx.x.x/flow_v0.66.0
3+
4+
/**
5+
* This is an autogenerated libdef stub for:
6+
*
7+
* 'snarkdown'
8+
*
9+
* Fill this stub out by replacing all the `any` types.
10+
*
11+
* Once filled out, we encourage you to share your work with the
12+
* community by sending a pull request to:
13+
* https://github.com/flowtype/flow-typed
14+
*/
15+
16+
declare module 'snarkdown' {
17+
declare module.exports: any;
18+
}
19+
20+
/**
21+
* We include stubs for each file inside this npm package in case you need to
22+
* require those files directly. Feel free to delete any files that aren't
23+
* needed.
24+
*/
25+
declare module 'snarkdown/dist/snarkdown.es' {
26+
declare module.exports: any;
27+
}
28+
29+
declare module 'snarkdown/dist/snarkdown' {
30+
declare module.exports: any;
31+
}
32+
33+
declare module 'snarkdown/dist/snarkdown.umd' {
34+
declare module.exports: any;
35+
}
36+
37+
declare module 'snarkdown/src/index' {
38+
declare module.exports: any;
39+
}
40+
41+
// Filename aliases
42+
declare module 'snarkdown/dist/snarkdown.es.js' {
43+
declare module.exports: $Exports<'snarkdown/dist/snarkdown.es'>;
44+
}
45+
declare module 'snarkdown/dist/snarkdown.js' {
46+
declare module.exports: $Exports<'snarkdown/dist/snarkdown'>;
47+
}
48+
declare module 'snarkdown/dist/snarkdown.umd.js' {
49+
declare module.exports: $Exports<'snarkdown/dist/snarkdown.umd'>;
50+
}
51+
declare module 'snarkdown/src/index.js' {
52+
declare module.exports: $Exports<'snarkdown/src/index'>;
53+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
"slate": "^0.20.1",
195195
"slate-markdown": "0.1.1",
196196
"slugg": "^1.1.0",
197+
"snarkdown": "^1.2.2",
197198
"stopword": "^0.1.13",
198199
"string-replace-to-array": "^1.0.3",
199200
"string-similarity": "^2.0.0",
@@ -293,4 +294,4 @@
293294
]
294295
},
295296
"pre-commit": "lint:staged"
296-
}
297+
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
// @flow
2-
// Determine whether a DraftJS message is short
3-
import { toPlainText, toState } from '../../../draft-utils';
4-
5-
import type { RawDraftContentState } from 'draft-js';
2+
import { toPlainText } from './plaintext';
63
import type { MessageInfoType } from '../../../graphql/fragments/message/messageInfo';
74

85
export const isShort = (message: MessageInfoType): boolean => {
96
if (message.messageType === 'media') return false;
107
const jsonBody = JSON.parse(message.content.body);
11-
return (
12-
jsonBody.blocks.length <= 1 && toPlainText(toState(jsonBody)).length <= 170
13-
);
8+
return jsonBody.blocks.length <= 1 && toPlainText(jsonBody).length <= 170;
149
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @flow
2+
import type { RawContentState } from 'draft-js';
3+
4+
export const toPlainText = (raw: RawContentState) => {
5+
return raw.blocks
6+
.filter(block => block.type === 'unstyled')
7+
.map(block => block.text)
8+
.join('\n');
9+
};

shared/draft-utils/add-embeds-to-draft-js.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const addEmbedsToEditorState = (
3434
if (block.type !== 'unstyled') return;
3535

3636
const embeds = getEmbedsFromText(block.text);
37-
if (!embeds.length === 0) return;
37+
if (embeds.length === 0) return;
3838

3939
embeds.forEach(embed => {
4040
lastEntityKey++;
@@ -64,19 +64,6 @@ export const addEmbedsToEditorState = (
6464
type: 'embed',
6565
};
6666
});
67-
// If this is the last block we need to add an empty block below the atomic block,
68-
// otherwise users cannot remove the embed during editing
69-
if (index === input.blocks.length - 1) {
70-
newBlocks.push({
71-
type: 'unstyled',
72-
data: {},
73-
text: ' ',
74-
depth: 0,
75-
entityRanges: [],
76-
inlineStyleRanges: [],
77-
key: genKey(),
78-
});
79-
}
8067
});
8168

8269
return {

0 commit comments

Comments
 (0)