/** * Submit a new message * * @param \Coyote\User $user * @param Request $request * @throws \Exception */ public function submit(\Coyote\User $user, Request $request) { $rootId = $request->get('root_id', dechex(mt_rand(0, 0x7fffffff))); $author = $this->user->findByName($request->get('author')); if (!$author) { throw new \Exception('Can not get recipient ID.'); } $text = Pm\Text::create(['text' => $request->get('text')]); $fill = ['root_id' => $rootId, 'text_id' => $text->id]; // we need to create two records. one for recipient and one for message author $this->model->create($fill + ['user_id' => $author->id, 'author_id' => $user->id, 'folder' => Pm::INBOX]); $pm = $this->model->create($fill + ['user_id' => $user->id, 'author_id' => $author->id, 'folder' => Pm::SENTBOX]); return $pm; }
/** * Parse users login * * @param array $excerpt * @return array */ protected function inlineUserTag($excerpt) { $text =& $excerpt['text']; $start = strpos($text, '@'); if (isset($text[$start + 1])) { $exitChar = $text[$start + 1] === '{' ? '}' : ' '; $end = strpos($text, $exitChar, $start); if ($end === false) { $end = mb_strlen($text) - $start; } $length = $end - $start; $start += 1; $end -= 1; if ($exitChar == '}') { $start += 1; $end -= 1; $length += 1; } $name = substr($text, $start, $end); $user = $this->user->findByName($name); if ($user) { return ['extent' => $length, 'element' => ['name' => 'a', 'text' => '@' . $name, 'attributes' => ['href' => route('profile', [$user->id]), 'data-user-id' => $user->id]]]; } } }