diff --git a/.eslintignore b/.eslintignore index 6fecd9d9b..8a8c3a213 100644 --- a/.eslintignore +++ b/.eslintignore @@ -11,4 +11,5 @@ plugins/* !plugins/coral-plugin-mod !plugins/coral-plugin-love !plugins/coral-plugin-viewing-options +!plugins/coral-plugin-comment-content node_modules diff --git a/.gitignore b/.gitignore index abd490356..b3e0eaa73 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,6 @@ plugins/* !plugins/coral-plugin-mod !plugins/coral-plugin-love !plugins/coral-plugin-viewing-options +!plugins/coral-plugin-comment-content **/node_modules/* diff --git a/bin/cli-users b/bin/cli-users index fccb4b8bb..057c0a806 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -8,6 +8,7 @@ const program = require('./commander'); const inquirer = require('inquirer'); const UsersService = require('../services/users'); const UserModel = require('../models/user'); +const USER_ROLES = require('../models/enum/user_roles'); const mongoose = require('../services/mongoose'); const util = require('./util'); const Table = require('cli-table'); @@ -36,7 +37,7 @@ function getUserCreateAnswers(options) { roles: [] }; - if (options.role && UserModel.USER_ROLES.indexOf(options.role) > -1) { + if (options.role && USER_ROLES.indexOf(options.role) > -1) { user.roles = [options.role]; } @@ -89,7 +90,7 @@ function getUserCreateAnswers(options) { name: 'roles', message: 'User Role', type: 'checkbox', - choices: UserModel.USER_ROLES + choices: USER_ROLES } ]); } @@ -291,8 +292,8 @@ function mergeUsers(dstUserID, srcUserID) { */ function addRole(userID, role) { - if (UserModel.USER_ROLES.indexOf(role) === -1) { - console.error(`Role '${role}' is not supported. Supported roles are ${UserModel.USER_ROLES.join(', ')}.`); + if (USER_ROLES.indexOf(role) === -1) { + console.error(`Role '${role}' is not supported. Supported roles are ${USER_ROLES.join(', ')}.`); util.shutdown(1); return; } @@ -316,8 +317,8 @@ function addRole(userID, role) { */ function removeRole(userID, role) { - if (UserModel.USER_ROLES.indexOf(role) === -1) { - console.error(`Role '${role}' is not supported. Supported roles are ${UserModel.USER_ROLES.join(', ')}.`); + if (USER_ROLES.indexOf(role) === -1) { + console.error(`Role '${role}' is not supported. Supported roles are ${USER_ROLES.join(', ')}.`); util.shutdown(1); return; } diff --git a/client/coral-embed-stream/src/components/Comment.js b/client/coral-embed-stream/src/components/Comment.js index 92c59d936..a66b8a224 100644 --- a/client/coral-embed-stream/src/components/Comment.js +++ b/client/coral-embed-stream/src/components/Comment.js @@ -3,13 +3,13 @@ import React, {PropTypes} from 'react'; import PermalinkButton from 'coral-plugin-permalinks/PermalinkButton'; import AuthorName from 'coral-plugin-author-name/AuthorName'; import TagLabel from 'coral-plugin-tag-label/TagLabel'; -import Content from 'coral-plugin-commentcontent/CommentContent'; import PubDate from 'coral-plugin-pubdate/PubDate'; import {ReplyBox, ReplyButton} from 'coral-plugin-replies'; import FlagComment from 'coral-plugin-flags/FlagComment'; import {can} from 'coral-framework/services/perms'; import {TransitionGroup} from 'react-transition-group'; import cn from 'classnames'; +import styles from './Comment.css'; import { BestButton, @@ -18,14 +18,14 @@ import { commentIsBest, BestIndicator } from 'coral-plugin-best/BestButton'; -import Slot from 'coral-framework/components/Slot'; import LoadMore from './LoadMore'; +import {getEditableUntilDate} from './util'; import {TopRightMenu} from './TopRightMenu'; +import CommentContent from './CommentContent'; +import Slot from 'coral-framework/components/Slot'; import IgnoredCommentTombstone from './IgnoredCommentTombstone'; import {EditableCommentContent} from './EditableCommentContent'; import {getActionSummary, iPerformedThisAction} from 'coral-framework/utils'; -import {getEditableUntilDate} from './util'; -import styles from './Comment.css'; const isStaff = (tags) => !tags.every((t) => t.tag.name !== 'STAFF'); const hasTag = (tags, lookupTag) => !!tags.filter((t) => t.tag.name === lookupTag).length; @@ -466,8 +466,7 @@ export default class Comment extends React.Component { stopEditing={this.stopEditing} /> :
- - +
} diff --git a/client/coral-embed-stream/src/components/CommentContent.js b/client/coral-embed-stream/src/components/CommentContent.js new file mode 100644 index 000000000..4d56ec0d5 --- /dev/null +++ b/client/coral-embed-stream/src/components/CommentContent.js @@ -0,0 +1,19 @@ +import React from 'react'; + +const CommentContent = ({comment}) => { + const textbreaks = comment.body.split('\n'); + return
+ { + textbreaks.map((line, i) => { + return ( + + {line} +
+
+ ); + }) + } +
; +}; + +export default CommentContent; diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index 65e77ad1d..14de2756e 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -54,6 +54,12 @@ function configurePymParent(pymParent, opts) { pymParent.sendMessage('config', JSON.stringify(config)); } + pymParent.onMessage('coral-auth-changed', function(message) { + if (opts.onAuthChanged) { + opts.onAuthChanged(message ? JSON.parse(message) : null); + } + }); + // Sends config to the child pymParent.onMessage('getConfig', function() { sendConfig(opts || {}); diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index eaaee3034..614b87632 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -3,6 +3,7 @@ import bowser from 'bowser'; import * as actions from '../constants/auth'; import * as Storage from '../helpers/storage'; import coralApi, {base} from '../helpers/request'; +import pym from '../services/PymConnection'; import {resetWebsocket} from 'coral-framework/services/client'; import t from 'coral-framework/services/i18n'; @@ -284,6 +285,7 @@ export const logout = () => (dispatch) => { resetWebsocket(); dispatch({type: actions.LOGOUT}); + pym.sendMessage('coral-auth-changed'); }); }; @@ -315,6 +317,7 @@ export const checkLogin = () => (dispatch) => { resetWebsocket(); dispatch(checkLoginSuccess(result.user)); + pym.sendMessage('coral-auth-changed', JSON.stringify(result.user)); // Display create username dialog if necessary. if (result.user.canEditName && result.user.status !== 'BANNED') { diff --git a/client/coral-framework/components/Slot.js b/client/coral-framework/components/Slot.js index 22a315623..ca246591b 100644 --- a/client/coral-framework/components/Slot.js +++ b/client/coral-framework/components/Slot.js @@ -4,10 +4,15 @@ import styles from './Slot.css'; import {connect} from 'react-redux'; import {getSlotElements} from 'coral-framework/helpers/plugins'; -function Slot ({fill, inline = false, className, plugin_config: config, ...rest}) { +function Slot ({fill, inline = false, className, plugin_config: config, defaultComponent: DefaultComponent, ...rest}) { + let children = getSlotElements(fill, {...rest, config}); + if (children.length === 0 && DefaultComponent) { + children = ; + } + return (
- {getSlotElements(fill, {...rest, config})} + {children}
); } diff --git a/client/coral-plugin-commentcontent/CommentContent.js b/client/coral-plugin-commentcontent/CommentContent.js deleted file mode 100644 index 501005b3d..000000000 --- a/client/coral-plugin-commentcontent/CommentContent.js +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react'; -const name = 'coral-plugin-commentcontent'; - -const Content = ({body, styles}) => { - const textbreaks = body.split('\n'); - return
- { - textbreaks.map((line, i) => - {line}
-
) - } -
; -}; - -export default Content; diff --git a/client/coral-plugin-commentcontent/__tests__/commentContent.spec.js b/client/coral-plugin-commentcontent/__tests__/commentContent.spec.js deleted file mode 100644 index 377726b6d..000000000 --- a/client/coral-plugin-commentcontent/__tests__/commentContent.spec.js +++ /dev/null @@ -1,11 +0,0 @@ -import React from 'react'; -import {shallow} from 'enzyme'; -import {expect} from 'chai'; -import CommentContent from '../CommentContent'; - -describe('CommentContent', () => { - it('should render content', () => { - const render = shallow(); - expect(render.contains('test')).to.be.truthy; - }); -}); diff --git a/client/coral-plugin-history/Comment.js b/client/coral-plugin-history/Comment.js index cb188e53e..888989737 100644 --- a/client/coral-plugin-history/Comment.js +++ b/client/coral-plugin-history/Comment.js @@ -1,8 +1,9 @@ import React, {PropTypes} from 'react'; import {Icon} from '../coral-ui'; import styles from './Comment.css'; +import Slot from 'coral-framework/components/Slot'; import PubDate from '../coral-plugin-pubdate/PubDate'; -import Content from '../coral-plugin-commentcontent/CommentContent'; +import CommentContent from '../coral-embed-stream/src/components/CommentContent'; import t from 'coral-framework/services/i18n'; @@ -10,9 +11,11 @@ const Comment = (props) => { return (
-

{t('createdisplay.if_you_dont_change_your_name')} diff --git a/plugins/coral-plugin-auth/client/components/FakeComment.js b/plugins/coral-plugin-auth/client/components/FakeComment.js index 390dd409b..5517b72aa 100644 --- a/plugins/coral-plugin-auth/client/components/FakeComment.js +++ b/plugins/coral-plugin-auth/client/components/FakeComment.js @@ -1,17 +1,17 @@ import React from 'react'; +import t from 'coral-framework/services/i18n'; import {ReplyButton} from 'coral-plugin-replies'; import PubDate from 'coral-plugin-pubdate/PubDate'; +import Slot from 'coral-framework/components/Slot'; import AuthorName from 'coral-plugin-author-name/AuthorName'; -import Content from 'coral-plugin-commentcontent/CommentContent'; import styles from 'coral-embed-stream/src/components/Comment.css'; -import t from 'coral-framework/services/i18n'; -export const FakeComment = ({username, created_at, body}) => ( +export const FakeComment = ({username, created_at, comment}) => (


- +