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

Commit

Permalink
Merge pull request #4847 from withspectrum/2.8.4
Browse files Browse the repository at this point in the history
2.8.4
  • Loading branch information
brianlovin authored Mar 9, 2019
2 parents 489e89c + 73303e8 commit e63c167
Show file tree
Hide file tree
Showing 38 changed files with 510 additions and 147 deletions.
50 changes: 40 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# CircleCI configuration for Spectrum
# CircleCI configuration for Spectrum
version: 2.1

# Aliases
aliases:
Expand Down Expand Up @@ -63,7 +64,6 @@ js_defaults: &js_defaults
docker:
- image: circleci/node:8

version: 2
jobs:

# Set up environment and install required dependencies
Expand All @@ -72,9 +72,9 @@ jobs:
steps:
- checkout

- restore-cache: *restore-yarn-cache
- restore_cache: *restore-yarn-cache
- run: *yarn
- save-cache: *save-yarn-cache
- save_cache: *save-yarn-cache

- persist_to_workspace:
root: .
Expand Down Expand Up @@ -112,15 +112,19 @@ jobs:


# Start db and servers, then run e2e and unit tests
test_e2e:
test_integration:
<<: *defaults
docker:
- image: circleci/node:8-browsers
- image: redis:3.2.7
- image: cypress/base:6
- image: rethinkdb:2.3.5
parallel: true
parallelism: 9
parameters:
parallelism:
type: integer
default: 1
description: Number of boxes to use to run this job
parallelism: <<parameters.parallelism>>
environment:
TERM: xterm
steps:
Expand All @@ -144,6 +148,14 @@ jobs:
yarn run test:e2e
fi
# This runs after the above and is only here to hack around missing support for varying jobs based on external vs internal PRs
# See https://github.com/withspectrum/spectrum/pull/4820
test_e2e:
docker:
- image: cypress/base:10
steps:
- run: echo "pass"

# Run eslint, flow etc.
test_static_js:
<<: *js_defaults
Expand All @@ -158,8 +170,6 @@ jobs:
command: yarn run lint

workflows:
version: 2

test:
jobs:
- checkout_environment
Expand All @@ -172,6 +182,26 @@ workflows:
- build_web:
requires:
- checkout_environment
- test_e2e:
# Run pull requests from internal contributors in parallel
- test_integration:
name: test_e2e_internal
requires:
- build_web
parallelism: 4
filters:
branches:
ignore: /pull.*/
# Run pull requests from external contributors on one machine
- test_integration:
name: test_e2e_external
requires:
- build_web
parallelism: 1
filters:
branches:
only: /pull.*/
# If either of the test_e2e_* jobs pass, this one passes so we can mark it as required on GitHub
- test_e2e:
requires:
- test_e2e_internal
- test_e2e_external
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import type { FileUpload } from 'shared/types';
import { events } from 'shared/analytics';
import { trackQueue } from 'shared/bull/queues';
import { isAuthedResolver as requireAuth } from '../../utils/permissions';
import { messageTypeObj } from 'shared/draft-utils/process-message-content';
import type { MessageType } from 'shared/draft-utils/process-message-content';
import { messageTypeObj } from 'shared/draft-utils/message-types';
import type { MessageType } from 'shared/draft-utils/message-types';

