Poco now returns the last update date as well. This date will be stored in the gcontact table.

pull/1285/head
Michael Vogel 2015-01-04 19:19:47 +01:00
parent 3195bacd9e
commit 11c82816b3
6 changed files with 43 additions and 11 deletions

View File

@ -18,7 +18,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Ginger');
define ( 'FRIENDICA_VERSION', '3.3.2' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1175 );
define ( 'DB_UPDATE_VERSION', 1177 );
define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );

View File

@ -616,6 +616,7 @@ function db_definition() {
"nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
),
"indexes" => array(
"PRIMARY" => array("id"),

View File

@ -1343,6 +1343,16 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
$current_post = $r[0]['id'];
logger('item_store: created item ' . $current_post);
// Set "success_update" to the date of the last time we heard from this contact
// This can be used to filter for inactive contacts and poco.
// Only do this for public postings to avoid privacy problems, since poco data is public.
// Don't set this value if it isn't from the owner (could be an author that we don't know)
if (!$arr['private'] AND (($arr["author-link"] === $arr["owner-link"]) OR ($arr["parent-uri"] === $arr["uri"])))
$r = q("UPDATE `contact` SET `success_update` = '%s' WHERE `id` = %d",
dbesc($arr['received']),
intval($arr['contact-id'])
);
// Only check for notifications on start posts
if ($arr['parent-uri'] === $arr['uri']) {
add_thread($r[0]['id']);

View File

@ -39,7 +39,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
if(! $url)
return;
$url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos' : '?fields=displayName,urls,photos') ;
$url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos' : '?fields=displayName,urls,photos,updated') ;
logger('poco_load: ' . $url, LOGGER_DEBUG);
@ -67,6 +67,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
$profile_photo = '';
$connect_url = '';
$name = '';
$updated = '0000-00-00 00:00:00';
$name = $entry->displayName;
@ -82,7 +83,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
}
}
}
if(isset($entry->photos)) {
if(isset($entry->photos)) {
foreach($entry->photos as $photo) {
if($photo->type == 'profile') {
$profile_photo = $photo->value;
@ -91,6 +92,9 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
}
}
if(isset($entry->updated))
$updated = date("Y-m-d H:i:s", strtotime($entry->updated));
if((! $name) || (! $profile_url) || (! $profile_photo))
continue;
@ -101,25 +105,27 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
if(count($x)) {
$gcid = $x[0]['id'];
if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo) {
q("update gcontact set `name` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s'
if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) {
q("update gcontact set `name` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `updated` = '%s'
where `nurl` = '%s'",
dbesc($name),
dbesc($profile_photo),
dbesc($connect_url),
dbesc($profile_url),
dbesc($updated),
dbesc(normalise_link($profile_url))
);
}
}
else {
q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`)
q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`, `updated`)
values ( '%s', '%s', '%s', '%s','%s') ",
dbesc($name),
dbesc($profile_url),
dbesc(normalise_link($profile_url)),
dbesc($profile_photo),
dbesc($connect_url)
dbesc($connect_url),
dbesc($updated)
);
$x = q("select * from `gcontact` where `nurl` = '%s' limit 1",
dbesc(normalise_link($profile_url))

View File

@ -30,7 +30,7 @@ function poco_init(&$a) {
$justme = true;
if($a->argc > 4 && intval($a->argv[4]) && $justme == false)
$cid = intval($a->argv[4]);
if(! $system_mode) {
$r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid`
@ -106,6 +106,7 @@ function poco_init(&$a) {
'id' => false,
'displayName' => false,
'urls' => false,
'updated' => false,
'preferredUsername' => false,
'photos' => false
);
@ -130,10 +131,24 @@ function poco_init(&$a) {
if($fields_ret['urls']) {
$entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
$entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
$entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
}
if($fields_ret['preferredUsername'])
$entry['preferredUsername'] = $rr['nick'];
if($fields_ret['updated']) {
$entry['updated'] = $rr['success_update'];
if ($rr['name-date'] > $entry['updated'])
$entry['updated'] = $rr['name-date'];
if ($rr['uri-date'] > $entry['updated'])
$entry['updated'] = $rr['uri-date'];
if ($rr['avatar-date'] > $entry['updated'])
$entry['updated'] = $rr['avatar-date'];
$entry['updated'] = date("c", strtotime($entry['updated']));
}
if($fields_ret['photos'])
$entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
$ret['entry'][] = $entry;
@ -153,7 +168,7 @@ function poco_init(&$a) {
if($format === 'json') {
header('Content-type: application/json');
echo json_encode($ret);
killme();
killme();
}
else
http_status_exit(500);

View File

@ -1,6 +1,6 @@
<?php
define( 'UPDATE_VERSION' , 1175 );
define( 'UPDATE_VERSION' , 1177 );
/**
*