Ejemplo n.º 1
0
 public static function joinPublic(ChainContainer $chain)
 {
     $users = DI::get()->getUsers();
     $user = $chain->getFrom();
     $lang = $user->getLang();
     $request = $chain->getRequest();
     if ($user->isInPrivateChat()) {
         RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('YouCantLeavePrivate')]);
         return;
     }
     try {
         $form = (new Form())->import($request)->addRule('channelId', Rules::existsChannel(), $lang->getPhrase('ChannelNotExists'))->addRule('channelId', Rules::verifyOnJoinRule($user));
     } catch (WrongRuleNameException $e) {
         RespondError::make($user);
         return;
     }
     if (!$form->validate()) {
         RespondError::make($user, $form->getErrors());
         return;
     }
     $channelId = trim($form->getValue('channelId'));
     $oldChannelId = $user->getChannelId();
     $user->setChannelId($channelId);
     $user->save(false);
     $user->setLastMsgId(0);
     ChannelNotifier::uploadHistory($user, true);
     ChannelNotifier::welcome($user, $users);
     ChannelNotifier::updateGuestsList($users, $oldChannelId);
     ChannelNotifier::indentifyChat($user, $users);
 }