function friend_accept($entityKey, $groupId) { $connection = new HubbubConnection(object('user')->ds['u_entity'], $entityKey); $connection->group($groupId); $friendEntity = new HubbubEntity($entityKey); return($this->friend_request($friendEntity)); }
/** * Receipt of a friend request message * @param object $data * @param object $msg * @return */ function friend_request_receive(&$data, &$msg) { // allow only if the server is trusted if (!$msg->validateSignature()) { return true; } $con = new HubbubConnection($msg->ownerEntity->key(), $msg->authorEntity->key()); $usr = new HubbubUser($msg->ownerEntity->key()); WriteToFile('log/activity.log', $data['msgid'] . ' friend_request received' . chr(10)); h2_audit_log('msg/friend_request/rcv', array('me' => $msg->ownerEntity->key(), 'sender' => $msg->authorEntity->key()), $data['msgid']); switch ($con->status()) { case 'req.sent': // if we already sent a request to them, complete the process $con->status('friend'); $usr->notify('friend/added', $msg->authorEntity); $msg->response['comment'] = 'status updated to {friend}'; break; case 'undefined': $con->status('req.rcv'); $usr->notify('friend/request', $msg->authorEntity); $msg->response['comment'] = 'status updated to {received}'; break; default: $msg->response['comment'] = 'status not updated'; break; } $msg->ok(); return true; }
function quickConnect($e0, $e1) { $con0to1 = new HubbubConnection($e0, $e1); $con0to1->status('friend'); $con1to0 = new HubbubConnection($e1, $e0); $con1to0->status('friend'); }
/** * Receipt of a friend request message * @param object $data * @param object $msg * @return */ function friend_remove_receive(&$data, &$msg) { // allow only if the server is trusted if (!$msg->validateSignature()) { return true; } $con = new HubbubConnection($msg->ownerEntity->key(), $msg->authorEntity->key()); if ($con->status() != 'friend') { return $msg->fail('no connection'); } $con->status('undefined'); $msg->ok(); return true; }
function foreign_post_receive(&$data, &$msg) { if (!$msg->validateSignature()) { return true; } WriteToFile('log/activity.log', $data['msgid'] . ' foreign_post ' . $msg->ownerEntity->key() . ' to ' . $msg->authorEntity->key() . chr(10)); $con = new HubbubConnection($msg->ownerEntity->key(), $msg->authorEntity->key()); if ($con->status() != 'friend') { return $msg->fail('no connection'); } $usr = new HubbubUser($msg->ownerEntity->key()); if ($con->ds['c_auto_approve'] == 'Y') { // if we're gonna approve this anyway, there is no reason to store the message // let's just create a post out of this WriteToFile('log/activity.log', $data['msgid'] . ' foreign_post received, accepted' . chr(10)); $post = new HubbubMessage('post'); $npid = $post->data['msgid']; $post->data = $msg->data; $post->data['type'] = 'post'; $post->data['msgid'] = $npid; $post->author($msg->authorEntity->ds); $post->owner($msg->ownerEntity->ds); $post->data['changed'] = time(); $post->data['received'] = time(); $post->data['rel']['foreign'] = $data['msgid']; $post->save(); WriteToFile('log/activity.log', $post->data['msgid'] . ' created from foreign_post' . chr(10)); $msg->response['post'] = $post->data; $msg->doSave = false; $usr->notify('fpost/new', $msg->authorEntity, $msg); } else { // if not, let's store this message for later approval $usr->notify('fpost/approve', $msg->authorEntity, $msg); $msg->vTag = 'A'; $msg->save(); } $msg->ok(); }
/** * This sends a blanket DMN to the user's closest connections */ function broadcast() { // fixme: obviously if ($GLOBALS['bcflag']) { return; } else { $GLOBALS['bcflag'] = true; } $this->sanitizeDataset(); $this->executeHandler('broadcast'); $this->payload = json_encode($this->data); $requests = array(); foreach (HubbubConnection::GetClosestServers($this->authorEntity->key()) as $con) { $req_urls[] = $con['s_url']; $requests[] = array('url' => $con['s_url'], 'params' => array('hubbub_sig' => md5($con['s_key_out'] . trim($this->payload)))); WriteToFile('log/activity.log', '- broadcast to server ' . $con['s_url'] . chr(10)); } $messageData = array('hubbub_msg' => $this->payload); if (sizeof($req_urls) > 0) { HubbubEndpoint::multiRequest($requests, $messageData); h2_audit_log('msg/broadcast', array('to' => $req_urls), $this->data['msgid']); } }