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); }
private function notifyOnClose(User $user, UserCollection $clients) { $response = new MessageResponse(); if ($user->isAsyncDetach()) { $response->setMsg(MsgToken::create('LeavesUs', $user->getProperties()->getName())); } $response->setTime(null)->setGuests($clients->getUsersByChatId($user->getChannelId()))->setChannelId($user->getChannelId()); $clients->setResponse($response)->notify(); ChannelNotifier::updateChannelInfo($clients, ChannelsCollection::get()); }
public static function run(User $user, UserCollection $users, ChannelsCollection $chats) { if (!$user->isInPrivateChat()) { return; } self::moveUsersToPublic($user, $users); self::informYouselfOnExit($user); ChannelNotifier::uploadHistory($user, true); ChannelNotifier::indentifyChat($user, $users); $chats->clean($user); }
/** * @param User $user */ private function handleHistory(User $user) { ChannelNotifier::uploadHistory($user); $ds = DIRECTORY_SEPARATOR; if (file_exists(ROOT . $ds . 'www' . $ds . 'motd.txt') && !$user->getLastMsgId()) { $motd = file_get_contents(ROOT . $ds . 'www' . $ds . 'motd.txt'); $motd .= "<br>Доступны каналы:<br>"; foreach (ChannelsCollection::get()->getChannels() as $channel) { if ($channel->isPrivate()) { continue; } $motd .= '(' . DI::get()->getUsers()->getClientsCount($channel->getId()) . ') ' . $channel->getName() . '<br>'; } $client = (new UserCollection())->attach($user); $response = (new MessageResponse())->setChannelId($user->getChannelId())->setMsg(MsgRaw::create($motd)); $client->setResponse($response)->notify(false); } }
protected function processSubmit(ChainContainer $chain) { $request = $chain->getRequest(); $user = $chain->getFrom(); $lang = $user->getLang(); $onlineLimitRule = function ($val) { $val = (int) $val; return $val >= 0 && $val <= 50; }; $aboutRule = function ($val) { $len = mb_strlen($val); return $len >= 0 && $len <= 1024; }; try { $form = (new Form())->import($request)->addRule(PropertiesDAO::NAME, Rules::namePattern(), $lang->getPhrase('InvalidNameFormat'))->addRule(PropertiesDAO::ABOUT, $aboutRule, $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::TIM, Rules::timPattern(), $lang->getPhrase('InvalidTIMFormat'))->addRule(PropertiesDAO::SEX, Rules::sexPattern(), $lang->getPhrase('InvalidSexFormat'))->addRule(PropertiesDAO::CITY, Rules::cityPattern(), $lang->getPhrase('InvalidCityFormat'))->addRule(PropertiesDAO::BIRTH, Rules::birthYears(), $lang->getPhrase('InvalidYearFormat'))->addRule(PropertiesDAO::CENSOR, Rules::notNull(), $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::NOTIFY_VISUAL, Rules::notNull(), $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::NOTIFY_SOUND, Rules::notNull(), $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::LINE_BREAK_TYPE, Rules::notNull(), $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::ONLINE_NOTIFICATION, $onlineLimitRule, $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::IS_SUBSCRIBED, Rules::notNull(), $lang->getPhrase('InvalidField'))->addRule(PropertiesDAO::MESSAGE_ANIMATION_TYPE, Rules::msgAnimationType(), $lang->getPhrase('InvalidField')); } catch (WrongRuleNameException $e) { RespondError::make($user, ['property' => $lang->getPhrase('InvalidProperty') . ' ' . $e->getMessage()]); return; } if (!$form->validate()) { RespondError::make($user, $form->getErrors()); return; } $userName = $request[PropertiesDAO::NAME] = strip_tags(trim($request[PropertiesDAO::NAME])); if (!$this->checkIfAlreadyRegisteredName(CharTranslator::toEnglish($userName), $user)) { return; } if (!$this->checkIfAlreadyRegisteredName(CharTranslator::toRussian($userName), $user)) { return; } if ($user->isInPrivateChat() || PendingDuals::get()->getUserPosition($user)) { $this->forbiddenChangeInDualization($user); $this->propertiesResponse($user); return; } $oldName = $user->getProperties()->getName(); $this->importProperties($user, $request); $this->guestsUpdateResponse($user, $oldName); $this->propertiesResponse($user); ChannelNotifier::notifyOnPendingDuals($user); }