Merge pull request #3775 from annando/ostatus-nick-change
OStatus: Better handling of changed nicknames
This commit is contained in:
commit
49cc514f29
|
@ -607,6 +607,10 @@ function get_contact($url, $uid = 0, $no_update = false) {
|
||||||
$data = array_merge($data, $gcontacts);
|
$data = array_merge($data, $gcontacts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) {
|
||||||
|
$contact_id = get_contact($data["alias"], $uid, true);
|
||||||
|
}
|
||||||
|
|
||||||
$url = $data["url"];
|
$url = $data["url"];
|
||||||
if (!$contact_id) {
|
if (!$contact_id) {
|
||||||
dba::insert('contact', array('uid' => $uid, 'created' => datetime_convert(), 'url' => $data["url"],
|
dba::insert('contact', array('uid' => $uid, 'created' => datetime_convert(), 'url' => $data["url"],
|
||||||
|
@ -658,7 +662,7 @@ function get_contact($url, $uid = 0, $no_update = false) {
|
||||||
|
|
||||||
update_contact_avatar($data["photo"], $uid, $contact_id);
|
update_contact_avatar($data["photo"], $uid, $contact_id);
|
||||||
|
|
||||||
$contact = dba::select('contact', array('addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date'),
|
$contact = dba::select('contact', array('url', 'nurl', 'addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date'),
|
||||||
array('id' => $contact_id), array('limit' => 1));
|
array('id' => $contact_id), array('limit' => 1));
|
||||||
|
|
||||||
// This condition should always be true
|
// This condition should always be true
|
||||||
|
@ -668,6 +672,8 @@ function get_contact($url, $uid = 0, $no_update = false) {
|
||||||
|
|
||||||
$updated = array('addr' => $data['addr'],
|
$updated = array('addr' => $data['addr'],
|
||||||
'alias' => $data['alias'],
|
'alias' => $data['alias'],
|
||||||
|
'url' => $data['url'],
|
||||||
|
'nurl' => normalise_link($data['url']),
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
'nick' => $data['nick']);
|
'nick' => $data['nick']);
|
||||||
|
|
||||||
|
|
|
@ -62,12 +62,26 @@ class ostatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$author["contact-id"] = $contact["id"];
|
$author["contact-id"] = $contact["id"];
|
||||||
|
|
||||||
$found = false;
|
$found = false;
|
||||||
|
|
||||||
if ($author["author-link"] != "") {
|
if ($aliaslink != '') {
|
||||||
|
$condition = array("`uid` = ? AND `alias` = ? AND `network` != ?",
|
||||||
|
$importer["uid"], $aliaslink, NETWORK_STATUSNET);
|
||||||
|
$r = dba::select('contact', array(), $condition, array('limit' => 1));
|
||||||
|
|
||||||
|
if (dbm::is_result($r)) {
|
||||||
|
$found = true;
|
||||||
|
if ($r['blocked']) {
|
||||||
|
$r['id'] = -1;
|
||||||
|
}
|
||||||
|
$contact = $r;
|
||||||
|
$author["contact-id"] = $r["id"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$found && ($author["author-link"] != "")) {
|
||||||
if ($aliaslink == "") {
|
if ($aliaslink == "") {
|
||||||
$aliaslink = $author["author-link"];
|
$aliaslink = $author["author-link"];
|
||||||
}
|
}
|
||||||
|
@ -83,7 +97,6 @@ class ostatus {
|
||||||
}
|
}
|
||||||
$contact = $r;
|
$contact = $r;
|
||||||
$author["contact-id"] = $r["id"];
|
$author["contact-id"] = $r["id"];
|
||||||
$author["author-link"] = $r["url"];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,12 +106,12 @@ class ostatus {
|
||||||
$r = dba::select('contact', array(), $condition, array('limit' => 1));
|
$r = dba::select('contact', array(), $condition, array('limit' => 1));
|
||||||
|
|
||||||
if (dbm::is_result($r)) {
|
if (dbm::is_result($r)) {
|
||||||
|
$found = true;
|
||||||
if ($r['blocked']) {
|
if ($r['blocked']) {
|
||||||
$r['id'] = -1;
|
$r['id'] = -1;
|
||||||
}
|
}
|
||||||
$contact = $r;
|
$contact = $r;
|
||||||
$author["contact-id"] = $r["id"];
|
$author["contact-id"] = $r["id"];
|
||||||
$author["author-link"] = $r["url"];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +151,9 @@ class ostatus {
|
||||||
|
|
||||||
// Update contact data
|
// Update contact data
|
||||||
|
|
||||||
|
$current = $contact;
|
||||||
|
unset($current['name-date']);
|
||||||
|
|
||||||
// This query doesn't seem to work
|
// This query doesn't seem to work
|
||||||
// $value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue;
|
// $value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue;
|
||||||
// if ($value != "")
|
// if ($value != "")
|
||||||
|
@ -148,6 +164,9 @@ class ostatus {
|
||||||
// if ($value != "")
|
// if ($value != "")
|
||||||
// $contact["poll"] = $value;
|
// $contact["poll"] = $value;
|
||||||
|
|
||||||
|
$contact['url'] = $author["author-link"];
|
||||||
|
$contact['nurl'] = normalise_link($contact['url']);
|
||||||
|
|
||||||
$value = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue;
|
$value = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue;
|
||||||
if ($value != "")
|
if ($value != "")
|
||||||
$contact["alias"] = $value;
|
$contact["alias"] = $value;
|
||||||
|
@ -168,32 +187,25 @@ class ostatus {
|
||||||
if ($value != "")
|
if ($value != "")
|
||||||
$contact["location"] = $value;
|
$contact["location"] = $value;
|
||||||
|
|
||||||
if (($contact["name"] != $r[0]["name"]) || ($contact["nick"] != $r[0]["nick"]) || ($contact["about"] != $r[0]["about"]) ||
|
$contact['name-date'] = datetime_convert();
|
||||||
($contact["alias"] != $r[0]["alias"]) || ($contact["location"] != $r[0]["location"])) {
|
|
||||||
|
|
||||||
logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG);
|
dba::update('contact', $contact, array('id' => $contact["id"]), $current);
|
||||||
|
|
||||||
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `alias` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d",
|
if (!empty($author["author-avatar"]) && ($author["author-avatar"] != $current['avatar'])) {
|
||||||
dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["alias"]),
|
|
||||||
dbesc($contact["about"]), dbesc($contact["location"]),
|
|
||||||
dbesc(datetime_convert()), intval($contact["id"]));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($author["author-avatar"]) && ($author["author-avatar"] != $r[0]['avatar'])) {
|
|
||||||
logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
|
logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
|
||||||
|
|
||||||
update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]);
|
update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that we are having this contact (with uid=0)
|
// Ensure that we are having this contact (with uid=0)
|
||||||
$cid = get_contact($author["author-link"], 0);
|
$cid = get_contact($aliaslink, 0);
|
||||||
|
|
||||||
if ($cid) {
|
if ($cid) {
|
||||||
$fields = array('url', 'name', 'nick', 'alias', 'about', 'location');
|
$fields = array('url', 'nurl', 'name', 'nick', 'alias', 'about', 'location');
|
||||||
$old_contact = dba::select('contact', $fields, array('id' => $cid), array('limit' => 1));
|
$old_contact = dba::select('contact', $fields, array('id' => $cid), array('limit' => 1));
|
||||||
|
|
||||||
// Update it with the current values
|
// Update it with the current values
|
||||||
$fields = array('url' => $author["author-link"], 'name' => $contact["name"],
|
$fields = array('url' => $author["author-link"], 'name' => $contact["name"],
|
||||||
|
'nurl' => normalise_link($author["author-link"]),
|
||||||
'nick' => $contact["nick"], 'alias' => $contact["alias"],
|
'nick' => $contact["nick"], 'alias' => $contact["alias"],
|
||||||
'about' => $contact["about"], 'location' => $contact["location"],
|
'about' => $contact["about"], 'location' => $contact["location"],
|
||||||
'success_update' => datetime_convert(), 'last-update' => datetime_convert());
|
'success_update' => datetime_convert(), 'last-update' => datetime_convert());
|
||||||
|
|
Loading…
Reference in a new issue