public static function joinPrivate(ChainContainer $chain) { $users = DI::get()->getUsers(); $user = $chain->getFrom(); $lang = $user->getLang(); if (!($desiredUser = self::checkRestrictions($chain, $users))) { return; } $privates = PendingPrivates::get(); list($inviterUserId, $time) = $privates->invite($user, $desiredUser, self::getTimeoutCallableResponse()); $remainingTime = time() - $time; if ($remainingTime < $privates->getTTL() && $inviterUserId) { RespondError::make($user, [PropertiesDAO::USER_ID => $lang->getPhrase('YouAlreadySentInvitation', $privates->getTTL() - $remainingTime)]); return; } elseif (!$time && !$inviterUserId) { $newChatRoomId = uniqid('_', 1); $desiredUser->setChannelId($newChatRoomId); $desiredUser->save(); $channel = new Channel($newChatRoomId, 'Приват_' . $newChatRoomId); $channel->setOwnerId($user->getId()); ChannelsCollection::get()->addChannel($channel); $user->setChannelId($newChatRoomId); $user->save(); self::sendMatchResponse($users->getUsersByChatId($newChatRoomId), MsgToken::create('InvitationAccepted')); return; } self::sendPendingResponse($user, MsgToken::create('SendInvitationFor', $desiredUser->getProperties()->getName())); self::sendPendingResponse($desiredUser, MsgToken::create('UserInvitesYou', $user->getProperties()->getName(), $user->getId())); ChannelNotifier::updateChannelInfo($users, ChannelsCollection::get()); }
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()); }