} // first is op ? first connected user on the channel is an operator if ($GLOBALS['first_is_op'] and count(Container_channels::getChannelUsers($cid)) == 1) { $isop = Container_channels_op::addOp($cid, $uid); } if ($isop) { Container_channels_op::addOp($cid, $uid); } // post a join message // when a join message is sent, body contains user's data and the "op" flag $body = array('userdata' => Container_users::getUserData($uid), 'op' => $isop); $msg = Container_messages::postMsgToChannel($cid, $uid, $body, 'join'); $res->status(201); // User joined the channel $res['Content-Type'] = 'application/json; charset=utf-8'; $res->body(json_encode(array('users' => Container_channels::getChannelUsers($cid, true), 'op' => Container_channels_op::getOpList($cid)))); return; } }); /** * Leave a channel * or is kicked from a channel */ $app->delete('/channels/:cid/users/:uid', function ($cid, $uid) use($app, $req, $res) { // check user acces session_start(); if (!isset($_SESSION['userdata']) or !isset($_SESSION['userdata']['id'])) { $res->status(401); // Need to authenticate return; }
} $uid = $_SESSION['userdata']['id']; // check this user is online if (!Container_users::checkUserExists($uid)) { $res->status(400); // User is not connected return; } // check this user has joined the channel if (!Container_channels::checkChannelUser($cid, $uid)) { $res->status(403); // You have to join channel return; } // get the operators on $cid $ops = Container_channels_op::getOpList($cid); $res->status(200); $res['Content-Type'] = 'application/json; charset=utf-8'; $res->body(json_encode($ops)); }); /** * Tells if :uid is operator on :cid */ $app->get('/channels/:cid/op/:uid', function ($cid, $uid) use($app, $req, $res) { // check user acces session_start(); if (!isset($_SESSION['userdata']) or !isset($_SESSION['userdata']['id'])) { $res->status(401); // Need to authenticate return; }