sforkowany z mirror/friendica
Improved contact update from probe
rodzic
89655ff0ae
commit
e89d56be6d
|
@ -1624,27 +1624,35 @@ class Contact extends BaseObject
|
||||||
/**
|
/**
|
||||||
* @param integer $id contact id
|
* @param integer $id contact id
|
||||||
* @param string $network Optional network we are probing for
|
* @param string $network Optional network we are probing for
|
||||||
|
* @param boolean $force Optional forcing of network probing (otherwise we use the cached data)
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function updateFromProbe($id, $network = '')
|
public static function updateFromProbe($id, $network = '', $force = false)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Warning: Never ever fetch the public key via Probe::uri and write it into the contacts.
|
Warning: Never ever fetch the public key via Probe::uri and write it into the contacts.
|
||||||
This will reliably kill your communication with Friendica contacts.
|
This will reliably kill your communication with Friendica contacts.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$fields = ['url', 'nurl', 'addr', 'alias', 'batch', 'notify', 'poll', 'poco', 'network'];
|
$fields = ['avatar', 'uid', 'name', 'nick', 'url', 'addr', 'batch', 'notify',
|
||||||
|
'poll', 'request', 'confirm', 'poco', 'network', 'alias'];
|
||||||
$contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
|
$contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
|
||||||
if (!DBA::isResult($contact)) {
|
if (!DBA::isResult($contact)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = Probe::uri($contact["url"], $network);
|
$uid = $contact['uid'];
|
||||||
|
unset($contact['uid']);
|
||||||
|
|
||||||
|
$contact['photo'] = $contact['avatar'];
|
||||||
|
unset($contact['avatar']);
|
||||||
|
|
||||||
|
$ret = Probe::uri($contact['url'], $network, $uid, !$force);
|
||||||
|
|
||||||
// If Probe::uri fails the network code will be different (mostly "feed" or "unkn")
|
// If Probe::uri fails the network code will be different (mostly "feed" or "unkn")
|
||||||
if (($ret["network"] != $contact["network"]) && !in_array($ret["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, $network])) {
|
if ((in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM])) && ($ret['network'] != $contact['network'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1652,11 +1660,11 @@ class Contact extends BaseObject
|
||||||
|
|
||||||
// make sure to not overwrite existing values with blank entries
|
// make sure to not overwrite existing values with blank entries
|
||||||
foreach ($ret as $key => $val) {
|
foreach ($ret as $key => $val) {
|
||||||
if (isset($contact[$key]) && ($contact[$key] != "") && ($val == "")) {
|
if (!isset($contact[$key])) {
|
||||||
|
unset($ret[$key]);
|
||||||
|
} elseif (($contact[$key] != '') && ($val == '')) {
|
||||||
$ret[$key] = $contact[$key];
|
$ret[$key] = $contact[$key];
|
||||||
}
|
} elseif ($ret[$key] != $contact[$key]) {
|
||||||
|
|
||||||
if (isset($contact[$key]) && ($ret[$key] != $contact[$key])) {
|
|
||||||
$update = true;
|
$update = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1665,20 +1673,12 @@ class Contact extends BaseObject
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBA::update(
|
$ret['nurl'] = Strings::normaliseLink($ret['url']);
|
||||||
'contact', [
|
|
||||||
'url' => $ret['url'],
|
self::updateAvatar($ret['photo'], $uid, $id, true);
|
||||||
'nurl' => Strings::normaliseLink($ret['url']),
|
|
||||||
'network' => $ret['network'],
|
unset($ret['photo']);
|
||||||
'addr' => $ret['addr'],
|
DBA::update('contact', $ret, ['id' => $id]);
|
||||||
'alias' => $ret['alias'],
|
|
||||||
'batch' => $ret['batch'],
|
|
||||||
'notify' => $ret['notify'],
|
|
||||||
'poll' => $ret['poll'],
|
|
||||||
'poco' => $ret['poco']
|
|
||||||
],
|
|
||||||
['id' => $id]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update the corresponding gcontact entry
|
// Update the corresponding gcontact entry
|
||||||
PortableContact::lastUpdated($ret["url"]);
|
PortableContact::lastUpdated($ret["url"]);
|
||||||
|
|
Ładowanie…
Reference in New Issue