basic support for AS friend requests

This commit is contained in:
Friendika 2011-10-02 16:18:01 -07:00
parent 7c1968907d
commit 8f9656da92
2 changed files with 38 additions and 10 deletions

View File

@ -8,7 +8,7 @@ require_once("include/pgettext.php");
require_once('include/nav.php'); require_once('include/nav.php');
define ( 'FRIENDIKA_PLATFORM', 'Free Friendika'); define ( 'FRIENDIKA_PLATFORM', 'Free Friendika');
define ( 'FRIENDIKA_VERSION', '2.3.1121' ); define ( 'FRIENDIKA_VERSION', '2.3.1122' );
define ( 'DFRN_PROTOCOL_VERSION', '2.21' ); define ( 'DFRN_PROTOCOL_VERSION', '2.21' );
define ( 'DB_UPDATE_VERSION', 1094 ); define ( 'DB_UPDATE_VERSION', 1094 );
@ -152,6 +152,8 @@ define ( 'ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike' );
define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' ); define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' );
define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' ); define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );
define ( 'ACTIVITY_REQ_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'request-friend' );
define ( 'ACTIVITY_UNFRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'remove-friend' );
define ( 'ACTIVITY_FOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'follow' ); define ( 'ACTIVITY_FOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'follow' );
define ( 'ACTIVITY_UNFOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'stop-following' ); define ( 'ACTIVITY_UNFOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'stop-following' );
define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' ); define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' );

View File

@ -1491,6 +1491,20 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
lose_follower($importer,$contact,$datarray,$item); lose_follower($importer,$contact,$datarray,$item);
return; return;
} }
if(activity_match($datarray['verb'],ACTIVITY_REQ_FRIEND)) {
logger('consume-feed: New friend request');
new_follower($importer,$contact,$datarray,$item,true);
return;
}
if(activity_match($datarray['verb'],ACTIVITY_UNFRIEND)) {
lose_sharer($importer,$contact,$datarray,$item);
return;
}
if(! is_array($contact)) if(! is_array($contact))
return; return;
@ -1522,7 +1536,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
} }
} }
function new_follower($importer,$contact,$datarray,$item) { function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
$url = notags(trim($datarray['author-link'])); $url = notags(trim($datarray['author-link']));
$name = notags(trim($datarray['author-name'])); $name = notags(trim($datarray['author-name']));
$photo = notags(trim($datarray['author-avatar'])); $photo = notags(trim($datarray['author-avatar']));
@ -1532,14 +1546,14 @@ function new_follower($importer,$contact,$datarray,$item) {
$nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']; $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'];
if(is_array($contact)) { if(is_array($contact)) {
if($contact['network'] == 'stat' && $contact['rel'] == CONTACT_IS_SHARING) { if(($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING)
|| ($sharing && $contact['rel'] == CONTACT_IS_FOLLOWER)) {
$r = q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", $r = q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval(CONTACT_IS_FRIEND), intval(CONTACT_IS_FRIEND),
intval($contact['id']), intval($contact['id']),
intval($importer['uid']) intval($importer['uid'])
); );
} }
// send email notification to owner? // send email notification to owner?
} }
else { else {
@ -1555,13 +1569,12 @@ function new_follower($importer,$contact,$datarray,$item) {
dbesc($name), dbesc($name),
dbesc($nick), dbesc($nick),
dbesc($photo), dbesc($photo),
dbesc('stat'), dbesc(($sharing) ? NETWORK_ZOT : NETWORK_OSTATUS),
intval(CONTACT_IS_FOLLOWER) intval(($sharing) ? CONTACT_IS_SHARING : CONTACT_IS_FOLLOWER)
); );
$r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 AND `rel` = %d LIMIT 1", $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 LIMIT 1",
intval($importer['uid']), intval($importer['uid']),
dbesc($url), dbesc($url)
intval(CONTACT_IS_FOLLOWER)
); );
if(count($r)) if(count($r))
$contact_record = $r[0]; $contact_record = $r[0];
@ -1593,7 +1606,7 @@ function new_follower($importer,$contact,$datarray,$item) {
'$sitename' => $a->config['sitename'] '$sitename' => $a->config['sitename']
)); ));
$res = mail($r[0]['email'], $res = mail($r[0]['email'],
t("You have a new follower at ") . $a->config['sitename'], (($sharing) ? t('A new person is sharing with you at ') : t("You have a new follower at ")) . $a->config['sitename'],
$email, $email,
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n" 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n"
@ -1617,6 +1630,19 @@ function lose_follower($importer,$contact,$datarray,$item) {
} }
} }
function lose_sharer($importer,$contact,$datarray,$item) {
if(($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_FOLLOWER)) {
q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d LIMIT 1",
intval(CONTACT_IS_FOLLOWER),
intval($contact['id'])
);
}
else {
contact_remove($contact['id']);
}
}
function subscribe_to_hub($url,$importer,$contact,$submode = 'subscribe') { function subscribe_to_hub($url,$importer,$contact,$submode = 'subscribe') {