Only update the contact when the header changed

This commit is contained in:
Michael 2022-01-09 05:49:11 +00:00
parent cfd63f5682
commit 618903fef7

View file

@ -2202,32 +2202,6 @@ class Contact
$update = false; $update = false;
$guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST)); $guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST));
// make sure to not overwrite existing values with blank entries except some technical fields
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
foreach ($ret as $key => $val) {
if (!array_key_exists($key, $contact)) {
unset($ret[$key]);
} elseif (($contact[$key] != '') && ($val === '') && !is_bool($ret[$key]) && !in_array($key, $keep)) {
$ret[$key] = $contact[$key];
} elseif ($ret[$key] != $contact[$key]) {
$update = true;
}
}
if (!empty($ret['last-item']) && ($contact['last-item'] < $ret['last-item'])) {
$update = true;
} else {
unset($ret['last-item']);
}
if (empty($uriid)) {
$update = true;
}
if (!empty($ret['photo']) && ($ret['network'] != Protocol::FEED)) {
self::updateAvatar($id, $ret['photo'], $update);
}
if (empty($ret['header']) && !empty($gsid)) { if (empty($ret['header']) && !empty($gsid)) {
// Use default banners for certain platforms // Use default banners for certain platforms
$gserver = DBA::selectFirst('gserver', ['platform'], ['id' => $gsid]); $gserver = DBA::selectFirst('gserver', ['platform'], ['id' => $gsid]);
@ -2263,6 +2237,32 @@ class Contact
$ret['header'] = 'https://picsum.photos/seed/' . hash('ripemd128', $ret['url']) . '/960/300'; $ret['header'] = 'https://picsum.photos/seed/' . hash('ripemd128', $ret['url']) . '/960/300';
} }
// make sure to not overwrite existing values with blank entries except some technical fields
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
foreach ($ret as $key => $val) {
if (!array_key_exists($key, $contact)) {
unset($ret[$key]);
} elseif (($contact[$key] != '') && ($val === '') && !is_bool($ret[$key]) && !in_array($key, $keep)) {
$ret[$key] = $contact[$key];
} elseif ($ret[$key] != $contact[$key]) {
$update = true;
}
}
if (!empty($ret['last-item']) && ($contact['last-item'] < $ret['last-item'])) {
$update = true;
} else {
unset($ret['last-item']);
}
if (empty($uriid)) {
$update = true;
}
if (!empty($ret['photo']) && ($ret['network'] != Protocol::FEED)) {
self::updateAvatar($id, $ret['photo'], $update);
}
$uriid = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]); $uriid = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
if (!$update) { if (!$update) {