1
0
Fork 0

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

This commit is contained in:
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_CODENAME', 'Ginger');
define ( 'FRIENDICA_VERSION', '3.3.2' ); define ( 'FRIENDICA_VERSION', '3.3.2' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1175 ); define ( 'DB_UPDATE_VERSION', 1177 );
define ( 'EOL', "<br />\r\n" ); define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); 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" => ""), "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"photo" => 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" => ""), "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("id"), "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']; $current_post = $r[0]['id'];
logger('item_store: created item ' . $current_post); 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 // Only check for notifications on start posts
if ($arr['parent-uri'] === $arr['uri']) { if ($arr['parent-uri'] === $arr['uri']) {
add_thread($r[0]['id']); add_thread($r[0]['id']);

View file

@ -39,7 +39,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
if(! $url) if(! $url)
return; 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); logger('poco_load: ' . $url, LOGGER_DEBUG);
@ -67,6 +67,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
$profile_photo = ''; $profile_photo = '';
$connect_url = ''; $connect_url = '';
$name = ''; $name = '';
$updated = '0000-00-00 00:00:00';
$name = $entry->displayName; $name = $entry->displayName;
@ -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)) if((! $name) || (! $profile_url) || (! $profile_photo))
continue; continue;
@ -101,25 +105,27 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
if(count($x)) { if(count($x)) {
$gcid = $x[0]['id']; $gcid = $x[0]['id'];
if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo) { 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' q("update gcontact set `name` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `updated` = '%s'
where `nurl` = '%s'", where `nurl` = '%s'",
dbesc($name), dbesc($name),
dbesc($profile_photo), dbesc($profile_photo),
dbesc($connect_url), dbesc($connect_url),
dbesc($profile_url), dbesc($profile_url),
dbesc($updated),
dbesc(normalise_link($profile_url)) dbesc(normalise_link($profile_url))
); );
} }
} }
else { 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') ", values ( '%s', '%s', '%s', '%s','%s') ",
dbesc($name), dbesc($name),
dbesc($profile_url), dbesc($profile_url),
dbesc(normalise_link($profile_url)), dbesc(normalise_link($profile_url)),
dbesc($profile_photo), dbesc($profile_photo),
dbesc($connect_url) dbesc($connect_url),
dbesc($updated)
); );
$x = q("select * from `gcontact` where `nurl` = '%s' limit 1", $x = q("select * from `gcontact` where `nurl` = '%s' limit 1",
dbesc(normalise_link($profile_url)) dbesc(normalise_link($profile_url))

View file

@ -106,6 +106,7 @@ function poco_init(&$a) {
'id' => false, 'id' => false,
'displayName' => false, 'displayName' => false,
'urls' => false, 'urls' => false,
'updated' => false,
'preferredUsername' => false, 'preferredUsername' => false,
'photos' => false 'photos' => false
); );
@ -134,6 +135,20 @@ function poco_init(&$a) {
} }
if($fields_ret['preferredUsername']) if($fields_ret['preferredUsername'])
$entry['preferredUsername'] = $rr['nick']; $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']) if($fields_ret['photos'])
$entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile')); $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
$ret['entry'][] = $entry; $ret['entry'][] = $entry;

View file

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