From 1134e3bc095f3e0d374862ec31245f9692a75b33 Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Fri, 18 Nov 2016 10:46:09 -0500 Subject: [PATCH 1/8] add(coral-admin): Syntax highlighting on links --- client/coral-admin/src/components/Comment.js | 12 +++++++++- package.json | 25 +++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/client/coral-admin/src/components/Comment.js b/client/coral-admin/src/components/Comment.js index fa94f74a4..4cc18aa0a 100644 --- a/client/coral-admin/src/components/Comment.js +++ b/client/coral-admin/src/components/Comment.js @@ -5,6 +5,7 @@ import timeago from 'timeago.js'; import styles from './CommentList.css'; import I18n from 'coral-framework/modules/i18n/i18n'; import translations from '../translations.json'; +import Linkify from 'react-linkify'; // Render a single comment for the list export default props => ( @@ -27,7 +28,11 @@ export default props => (
- {props.comment.get('body')} + + + {props.comment.get('body')} + +
); @@ -43,4 +48,9 @@ const canShowAction = (action, comment) => { return true; }; +const linkStyles = { + backgroundColor: 'rgb(255, 219, 135)', + padding: '1px 2px' +}; + const lang = new I18n(translations); diff --git a/package.json b/package.json index dd9f8db8a..fb83055b6 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,13 @@ "config": { "pre-git": { "commit-msg": [], - "pre-commit": ["npm run lint", "npm test"], - "pre-push": ["npm test"], + "pre-commit": [ + "npm run lint", + "npm test" + ], + "pre-push": [ + "npm test" + ], "post-commit": [], "post-merge": [] } @@ -26,7 +31,12 @@ "type": "git", "url": "git+https://github.com/coralproject/talk.git" }, - "keywords": ["talk", "coral", "coralproject", "ask"], + "keywords": [ + "talk", + "coral", + "coralproject", + "ask" + ], "author": "", "license": "Apache-2.0", "bugs": { @@ -44,18 +54,17 @@ "express": "^4.14.0", "express-session": "^1.14.2", "helmet": "^3.1.0", + "jsonwebtoken": "^7.1.9", + "lodash": "^4.16.6", "lodash.debounce": "^4.0.8", "mongoose": "^4.6.5", "morgan": "^1.7.0", + "nodemailer": "^2.6.4", "passport": "^0.3.2", "passport-facebook": "^2.1.1", "passport-local": "^1.0.0", - "jsonwebtoken": "^7.1.9", - "lodash": "^4.16.6", - "mongoose": "^4.6.5", - "morgan": "^1.7.0", - "nodemailer": "^2.6.4", "prompt": "^1.0.0", + "react-linkify": "^0.1.3", "redis": "^2.6.3", "uuid": "^2.0.3" }, From ee9dc7260fe9e82ce3fe6f34ad12162170aff43b Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Fri, 18 Nov 2016 12:15:53 -0500 Subject: [PATCH 2/8] add(coral-admin): Added cointains link warning --- client/coral-admin/src/components/Comment.js | 66 +++++++++++-------- .../src/components/CommentList.css | 12 ++++ 2 files changed, 50 insertions(+), 28 deletions(-) diff --git a/client/coral-admin/src/components/Comment.js b/client/coral-admin/src/components/Comment.js index 4cc18aa0a..0c63445c8 100644 --- a/client/coral-admin/src/components/Comment.js +++ b/client/coral-admin/src/components/Comment.js @@ -7,35 +7,45 @@ import I18n from 'coral-framework/modules/i18n/i18n'; import translations from '../translations.json'; import Linkify from 'react-linkify'; +const linkify = new Linkify() + // Render a single comment for the list -export default props => ( -
  • -
    -
    - person - {props.comment.get('name') || lang.t('comment.anon')} - {timeago().format(props.comment.get('createdAt') || (Date.now() - props.index * 60 * 1000), lang.getLocale().replace('-', '_'))} - {props.comment.get('flagged') ?

    {lang.t('comment.flagged')}

    : null} -
    -
    - {props.actions.map(action => canShowAction(action, props.comment) ? ( - - ) : null)} -
    -
    -
    - - - {props.comment.get('body')} - - -
    -
  • -); +export default props => { + const links = linkify.getMatches(props.comment.get('body')) + + return ( +
  • +
    +
    + person + {props.comment.get('name') || lang.t('comment.anon')} + {timeago().format(props.comment.get('createdAt') || (Date.now() - props.index * 60 * 1000), lang.getLocale().replace('-', '_'))} + {props.comment.get('flagged') ?

    {lang.t('comment.flagged')}

    : null} +
    +
    + {links ? + Contains Link : null} +
    + {props.actions.map(action => canShowAction(action, props.comment) ? ( + + ) : null)} +
    +
    +
    +
    + + + {props.comment.get('body')} + + +
    +
  • + ) +}; // Check if an action can be performed over a comment const canShowAction = (action, comment) => { diff --git a/client/coral-admin/src/components/CommentList.css b/client/coral-admin/src/components/CommentList.css index f683ca36b..2c58c81cf 100644 --- a/client/coral-admin/src/components/CommentList.css +++ b/client/coral-admin/src/components/CommentList.css @@ -121,3 +121,15 @@ } } + + +.hasLinks { + color: #f00; + text-align: right; + display: flex; + align-items: center; + + i { + margin-right: 5px; + } +} From a0db48ea224059905ab79c27980346d384c3817c Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 18 Nov 2016 13:10:59 -0500 Subject: [PATCH 3/8] Adding author id to posted comments. --- client/coral-embed-stream/src/CommentStream.js | 2 +- client/coral-plugin-commentbox/CommentBox.js | 11 ++++++----- swagger.yaml | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/client/coral-embed-stream/src/CommentStream.js b/client/coral-embed-stream/src/CommentStream.js index cb5fcd89a..7d8669d38 100644 --- a/client/coral-embed-stream/src/CommentStream.js +++ b/client/coral-embed-stream/src/CommentStream.js @@ -105,7 +105,7 @@ class CommentStream extends Component { id={rootItemId} premod={this.props.config.moderation} reply={false} - canPost={loggedIn} + authorId={user.id} /> {!loggedIn && } diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index e712d8e24..be03177f8 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -12,7 +12,8 @@ class CommentBox extends Component { id: PropTypes.string, comments: PropTypes.array, reply: PropTypes.bool, - canPost: PropTypes.bool + canPost: PropTypes.bool, + currentUser: PropTypes.object } state = { @@ -21,11 +22,11 @@ class CommentBox extends Component { } postComment = () => { - const {postItem, updateItem, id, parent_id, addNotification, appendItemArray, premod} = this.props; + const {postItem, updateItem, id, parent_id, addNotification, appendItemArray, premod, authorId} = this.props; let comment = { body: this.state.body, asset_id: id, - username: this.state.username + user_id: authorId.id }; let related; let parent_type; @@ -52,7 +53,7 @@ class CommentBox extends Component { } render () { - const {styles, reply, canPost} = this.props; + const {styles, reply, authorId} = this.props; // How to handle language in plugins? Should we have a dependency on our central translation file? return
    - { canPost && ( + { authorId && ( - ) : null)} -
    + return ( +
  • +
    +
    + person + {props.comment.get('name') || lang.t('comment.anon')} + {timeago().format(props.comment.get('createdAt') || (Date.now() - props.index * 60 * 1000), lang.getLocale().replace('-', '_'))} + {props.comment.get('flagged') ?

    {lang.t('comment.flagged')}

    : null} +
    +
    + {links ? + Contains Link : null} +
    + {props.actions.map(action => canShowAction(action, props.comment) ? ( + + ) : null)}
    -
    - - - {props.comment.get('body')} - - -
    -
  • - ) +
    +
    + + + {props.comment.get('body')} + + +
    + + ); }; // Check if an action can be performed over a comment From a4a8b97873a99fcdce89c7a037ff7775dd9bf7ae Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 18 Nov 2016 23:15:41 -0500 Subject: [PATCH 7/8] Including author name when comments are first posted. --- client/coral-embed-stream/src/CommentStream.js | 4 ++-- client/coral-framework/actions/auth.js | 7 +++++-- client/coral-plugin-commentbox/CommentBox.js | 2 +- client/coral-sign-in/components/styles.css | 4 ++-- routes/api/stream/index.js | 2 +- swagger.yaml | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/client/coral-embed-stream/src/CommentStream.js b/client/coral-embed-stream/src/CommentStream.js index b67b98582..212264826 100644 --- a/client/coral-embed-stream/src/CommentStream.js +++ b/client/coral-embed-stream/src/CommentStream.js @@ -115,7 +115,7 @@ class CommentStream extends Component { const comment = this.props.items.comments[commentId]; return

    - +
    @@ -162,7 +162,7 @@ class CommentStream extends Component { let reply = this.props.items.comments[replyId]; return

    - +
    diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index a1a44611f..a566ee15c 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -3,6 +3,7 @@ import translations from './../translations'; const lang = new I18n(translations); import * as actions from '../constants/auth'; import {base, handleResp, getInit} from '../helpers/response'; +import {addItem} from './items' // Dialog Actions export const showSignInDialog = () => ({type: actions.SHOW_SIGNIN_DIALOG}); @@ -29,6 +30,7 @@ export const fetchSignIn = (formData) => dispatch => { .then(({user}) => { dispatch(hideSignInDialog()); dispatch(signInSuccess(user)); + dispatch(addItem(user, 'users')); }) .catch(() => dispatch(signInFailure(lang.t('error.emailPasswordError')))); }; @@ -54,8 +56,10 @@ export const facebookCallback = (err, data) => dispatch => { return; } try { - dispatch(signInFacebookSuccess(JSON.parse(data))); + const user = JSON.parse(data); + dispatch(signInFacebookSuccess(user)); dispatch(hideSignInDialog()); + dispatch(addItem(user, 'users')); } catch (err) { dispatch(signInFacebookFailure(err)); return; @@ -113,4 +117,3 @@ export const logout = () => dispatch => { export const validForm = () => ({type: actions.VALID_FORM}); export const invalidForm = error => ({type: actions.INVALID_FORM, error}); - diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index e18d83acc..76f7e43be 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -26,7 +26,7 @@ class CommentBox extends Component { let comment = { body: this.state.body, asset_id: id, - user_id: author.id + author_id: author.id }; let related; let parent_type; diff --git a/client/coral-sign-in/components/styles.css b/client/coral-sign-in/components/styles.css index 81864eb2f..e8458f314 100644 --- a/client/coral-sign-in/components/styles.css +++ b/client/coral-sign-in/components/styles.css @@ -106,7 +106,7 @@ input.error{ .userBox a { color: #2c69b6; cursor: pointer; - margin: 0 5px; + margin: 0px; } .attention { @@ -128,4 +128,4 @@ input.error{ .action { margin-top: 15px; -} \ No newline at end of file +} diff --git a/routes/api/stream/index.js b/routes/api/stream/index.js index 7455651a5..b06e3566c 100644 --- a/routes/api/stream/index.js +++ b/routes/api/stream/index.js @@ -35,7 +35,7 @@ router.get('/', (req, res, next) => { return Promise.all([ [asset], comments, - User.findPublicByIdArray(comments.map((comment) => comment.user_id)), + User.findPublicByIdArray(comments.map((comment) => comment.author_id)), Action.getActionSummaries(comments.map((comment) => comment.id)) ]); }) diff --git a/swagger.yaml b/swagger.yaml index 9da36d5da..9f25c6f42 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -243,7 +243,7 @@ definitions: type: string format: date-time description: Display name of comment - user_id: + author_id: type: string description: User who posted the comment parent_id: From 1a1df1656ff1781b6594c2fd26eed56de30fd1a1 Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 18 Nov 2016 23:20:17 -0500 Subject: [PATCH 8/8] Posting like and flag with appropriate user_id. --- client/coral-plugin-flags/FlagButton.js | 9 ++++++--- client/coral-plugin-likes/LikeButton.js | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/client/coral-plugin-flags/FlagButton.js b/client/coral-plugin-flags/FlagButton.js index a4869c486..77fe519f9 100644 --- a/client/coral-plugin-flags/FlagButton.js +++ b/client/coral-plugin-flags/FlagButton.js @@ -4,18 +4,21 @@ import translations from './translations.json'; const name = 'coral-plugin-flags'; -const FlagButton = ({flag, id, postAction, deleteAction, addItem, updateItem, addNotification}) => { +const FlagButton = ({flag, id, postAction, deleteAction, addItem, updateItem, addNotification, currentUser}) => { const flagged = flag && flag.current_user; const onFlagClick = () => { + if (!currentUser) { + return; + } if (!flagged) { - postAction(id, 'flag', '123', 'comments') + postAction(id, 'flag', currentUser.id, 'comments') .then((action) => { addItem({...action, current_user:true}, 'actions'); updateItem(action.item_id, action.action_type, action.id, 'comments'); }); addNotification('success', lang.t('flag-notif')); } else { - deleteAction(id, 'flag', '123', 'comments') + deleteAction(id, 'flag', currentUser.id, 'comments') .then(() => { updateItem(id, 'flag', '', 'comments'); }); diff --git a/client/coral-plugin-likes/LikeButton.js b/client/coral-plugin-likes/LikeButton.js index 9bdf7b84d..ecdffaf62 100644 --- a/client/coral-plugin-likes/LikeButton.js +++ b/client/coral-plugin-likes/LikeButton.js @@ -4,17 +4,20 @@ import translations from './translations.json'; const name = 'coral-plugin-flags'; -const LikeButton = ({like, id, postAction, deleteAction, addItem, updateItem}) => { +const LikeButton = ({like, id, postAction, deleteAction, addItem, updateItem, currentUser}) => { const liked = like && like.current_user; const onLikeClick = () => { + if (!currentUser) { + return; + } if (!liked) { - postAction(id, 'like', '123', 'comments') + postAction(id, 'like', currentUser.id, 'comments') .then((action) => { addItem({id: action.id, current_user:true, count: like ? like.count + 1 : 1}, 'actions'); updateItem(action.item_id, action.action_type, action.id, 'comments'); }); } else { - deleteAction(id, 'like', '123', 'comments') + deleteAction(id, 'like', currentUser.id, 'comments') .then(() => { updateItem(like.id, 'count', like.count - 1, 'actions'); updateItem(like.id, 'current_user', false, 'actions');