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); }
/** * @param User $user * @param UserCollection $userCollection */ public function notifyChat(User $user, UserCollection $userCollection) { $channelId = $user->getChannelId(); DI::get()->getLogger()->info("Total user count {$userCollection->getTotalCount()}", [__CLASS__]); if ($user->isInPrivateChat()) { $dualUsers = new UserCollection(); $dualUsers->attach($user); $response = (new MessageResponse())->setTime(null)->setGuests($userCollection->getUsersByChatId($channelId))->setChannelId($channelId); if ($userCollection->getClientsCount($channelId) > 1) { $dualUsers = $userCollection; $response->setMsg(MsgToken::create('PartnerIsOnline'))->setDualChat('match'); } elseif ($num = PendingDuals::get()->getUserPosition($user)) { $response->setMsg(MsgToken::create('StillInDualSearch', $num))->setDualChat('init'); } else { $response->setMsg(MsgToken::create('YouAreAlone'))->setDualChat('match'); } if ($user->getLastMsgId()) { $response->setMsg(Msg::create(null)); } $dualUsers->setResponse($response)->notify(false); } else { ChannelNotifier::welcome($user, $userCollection); ChannelNotifier::indentifyChat($user, $userCollection, true); } }
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); }