Merge pull request #1412 from schabluk/devel

Extendable Subscribe component & locale
This commit is contained in:
Sacha Greif 2016-08-07 19:08:20 +09:00 committed by GitHub
commit 6f530923b2
9 changed files with 1582 additions and 1334 deletions

View file

@ -0,0 +1,32 @@
import Posts from "meteor/nova:posts";
import Users from 'meteor/nova:users';
// Notify users subscribed to the thread
function SubscribedCommentsNotifications (comment) {
if (typeof Telescope.notifications !== "undefined") {
// note: dummy content has disableNotifications set to true
if(Meteor.isServer && !comment.disableNotifications){
const post = Posts.findOne(comment.postId);
let userIdsNotified = [],
notificationData = {
comment: _.pick(comment, '_id', 'userId', 'author', 'htmlBody', 'postId'),
post: _.pick(post, '_id', 'userId', 'title', 'url')
};
if (!!post.subscribers) {
// remove userIds of users that have already been notified
// and of comment author (they could be replying in a thread they're subscribed to)
let subscriberIdsToNotify = _.difference(post.subscribers, userIdsNotified, [comment.userId]);
Telescope.notifications.create(subscriberIdsToNotify, 'newCommentSubscribed', notificationData);
userIdsNotified = userIdsNotified.concat(subscriberIdsToNotify);
}
}
}
}
Telescope.callbacks.add("comments.new.async", SubscribedCommentsNotifications);

View file

