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 #4142 from withspectrum/2.4.52
Browse files Browse the repository at this point in the history
2.4.52
  • Loading branch information
brianlovin authored Oct 27, 2018
2 parents 67f0212 + 412edfb commit c777fbb
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exports.up = function(r, conn) {
return Promise.all([
r
.table('threads')
.update({
attachments: r.literal(),
})
.run(conn),
]).catch(err => console.error(err));
};
exports.down = function(r, conn) {
return Promise.resolve();
};
13 changes: 0 additions & 13 deletions api/migrations/seed/default/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = [
{
id: '1',
threadId: 'thread-1',
attachments: [],
content: {
body: JSON.stringify({
blocks: [
Expand All @@ -32,7 +31,6 @@ module.exports = [
{
id: '2',
threadId: 'thread-1',
attachments: [],
content: {
body: JSON.stringify(
toJSON(fromPlainText('This is the second message!'))
Expand All @@ -46,7 +44,6 @@ module.exports = [
{
id: '3',
threadId: 'thread-1',
attachments: [],
content: {
body: JSON.stringify(
toJSON(fromPlainText('The next one is an emoji-only one :scream:'))
Expand All @@ -60,7 +57,6 @@ module.exports = [
{
id: '4',
threadId: 'thread-1',
attachments: [],
content: {
body: JSON.stringify(toJSON(fromPlainText('🎉'))),
},
Expand All @@ -73,7 +69,6 @@ module.exports = [
{
id: '5',
threadId: 'thread-2',
attachments: [],
content: {
body: JSON.stringify({
blocks: [
Expand All @@ -98,7 +93,6 @@ module.exports = [
{
id: '6',
threadId: 'thread-2',
attachments: [],
content: {
body: JSON.stringify(
toJSON(fromPlainText('This is the second message!'))
Expand All @@ -112,7 +106,6 @@ module.exports = [
{
id: '7',
threadId: 'thread-2',
attachments: [],
content: {
body: JSON.stringify(
toJSON(fromPlainText('The next one is an emoji-only one :scream:'))
Expand All @@ -126,7 +119,6 @@ module.exports = [
{
id: '8',
threadId: 'thread-2',
attachments: [],
content: {
body: JSON.stringify(toJSON(fromPlainText('🎉'))),
},
Expand All @@ -141,7 +133,6 @@ module.exports = [
id: '9',
threadId: 'dm-1',
threadType: 'directMessageThread',
attachments: [],
content: {
body: JSON.stringify(
toJSON(fromPlainText('Direct message thread message!'))
Expand All @@ -155,7 +146,6 @@ module.exports = [
id: '10',
threadId: 'dm-1',
threadType: 'directMessageThread',
attachments: [],
content: {
body: JSON.stringify(toJSON(fromPlainText('A second one'))),
},
Expand All @@ -167,7 +157,6 @@ module.exports = [
id: '11',
threadId: 'dm-1',
threadType: 'directMessageThread',
attachments: [],
content: {
body: JSON.stringify(toJSON(fromPlainText('A third one'))),
},
Expand All @@ -179,7 +168,6 @@ module.exports = [
id: '12',
threadId: 'dm-1',
threadType: 'directMessageThread',
attachments: [],
content: {
body: JSON.stringify(toJSON(fromPlainText('A fourth one'))),
},
Expand All @@ -191,7 +179,6 @@ module.exports = [
id: '13',
threadId: 'dm-1',
threadType: 'directMessageThread',
attachments: [],
content: {
body: JSON.stringify(toJSON(fromPlainText('A fifth one'))),
},
Expand Down
13 changes: 0 additions & 13 deletions api/migrations/seed/default/threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module.exports = [
toJSON(fromPlainText('This is it, we got a thread here'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE),
Expand Down Expand Up @@ -65,7 +64,6 @@ module.exports = [
toJSON(fromPlainText('This is just another thread'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 1),
Expand Down Expand Up @@ -97,7 +95,6 @@ module.exports = [
toJSON(fromPlainText('This is just another thread'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 2),
Expand Down Expand Up @@ -130,7 +127,6 @@ module.exports = [
toJSON(fromPlainText('This is it, we got a thread here'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE),
Expand Down Expand Up @@ -162,7 +158,6 @@ module.exports = [
toJSON(fromPlainText('This is just another thread'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 1),
Expand Down Expand Up @@ -194,7 +189,6 @@ module.exports = [
toJSON(fromPlainText('This is just another thread'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 2),
Expand Down Expand Up @@ -226,7 +220,6 @@ module.exports = [
toJSON(fromPlainText('This is just another thread'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 2),
Expand Down Expand Up @@ -259,7 +252,6 @@ module.exports = [
toJSON(fromPlainText('This is just another thread'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 2),
Expand Down Expand Up @@ -291,7 +283,6 @@ module.exports = [
toJSON(fromPlainText('This is just another thread'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 2),
Expand Down Expand Up @@ -322,7 +313,6 @@ module.exports = [
toJSON(fromPlainText('This is just another thread'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 2),
Expand Down Expand Up @@ -352,7 +342,6 @@ module.exports = [
title: 'Deleted thread',
body: JSON.stringify(toJSON(fromPlainText('This is a deleted thread'))),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 2),
Expand Down Expand Up @@ -386,7 +375,6 @@ module.exports = [
toJSON(fromPlainText('This is just another thread'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 2),
Expand Down Expand Up @@ -420,7 +408,6 @@ module.exports = [
toJSON(fromPlainText('This is just another thread'))
),
},
attachments: [],
edits: [
{
timestamp: new Date(DATE + 2),
Expand Down
2 changes: 0 additions & 2 deletions api/migrations/seed/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ const generateThread = (communityId, channelId, creatorId) => {
communityId,
isPublished: faker.random.boolean(),
content,
attachments: [],
type: 'DRAFTJS',
lastActive: faker.date.between(createdAt, new Date()),
edits: [
Expand Down Expand Up @@ -244,7 +243,6 @@ const generateMessage = (senderId, threadId, threadType) => {
content: {
body: casual.text(),
},
attachments: [],
messageType: 'text',
timestamp: faker.date.past(2),
};
Expand Down
8 changes: 0 additions & 8 deletions api/models/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,18 +534,12 @@ export const deleteThread = (threadId: string, userId: string): Promise<Boolean>

type File = FileUpload;

type Attachment = {
attachmentType: string,
data: string,
};

export type EditThreadInput = {
threadId: string,
content: {
title: string,
body: ?string,
},
attachments?: ?Array<Attachment>,
filesToUpload?: ?Array<File>,
};

Expand All @@ -558,11 +552,9 @@ export const editThread = (input: EditThreadInput, userId: string, shouldUpdate:
.update(
{
content: input.content,
attachments: input.attachments,
modifiedAt: shouldUpdate ? new Date() : null,
edits: db.row('edits').append({
content: db.row('content'),
attachments: db.row('attachments'),
timestamp: new Date(),
}),
},
Expand Down
15 changes: 0 additions & 15 deletions api/mutations/thread/editThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,12 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
);
}

let attachments = [];
// if the thread came in with attachments
if (input.attachments) {
// iterate through them and construct a new attachment object
input.attachments.map(attachment => {
attachments.push({
attachmentType: attachment.attachmentType,
data: JSON.parse(attachment.data),
});

return null;
});
}

const newInput = Object.assign({}, input, {
...input,
content: {
...input.content,
title: input.content.title.trim(),
},
attachments,
});

// $FlowIssue
Expand Down
32 changes: 0 additions & 32 deletions api/mutations/thread/publishThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ const threadBodyToPlainText = (body: any): string =>
const MEMBER_SPAM_LMIT = 3;
const SPAM_TIMEFRAME = 60 * 10;

type Attachment = {
attachmentType: string,
data: string,
};

type File = FileUpload;

export type PublishThreadInput = {
Expand All @@ -47,7 +42,6 @@ export type PublishThreadInput = {
title: string,
body?: string,
},
attachments?: ?Array<Attachment>,
filesToUpload?: ?Array<File>,
},
};
Expand Down Expand Up @@ -256,17 +250,6 @@ export default requireAuth(
}
}

/*
If the thread has attachments, we have to iterate through each attachment and JSON.parse() the data payload. This is because we want a generic data shape in the graphQL layer like this:
{
attachmentType: enum String
data: String
}
But when we get the data onto the client we JSON.parse the `data` field so that we can have any generic shape for attachments in the future.
*/

let threadObject = Object.assign(
{},
{
Expand All @@ -277,21 +260,6 @@ export default requireAuth(
},
}
);
// if the thread has attachments
if (thread.attachments) {
// iterate through them and construct a new attachment object
const attachments = thread.attachments.map(attachment => {
return {
attachmentType: attachment.attachmentType,
data: JSON.parse(attachment.data),
};
});

// create a new thread object, overriding the attachments field with our new array
threadObject = Object.assign({}, threadObject, {
attachments,
});
}

// $FlowFixMe
const dbThread: DBThread = await publishThread(threadObject, user.id);
Expand Down
4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"react-infinite-scroller-with-scroll-element": "^1.0.4",
"react-loadable": "5.2.2",
"react-modal": "^1.6.5",
"react-redux": "^5.0.7",
"react-redux": "^5.1.0",
"react-remarkable": "^1.1.1",
"react-router": "^4.0.0-beta.7",
"react-router-dom": "^4.0.0-beta.7",
Expand All @@ -111,7 +111,7 @@
"serialize-javascript": "^1.5.0",
"session-rethinkdb": "^2.0.0",
"shortid": "^2.2.13",
"slate": "^0.42.3",
"slate": "^0.42.6",
"slate-markdown": "0.1.0",
"slugg": "^1.1.0",
"string-replace-to-array": "^1.0.3",
Expand Down
14 changes: 6 additions & 8 deletions api/queries/thread/attachments.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// @flow
/*
Deprecated Oct 26 2018 by @brian
*/
import type { DBThread } from 'shared/types';

export default ({ attachments }: DBThread) =>
attachments &&
attachments.map(attachment => {
return {
attachmentType: attachment.attachmentType,
data: JSON.stringify(attachment.data),
};
});
export default () => [];
Loading

0 comments on commit c777fbb

Please sign in to comment.