예제 #1
0
  @Security.Authenticated(Secured.class)
  public static Result viewMyConversations() {

    return ok(
        viewConversations.render(
            Student.find.byId(request().username()),
            Conversation.findConversationsOfStudent(Student.find.byId(request().username()))));
  }
예제 #2
0
 public static int numberOfUnreadMessagesOf(Student student) {
   int numberUnread = 0;
   List<Conversation> conversations = Conversation.findConversationsOfStudent(student);
   for (Conversation c : conversations) {
     for (Message m : c.messages) {
       if (!m.sender.email.equals(student.email) && !m.read) {
         numberUnread++;
       }
     }
   }
   return numberUnread;
 }
예제 #3
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;
 }