Exemple #1
0
  @Security.Authenticated(Secured.class)
  public static Result viewMyConversation(Long id) {
    Student s = Student.find.byId(request().username());
    Conversation c = Conversation.find.byId(id.toString());

    if (!c.getParticipants().contains(s)) { // unauthorized access!
      return redirect(routes.Application.viewMyConversations());
    } else {
      // mark all read
      for (Message m : c.messages) {
        if (!m.sender.email.equals(s.email)) {
          m.setRead();
          m.save();
        }
      }

      return ok(viewConversation.render(s, c, form(MessageForm.class)));
    }
  }
Exemple #2
0
  @Security.Authenticated(Secured.class)
  public static Result addNewMessageForm(Long id) {
    Form<MessageForm> mesForm = Form.form(MessageForm.class).bindFromRequest();
    if (mesForm.hasErrors()) {
      return badRequest(postNewMessage.render(mesForm, id));
    } else {

      Message m =
          new Message(
              mesForm.field("text").value().toString(), Student.find.byId(request().username()));

      Conversation c = null;

      c = Conversation.find.byId(id.toString());
      c.messages.add(m);
      c.save();

      return redirect(routes.Application.viewMyConversation(id));
    }
  }