示例#1
0
  'comments.deleteById': function (commentId) {

    check(commentId, String);
    
    var comment = Comments.findOne(commentId);
    var user = Meteor.user();

    if(Users.canEdit(user, comment)){
      // decrement post comment count and remove user ID from post
      Posts.update(comment.postId, {
        $inc:   {commentCount: -1},
        $pull:  {commenters: comment.userId}
      });

      // decrement user comment count and remove comment ID from user
      Users.update({_id: comment.userId}, {
        $inc:   {'telescope.commentCount': -1}
      });

      // note: should we also decrease user's comment karma ?
      // We don't actually delete the comment to avoid losing all child comments.
      // Instead, we give it a special flag
      Comments.update({_id: commentId}, {$set: {
        body: 'Deleted',
        htmlBody: 'Deleted',
        isDeleted: true
      }});
    } else {
      Messages.flash("You don't have permission to delete this comment.", "error");
    }
  },
示例#2
0
Posts.increaseClicks = (postId, ip) => {
  const clickEvent = {
    name: 'click',
    properties: {
      postId: postId,
      ip: ip
    }
  };

  // make sure this IP hasn't previously clicked on this post
  const existingClickEvent = Events.findOne({name: 'click', 'properties.postId': postId, 'properties.ip': ip});

  if(!existingClickEvent) {
    Events.log(clickEvent);
    return Posts.update(postId, { $inc: { clickCount: 1 }});
  }
};
示例#3
0
Newsletter.scheduleWithMailChimp = function (campaign, isTest = false) {

  var apiKey = Telescope.settings.get('mailChimpAPIKey');
  var listId = Telescope.settings.get('mailChimpListId');

  if(!!apiKey && !!listId){

    var wordCount = 15;
    var subject = campaign.subject;
    while (subject.length >= 150){
      subject = Telescope.utils.trimWords(subject, wordCount);
      wordCount--;
    }

    try {

      var api = new MailChimp(apiKey);
      var text = htmlToText.fromString(campaign.html, {wordwrap: 130});
      var defaultEmail = Telescope.settings.get('defaultEmail');
      var campaignOptions = {
        type: 'regular',
        options: {
          list_id: listId,
          subject: subject,
          from_email: defaultEmail,
          from_name: Telescope.settings.get('title')
        },
        content: {
          html: campaign.html,
          text: text
        }
      };

      console.log('// Creating campaign…');
      console.log('// Subject: '+subject)
      // create campaign
      var mailchimpNewsletter = api.call( 'campaigns', 'create', campaignOptions);

      console.log('// Newsletter created');
      // console.log(campaign)

      var scheduledTime = moment().utcOffset(0).add(1, 'hours').format("YYYY-MM-DD HH:mm:ss");

      var scheduleOptions = {
        cid: mailchimpNewsletter.id,
        schedule_time: scheduledTime
      };

      // schedule campaign
      var schedule = api.call('campaigns', 'schedule', scheduleOptions); // eslint-disable-line

      console.log('// Newsletter scheduled for '+scheduledTime);
      // console.log(schedule)

      // if this is not a test, mark posts as sent
      if (!isTest)
        var updated = Posts.update({_id: {$in: campaign.postIds}}, {$set: {scheduledAt: new Date()}}, {multi: true}) // eslint-disable-line

      // send confirmation email
      var confirmationHtml = NovaEmail.getTemplate('newsletterConfirmation')({
        time: scheduledTime,
        newsletterLink: mailchimpNewsletter.archive_url,
        subject: subject
      });
      NovaEmail.send(defaultEmail, 'Newsletter scheduled', NovaEmail.buildTemplate(confirmationHtml));

    } catch (error) {
      console.log(error);
    }
    return subject;
  }
};