示例#1
0
  public BlingInfo requestCashOutBling(
      int memberId, int blingAmount, String password, CashOutBillingInfo info)
      throws ServiceException {
    // Re-auth the user before allowing them to continue.
    MemberRecord mrec = requireAuthedUser();
    if (mrec.memberId != memberId) {
      throw new ServiceException(ServiceCodes.E_ACCESS_DENIED);
    }
    _authenticator.authenticateSession(mrec.accountName, password);

    BlingInfo result = _moneyLogic.requestCashOutBling(memberId, blingAmount, info);

    // Spam the cash out mailing list
    _mailer.sendTemplateEmail(
        MailSender.By.HUMAN,
        ServerConfig.getCashOutAddress(),
        "*****@*****.**",
        "blingCashOutNotice",
        "memberId",
        mrec.memberId,
        "name",
        mrec.name,
        "server_url",
        DeploymentConfig.serverURL,
        "url",
        Pages.ADMINZ.makeURL("cashout")); // TODO: A more meaningful URL

    return result;
  }
示例#2
0
  /**
   * Does the heavy lifting of sending a retention email. Returns a result indicating what was
   * included in the mailing.
   *
   * @param realDeal testing flag; if false, we make sure the mail is sent regardless
   */
  protected MailContent sendRetentionEmail(
      final MemberRecord mrec, String addressOverride, NewStuff filler, boolean realDeal) {
    int memberId = mrec.memberId;

    // load up friends and feed categories
    Set<Integer> friendIds = _memberRepo.loadFriendIds(mrec.memberId);
    List<FeedCategory> categories = Lists.newArrayList(); // FIXME(bruno)

    // count up all messages and ones that are personal
    int count = 0;
    int personalMessages = 0;
    for (FeedCategory cat : categories) {
      count += cat.messages.length;
      switch (cat.category) {
        case ANNOUNCEMENTS:
          for (FeedMessage fm : cat.messages) {
            if (fm.type != FeedMessageType.GLOBAL_ANNOUNCEMENT) {
              personalMessages++;
            }
          }
          break;
        default:
          personalMessages += cat.messages.length;
          break;
      }
    }

    // assign the user a bucket
    Bucket bucket;
    if (friendIds.size() == 0) {
      bucket = Bucket.HAS_NO_FRIENDS;

    } else if (personalMessages == 0) {
      bucket = Bucket.HAS_INACTIVE_FRIENDS;

    } else {
      bucket = Bucket.HAS_PERSONAL_EVENTS;
    }

    // generate the feed if we have at least a couple of items (this will always be true on
    // production until we stop posting announcements frequently)
    Parameters params = new Parameters();
    if (count >= MIN_NEWS_ITEM_COUNT) {
      // prepare the generators!
      final Generator generators[] = {
        new Generator(memberId, new PlainTextBuilder(), _messages),
        new Generator(memberId, new HTMLBuilder(), _messages)
      };

      // convert to our wrapped categories and items
      List<EmailFeedCategory> ecats = Lists.newArrayList();
      for (FeedCategory category : categories) {
        List<EmailFeedItem> eitems =
            Lists.transform(
                FeedMessageAggregator.aggregate(Arrays.asList(category.messages), false),
                new Function<FeedMessage, EmailFeedItem>() {;
                  public EmailFeedItem apply(FeedMessage fm) {
                    return new EmailFeedItem(generators, mrec.memberId, fm);
                  }
                });
        if (eitems.isEmpty()) {
          continue;
        }
        EmailFeedCategory ecat = new EmailFeedCategory(category.category, eitems);
        ecats.add(ecat);
      }

      // Sort to CATEGORIES order
      Collections.sort(ecats);

      params.set("feed", ecats);

    } else {
      // otherwise, tell the template not to show the feed section at all
      params.set("feed", null);
    }

    // list of threads with unread posts from friends
    List<ForumThread> threads = _forumLogic.loadUnreadFriendThreads(mrec, 0, FRIEND_THREAD_COUNT);
    if (threads.size() > 0) {
      params.set(
          "threads",
          Lists.transform(
              threads,
              new Function<ForumThread, EmailForumThread>() {
                public EmailForumThread apply(ForumThread thread) {
                  return new EmailForumThread(thread);
                }
              }));

    } else {
      params.set("threads", null);
    }

    // pick a random subject line based on the bucket
    String subjectLine = RandomUtil.pickRandom(bucket.subjectLines);
    String address = (addressOverride != null) ? addressOverride : mrec.accountName;

    // fire off the email, the template will take care of looping over categories and items
    // TODO: it would be great if we could somehow get the final result of actually sending the
    // mail. A lot of users have emails like [email protected] and we are currently counting them
    // as sent. I also like my pie at 30,000 feet please.
    // only generate the feed if we have at least a few items
    // TODO: maybe change the template based on the bucket too
    params.set("server_url", DeploymentConfig.serverURL);
    params.set("name", mrec.name);
    params.set("member_id", mrec.memberId);
    params.set("avatars", filler.avatars);
    params.set("games", filler.games);
    params.set("subject", subjectLine);
    params.set("optoutbits", SpamUtil.generateOptOutHash(memberId, address) + "_" + memberId);

    _mailSender.sendTemplateEmail(
        realDeal ? MailSender.By.COMPUTER : MailSender.By.HUMAN,
        address,
        ServerConfig.getFromAddress(),
        MAIL_TEMPLATE,
        params);
    return new MailContent(subjectLine, bucket, friendIds.size(), personalMessages);
  }