public static void post(Long convID, String msg) {
   if (!Security.isConnected()) return;
   Conversation conv = Conversation.findById(convID);
   if (conv == null) {
     conv = new Conversation();
     conv.id = convID;
     conv.save();
   }
   Message mess = new Message();
   mess.conversation = conv;
   mess.user = Security.loggedUser();
   mess.contents = msg;
   mess.timeSent = new Date();
   mess.save();
 }
Exemplo n.º 2
0
 public static long getConversationID(String stud1, String stud2) {
   List<Conversation> convs = Conversation.findConversationsOfStudent(Student.find.byId(stud1));
   long id = -1; // default value, new conv needs to be created
   if (stud1.equals(stud2)) {
     return -2;
   }
   for (Conversation c : convs) {
     if ((c.participants.get(0).email.equals(stud1) && c.participants.get(1).email.equals(stud2))
         || (c.participants.get(0).email.equals(stud2)
             && c.participants.get(1).email.equals(stud1))) {
       id = c.id;
     }
   }
   if (id == -1) {
     Conversation c = new Conversation(Student.find.byId(stud1), Student.find.byId(stud2));
     c.save();
     id = c.id;
   }
   return id;
 }
Exemplo n.º 3
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));
    }
  }