Ejemplo n.º 1
0
 /**
  * Show messages from conversation
  *
  * @param int $conversation_id
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function showConversation($conversation_id)
 {
     /**
      * Sprawdzanie, czy taka konwersacja istnieje i czy mam do niej dostęp
      */
     $conversations = new Conversations();
     $users = new Users();
     if ($users->isUserInConversation(\Auth::user()->id, $conversation_id) === false) {
         return \Redirect::to('mail');
     }
     /**
      * Mark as read
      */
     $users->markAsRead($conversation_id, \Auth::user()->id);
     return view('mail.messages.conversation', ['conversation' => $conversations->getById($conversation_id)]);
 }
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;
 }
 /**
  * Select as important / not
  *
  * @param int $id
  * @param int $is
  *
  * @return mixed
  */
 public function important($id, $is)
 {
     $users = new Users();
     $users->where('conversation_id', $id)->where('user_id', Auth::getUserId())->update(['is_important' => (string) $is]);
     return \Redirect::to('mail/' . $id);
 }