@ -1,6 +1,7 @@
import React, { PropTypes, Component } from 'react';
import { intlShape } from 'react-intl';
class SubscribeButton extends Component {
class Subscribe extends Component {
constructor(props, context) {
super(props, context);
@ -9,7 +10,9 @@ class SubscribeButton extends Component {
this.isSubscribed = this.isSubscribed.bind(this);
}
onSubscribe() {
onSubscribe(e) {
e.preventDefault();
const post = this.props.post;
const user = this.context.currentUser;
@ -38,37 +41,33 @@ class SubscribeButton extends Component {
// can't subscribe to own post (also validated on server side)
if(user && post.author === user.username) {
return null
return null;
}
let btnStyle = "default";
let btnTitle = "posts.subscribe";
let isSubscribed = this.isSubscribed(post, user);
if( isSubscribed ) {
btnStyle = "info";
btnTitle = "posts.unsubscribe";
}
return (
<button type="button" title="Observe"
className={`btn btn-${btnStyle} btn-sm pull-right`}
style={{padding: '.5rem', lineHeight: 1, borderRadius: '50%', marginLeft: '.5rem'}}
onClick={this.onSubscribe} >
<i className="fa fa-eye"></i>
</button>
<a onClick={this.onSubscribe} >{this.context.intl.formatMessage({id: btnTitle})}</a>
)
}
}
SubscribeButton.propTypes = {
Subscribe.propTypes = {
post: React.PropTypes.object.isRequired
}
SubscribeButton.contextTypes = {
Subscribe.contextTypes = {
currentUser: React.PropTypes.object,
actions: React.PropTypes.object,
events: React.PropTypes.object
events: React.PropTypes.object,
intl: intlShape
};
module.exports = SubscribeButton;
export default SubscribeButton;
module.exports = Subscribe;
export default Subscribe;

View file

@ -0,0 +1,29 @@
import React, { PropTypes, Component } from 'react';
import { ListContainer } from "meteor/utilities:react-list-container";
import Posts from "meteor/nova:posts";
class SubscribedPosts extends Component {
render() {
const params = {view: 'userSubscribedPosts', userId: Meteor.userId(), listId: "posts.list.subscribed"};
const {selector, options} = Posts.parameters.get(params);
return (
<ListContainer
collection={Posts}
publication="posts.list"
selector={selector}
options={options}
terms={params}
joins={Posts.getJoins()}
component={Telescope.components.PostsList}
cacheSubscription={false}
listId={params.listId}
limit={Telescope.settings.get("postsPerPage", 10)}
/>
)
}
};
module.exports = SubscribedPosts;

View file

@ -1,8 +1,10 @@
import {subscribeItem, unsubscribeItem} from './methods.js';
import SubscribeButton from './components/SubscribeButton.jsx';
import Subscribe from './components/Subscribe.jsx';
import SubscribedPosts from './components/SubscribedPosts.jsx';
export {
subscribeItem,
unsubscribeItem,
SubscribeButton
Subscribe,
SubscribedPosts
}

View file

@ -0,0 +1,15 @@
import Posts from "meteor/nova:posts";
Posts.views.add("userSubscribedPosts", function (terms) {
var user = Meteor.users.findOne(terms.userId),
postsIds = [];
if (user && user.telescope.subscribedItems && user.telescope.subscribedItems.Posts) {
postsIds = _.pluck(user.telescope.subscribedItems.Posts, "itemId");
}
return {
selector: {_id: {$in: postsIds}},
options: {limit: 5, sort: {postedAt: -1}}
};
});

View file

@ -37,8 +37,10 @@ Package.onUse(function (api) {
api.addFiles([
// 'lib/subscribe-to-posts.js',',
'lib/callbacks.js',
'lib/custom_fields.js',
'lib/methods.js'
'lib/methods.js',
'lib/views.js'
], ['client', 'server']);
// client

File diff suppressed because it is too large Load diff

View file

@ -124,7 +124,7 @@ Telescope.callbacks.add("comments.new.method", CommentsNewSubmittedPropertiesChe
* @summary Check for required properties
*/
function CommentsNewRequiredPropertiesCheck (comment, user) {
var userId = comment.userId; // at this stage, a userId is expected
// Don't allow empty comments
@ -231,20 +231,7 @@ function CommentsNewNotifications (comment) {
}
}
// 3. Notify users subscribed to the thread
// TODO: ideally this would be injected from the telescope-subscribe-to-posts package
if (!!post.subscribers) {
// remove userIds of users that have already been notified
// and of comment author (they could be replying in a thread they're subscribed to)
var subscriberIdsToNotify = _.difference(post.subscribers, userIdsNotified, [comment.userId]);
Telescope.notifications.create(subscriberIdsToNotify, 'newCommentSubscribed', notificationData);
userIdsNotified = userIdsNotified.concat(subscriberIdsToNotify);
}
}
}
}

View file

@ -31,6 +31,9 @@ Telescope.strings.en = {
"posts.rate_limit_error": "Please wait {details} seconds before posting again.",
"posts.postedAt": "Posted at",
"posts.dateNotDefined": "Date not defined",
"posts.subscribe": "Subscribe",
"posts.unsubscribe": "Unsubscribe",
"posts.subscribed_posts" : "Subscribed Posts",
"comments.comments": "Comments",
"comments.count": "{count, plural, =0 {No comments} one {# comment} other {# comments}}",
@ -111,20 +114,20 @@ Telescope.strings.en = {
"settings.requirePostInvite": "Require Post Invite",
"settings.requirePostsApproval": "Require Posts Approval",
"settings.scoreUpdateInterval": "Score Update Interval",
"app.loading": "Loading…",
"app.404": "Sorry, we couldn't find what you were looking for.",
"app.powered_by": "Powered by Telescope",
"app.or": "Or",
"app.noPermission": "Sorry, you do not have the permission to do this at this time.",
"newsletter": "Newsletter",
"newsletter.subscribe": "Subscribe",
"newsletter.unsubscribe": "Unsubscribe",
"newsletter": "Newsletter",
"newsletter.subscribe": "Subscribe",
"newsletter.unsubscribe": "Unsubscribe",
"newsletter.subscribe_prompt": "Subscribe to the newsletter",
"newsletter.email": "Your email",
"newsletter.success_message": "Thanks for subscribing!",
"admin": "Admin",
"notifications": "Notifications",
}
}