export type CreateDirectMessageThreadInput = {
input: {
Expand Down
3 changes: 2 additions & 1 deletion api/mutations/message/addMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { validateRawContentState } from '../../utils/validate-draft-js-input';
import processMessageContent, {
messageTypeObj,
} from 'shared/draft-utils/process-message-content';
import type { MessageType } from 'shared/draft-utils/process-message-content';
import type { MessageType } from 'shared/draft-utils/message-types';

type Input = {
message: {
Expand All @@ -34,6 +34,7 @@ type Input = {
},
parentId?: string,
file?: FileUpload,
bot?: boolean,
},
};

Expand Down
2 changes: 1 addition & 1 deletion api/mutations/message/editMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { validateRawContentState } from '../../utils/validate-draft-js-input';
import processMessageContent, {
messageTypeObj,
} from 'shared/draft-utils/process-message-content';
import type { MessageType } from 'shared/draft-utils/process-message-content';
import type { MessageType } from 'shared/draft-utils/message-types';

type Args = {
input: {
Expand Down
34 changes: 18 additions & 16 deletions api/mutations/thread/publishThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,22 +348,24 @@ export default requireAuth(
await createParticipantInThread(dbThread.id, user.id);

// Post a new message with a link to the new thread to the watercooler thread if one exists
// if (community.watercoolerId && !channel.isPrivate) {
// const identifier = user.username ? `@${user.username}` : user.name;
// await addMessage(
// {
// content: {
// body: `${identifier} just posted a new thread 📝 https://spectrum.chat/${
// community.slug
// }/${channel.slug}/${slugg(dbThread.content.title)}~${dbThread.id}`,
// },
// messageType: 'text',
// threadId: community.watercoolerId,
// threadType: 'story',
// },
// 'sam'
// );
// }
if (community.watercoolerId && !channel.isPrivate) {
await addMessage(
{
content: {
body: `${
user.name
} just posted a new thread 📝 https://spectrum.chat/${
community.slug
}/${channel.slug}/${slugg(dbThread.content.title)}~${dbThread.id}`,
},
messageType: 'text',
threadId: community.watercoolerId,
threadType: 'story',
bot: true,
},
user.id
);
}

if (!thread.filesToUpload || thread.filesToUpload.length === 0) {
return dbThread;
Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"sanitize-filename": "^1.6.1",
"serialize-javascript": "^1.6.1",
"session-rethinkdb": "^2.0.0",
"slate": "^0.44.10",
"slate": "^0.44.11",
"slate-markdown": "0.1.0",
"slugg": "^1.1.0",
"string-replace-to-array": "^1.0.3",
Expand Down
15 changes: 13 additions & 2 deletions api/queries/thread/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
import type { GraphQLContext } from '../../';
import type { DBThread } from 'shared/types';

export default ({ channelId }: DBThread, _: any, { loaders }: GraphQLContext) =>
loaders.channel.load(channelId);
export default async (root: DBThread, _: any, ctx: GraphQLContext) => {
const { channelId, id } = root;
const { loaders } = ctx;
const channel = await loaders.channel.load(channelId);
if (!channel) {
console.error(
'User queried thread of non-existent/deleted channel: ',
channelId
);
console.error('Thread queried: ', id);
}
return channel;
};
18 changes: 13 additions & 5 deletions api/queries/thread/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
import type { GraphQLContext } from '../../';
import type { DBThread } from 'shared/types';

export default (
{ communityId }: DBThread,
_: any,
{ loaders }: GraphQLContext
) => loaders.community.load(communityId);
export default async (root: DBThread, _: any, ctx: GraphQLContext) => {
const { communityId, id } = root;
const { loaders } = ctx;
const community = await loaders.community.load(communityId);
if (!community) {
console.error(
'User queried thread of non-existent/deleted community: ',
communityId
);
console.error('Thread queried: ', id);
}
return community;
};
1 change: 1 addition & 0 deletions api/types/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const Message = /* GraphQL */ `
messageType: MessageTypes!
parent: Message
modifiedAt: Date
bot: Boolean
sender: User! @deprecated(reason: "Use Message.author field instead")
}
Expand Down
8 changes: 4 additions & 4 deletions api/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8726,10 +8726,10 @@ [email protected]:
react "^0.14.0 || ^15.0.0"
styled-components "^2.0.0"

slate@^0.44.10:
version "0.44.10"
resolved "https://registry.yarnpkg.com/slate/-/slate-0.44.10.tgz#ac7c3e3cf85570a8723a64a8a7807c881ddbfa8a"
integrity sha512-2jMPgOjExjeWfHrYUsYTMLo/ykbXjCwLUFwG3G34Q0vwRsmf4yOf3b0Zx5LoUaNlyvQDdBsOGsF1qi6yTx53DA==
slate@^0.44.11:
version "0.44.11"
resolved "https://registry.yarnpkg.com/slate/-/slate-0.44.11.tgz#0cdf454726a6d45a6dbf3174ea3f6261ad1a0428"
integrity sha512-ZtNCxHtGMuWXwUb6vmbrLR73MbHeEQ1LRJNIIyEpj1Kixk0Sd0T+zSKI+cBWCXlOOITqFEfBcJOWaSppiID+1A==
dependencies:
debug "^3.1.0"
direction "^0.1.5"
Expand Down
3 changes: 3 additions & 0 deletions athena/queues/new-message-in-thread/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export default async (job: Job<MessageNotificationJobData>) => {
}`
);

// Do not send notification emails for bot messages
if (incomingMessage.bot) return;

// Check to see if an existing notif exists by matching the 'event' type, with the context of the notification, within a certain time period.
const existing = await checkForExistingNotification(
'MESSAGE_CREATED',
Expand Down
53 changes: 53 additions & 0 deletions flow-typed/npm/snarkdown_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// flow-typed signature: 8f063755e65f032485439ac4cefffded
// flow-typed version: <<STUB>>/snarkdown_vx.x.x/flow_v0.66.0

/**
* This is an autogenerated libdef stub for:
*
* 'snarkdown'
*
* Fill this stub out by replacing all the `any` types.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/

declare module 'snarkdown' {
declare module.exports: any;
}

/**
* We include stubs for each file inside this npm package in case you need to
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
declare module 'snarkdown/dist/snarkdown.es' {
declare module.exports: any;
}

declare module 'snarkdown/dist/snarkdown' {
declare module.exports: any;
}

declare module 'snarkdown/dist/snarkdown.umd' {
declare module.exports: any;
}

declare module 'snarkdown/src/index' {
declare module.exports: any;
}

// Filename aliases
declare module 'snarkdown/dist/snarkdown.es.js' {
declare module.exports: $Exports<'snarkdown/dist/snarkdown.es'>;
}
declare module 'snarkdown/dist/snarkdown.js' {
declare module.exports: $Exports<'snarkdown/dist/snarkdown'>;
}
declare module 'snarkdown/dist/snarkdown.umd.js' {
declare module.exports: $Exports<'snarkdown/dist/snarkdown.umd'>;
}
declare module 'snarkdown/src/index.js' {
declare module.exports: $Exports<'snarkdown/src/index'>;
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Spectrum",
"version": "2.8.3",
"version": "2.8.4",
"license": "BSD-3-Clause",
"devDependencies": {
"@babel/preset-flow": "^7.0.0",
Expand Down Expand Up @@ -194,6 +194,7 @@
"slate": "^0.20.1",
"slate-markdown": "0.1.1",
"slugg": "^1.1.0",
"snarkdown": "^1.2.2",
"stopword": "^0.1.13",
"string-replace-to-array": "^1.0.3",
"string-similarity": "^2.0.0",
Expand Down Expand Up @@ -293,4 +294,4 @@
]
},
"pre-commit": "lint:staged"
}
}
9 changes: 2 additions & 7 deletions shared/clients/draft-js/utils/isShort.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
// @flow
// Determine whether a DraftJS message is short
import { toPlainText, toState } from '../../../draft-utils';

import type { RawDraftContentState } from 'draft-js';
import { toPlainText } from './plaintext';
import type { MessageInfoType } from '../../../graphql/fragments/message/messageInfo';

export const isShort = (message: MessageInfoType): boolean => {
if (message.messageType === 'media') return false;
const jsonBody = JSON.parse(message.content.body);
return (
jsonBody.blocks.length <= 1 && toPlainText(toState(jsonBody)).length <= 170
);
return jsonBody.blocks.length <= 1 && toPlainText(jsonBody).length <= 170;
};
9 changes: 9 additions & 0 deletions shared/clients/draft-js/utils/plaintext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @flow
import type { RawContentState } from 'draft-js';

export const toPlainText = (raw: RawContentState) => {
return raw.blocks
.filter(block => block.type === 'unstyled')
.map(block => block.text)
.join('\n');
};
15 changes: 1 addition & 14 deletions shared/draft-utils/add-embeds-to-draft-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const addEmbedsToEditorState = (
if (block.type !== 'unstyled') return;

const embeds = getEmbedsFromText(block.text);
if (!embeds.length === 0) return;
if (embeds.length === 0) return;

embeds.forEach(embed => {
lastEntityKey++;
Expand Down Expand Up @@ -64,19 +64,6 @@ export const addEmbedsToEditorState = (
type: 'embed',
};
});
// If this is the last block we need to add an empty block below the atomic block,
// otherwise users cannot remove the embed during editing
if (index === input.blocks.length - 1) {
newBlocks.push({
type: 'unstyled',
data: {},
text: ' ',
depth: 0,
entityRanges: [],
inlineStyleRanges: [],
key: genKey(),
});
}
});

return {
Expand Down
Loading

0 comments on commit e63c167

Please sign in to comment.