Example #1
0
  @Restrict(Mupi.USER_ROLE)
  public static Result nextPublications(Long last) {
    final models.Profile p = Mupi.getLocalUser(session()).profile;
    Long i = getLocalInterest();
    Long l = getLocalLocation();
    models.Interest iObj = null;
    models.Location lObj = null;
    if (i != null) iObj = models.Interest.find.byId(i);
    if (l != null) lObj = models.Location.find.byId(l);

    List<models.Publication> pubs = new ArrayList<models.Publication>();

    if (i == null || i == -1) {
      if (l == null || l == -1) {
        pubs =
            Publication.findByInterests(models.Interest.getIds(p.getInterests()), last).getList();
      } else {
        pubs =
            Publication.findByInterestsLocation(models.Interest.getIds(p.getInterests()), l, last)
                .getList();
      }
    } else {
      if (l == null || l == -1) {
        pubs = Publication.findByInterest(i, last).getList();
      } else {
        pubs = Publication.findByInterestLocation(i, l, last).getList();
      }
    }

    if (pubs.isEmpty()) return AjaxResponse.build(2, "");
    else return AjaxResponse.build(0, pubList.render(pubs, iObj, lObj).body());
  }
Example #2
0
  @Dynamic("editor")
  public static Result removePublication(Long id) {
    final User u = Mupi.getLocalUser(session());
    final models.Profile p = u.profile;

    Publication pub = models.Publication.find.byId(id);

    if (pub.getProfile().getId() == p.getId()
        && (pub.getPub_typ() == conf.MupiParams.PubType.DISCUSSION
            || pub.getPub_typ() == conf.MupiParams.PubType.IDEA
            || pub.getPub_typ() == conf.MupiParams.PubType.QUESTION)) {
      models.Publication.unpublish(id);
      return AjaxResponse.build(0, "Publicação removida!");
    } else if (pub.getProfile().getId() == p.getId()
        && pub.getPub_typ() == MupiParams.PubType.EVENT) {
      return AjaxResponse.build(
          2, "Esta publicação pertence à um evento! Você não pode removê-la!");
    } else if (pub.getProfile().getId() == p.getId()
        && pub.getPub_typ() == MupiParams.PubType.MUPI_EVENT) {
      return AjaxResponse.build(
          2, "Esta publicação pertence à um evento Mupi! Você não pode removê-la!");
    } else {
      return AjaxResponse.build(4, "Esta publicação não é sua! Você não pode removê-la");
    }
  }
Example #3
0
  @Dynamic("editor")
  public static Result publish() {
    Form<utils.Forms.PublicationBinder> bindedForm =
        form(utils.Forms.PublicationBinder.class).bindFromRequest();

    Long l = bindedForm.get().location;
    Long i = bindedForm.get().interest;

    if (i != null && l != null) {
      final User u = Mupi.getLocalUser(session());
      final models.Profile p = u.profile;

      String safeBody =
          Jsoup.clean(
              bindedForm.get().body,
              Whitelist.basicWithImages()
                  .addEnforcedAttribute("a", "target", "_blank")
                  .addTags("h1", "h2"));

      Publication.create(
          p,
          models.Location.find.byId(l),
          models.Interest.find.byId(i),
          PubType.get(bindedForm.get().pub_typ),
          safeBody);
    }
    return selectFeed(getLocalInterest(), getLocalLocation());
  }
Example #4
0
  @Restrict(Mupi.USER_ROLE)
  public static Result selectFeed(Long i, Long l) {
    final models.Profile p = Mupi.getLocalUser(session()).profile;

    return renderFeedContent(
        0,
        Publication.findByInterestLocation(i, l, 0, 10, "created desc"),
        Promotion.findByInterestLocation(i, l, 0, 5, "date, time"),
        models.Interest.find.byId(i),
        models.Location.find.byId(l));
  }
Example #5
0
 @Restrict(Mupi.USER_ROLE)
 public static Result commentPublication(String body, Long id) {
   final User u = Mupi.getLocalUser(session());
   final models.Profile p = u.profile;
   final models.Publication pub = models.Publication.find.byId(id);
   String safeBody =
       Jsoup.clean(
           textWithLinks(body.replaceAll("(\r\n|\n)", " <br/> ")),
           Whitelist.none().addTags("br", "a").addAttributes("a", "href", "target"));
   if (pub != null) {
     PubComment.create(pub, p, safeBody);
     List<UserEmail> l_ue = models.Profile.emailsFromPublication(pub);
     for (UserEmail ue : l_ue) {
       if (u.getEmail().equalsIgnoreCase(ue.getEmail()))
         System.out.println("Commenter: " + ue.getEmail());
       else System.out.println(ue.getEmail());
     }
     return AjaxResponse.build(0, comments.render(pub.getComments()).body());
   } else {
     return AjaxResponse.build(1, null);
   }
 }
Example #6
0
  public static Result feed() {
    final User user = Mupi.getLocalUser(session());
    if (user == null || user.profile == null) {
      session("ref", request().getHeader(HttpHeaders.REFERER));
      return ok(
          index.render(
              MyUsernamePasswordAuthProvider.LOGIN_FORM,
              MyUsernamePasswordAuthProvider.SIGNUP_FORM));
    } else if (session("ref") != null && !session().get("ref").equalsIgnoreCase("null")) {
      String url = session("ref");
      session().remove("ref");
      return redirect(url);
    } else if (user.getProfile().getInterests().isEmpty()) {
      return redirect(routes.Interest.interestManager());
    } else if (user.getProfile().getStatus() == MupiParams.FIRST_LOGIN) {
      return redirect(routes.Profile.profile());
    } else {
      Long interest = getLocalInterest();
      Long location = getLocalLocation();

      models.Interest i;
      if (interest == null) i = null;
      else i = models.Interest.find.byId(interest);
      models.Location l;
      if (location == null) l = null;
      else l = models.Location.find.byId(location);

      return ok(
          views.html.feed.render(
              user,
              user.getProfile().getInterests(),
              user.getProfile().getLocations(),
              i,
              l,
              Publication.findByInterests(
                  models.Interest.getIds(user.getProfile().getInterests()), 0l),
              Promotion.findByInterests(
                  models.Interest.getIds(user.getProfile().getInterests()), 0l),
              form(models.Promotion.class),
              PROMOTE_MEETUP_FORM,
              HOST_MEETUP_FORM,
              MyUsernamePasswordAuthProvider.LOGIN_FORM,
              MyUsernamePasswordAuthProvider.SIGNUP_FORM));
    }
  }