Ejemplo n.º 1
0
 /**
  * Add new message
  *
  * @param NewMessage $message
  *
  * @return int
  */
 public function addNewMessage(\Flocc\Mail\NewMessage $message)
 {
     /**
      * mail_messages
      */
     $messages = new Messages();
     $messages->conversation_id = $message->getConversationId();
     $messages->user_id = $message->getUserId();
     $messages->message = $message->getMessage();
     $messages->save();
     /**
      * mail_conversations
      */
     (new Conversations())->updateLastMessageTime($message->getConversationId());
     /**
      * mail_users
      */
     (new Users())->updateUnreadMessages($message->getConversationId(), [$message->getUserId()]);
     return $message->getConversationId();
 }
Ejemplo n.º 2
0
 /**
  * New conversation
  *
  * @param NewMessage $message
  *
  * @return int
  */
 public function addNewConversation(\Flocc\Mail\NewMessage $message)
 {
     /**
      * mail_conversations
      */
     $conversation = new Conversations();
     $conversation->last_message_time = null;
     $conversation->save();
     /**
      * ID
      */
     $conversation_id = (int) \DB::getPdo()->lastInsertId();
     /**
      * User label
      */
     $labels = new Labels();
     /**
      * owner
      */
     $mail_users = new Users();
     $mail_users->conversation_id = $conversation_id;
     $mail_users->user_id = $message->getUserId();
     $mail_users->label_id = $labels->getUserInboxID($message->getUserId());
     $mail_users->is_owner = '1';
     $mail_users->save();
     /**
      * mail_users
      */
     foreach ($message->getUsers() as $user_id) {
         if ((int) $user_id != $message->getUserId()) {
             $mail_users = new Users();
             $mail_users->conversation_id = $conversation_id;
             $mail_users->user_id = (int) $user_id;
             $mail_users->label_id = $labels->getUserInboxID($user_id);
             $mail_users->unread_messages = 1;
             $mail_users->save();
         }
     }
     /**
      * mail_messages
      */
     $messages = new Messages();
     $messages->conversation_id = $conversation_id;
     $messages->user_id = $message->getUserId();
     $messages->message = $message->getMessage();
     $messages->save();
     return (int) $conversation_id;
 }