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); }
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); } }