mirror of
https://github.com/friendica/friendica
synced 2025-04-26 01:50:11 +00:00
Display interaction data for Diaspora accounts
This commit is contained in:
parent
5a07068049
commit
29be22ee6a
7 changed files with 72 additions and 35 deletions
|
@ -211,6 +211,19 @@ class Contact
|
|||
return DBA::selectFirst('contact', $fields, ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the first contact with the provided uri-id.
|
||||
*
|
||||
* @param integer $uri_id uri-id of the contact
|
||||
* @param array $fields Array of selected fields, empty for all
|
||||
* @return array|boolean Contact record if it exists, false otherwise
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getByUriId($uri_id, $fields = [])
|
||||
{
|
||||
return DBA::selectFirst('contact', $fields, ['uri-id' => $uri_id], ['order' => ['uid']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a contact by a given url
|
||||
*
|
||||
|
|
|
@ -40,12 +40,12 @@ class FContact
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function getByURL($handle, $update = null, $network = Protocol::DIASPORA)
|
||||
public static function getByURL($handle, $update = null)
|
||||
{
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => $network, 'addr' => $handle]);
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'addr' => $handle]);
|
||||
if (!DBA::isResult($person)) {
|
||||
$urls = [$handle, str_replace('http://', 'https://', $handle), Strings::normaliseLink($handle)];
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => $network, 'url' => $urls]);
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'url' => $urls]);
|
||||
}
|
||||
|
||||
if (DBA::isResult($person)) {
|
||||
|
@ -70,14 +70,14 @@ class FContact
|
|||
|
||||
if ($update) {
|
||||
Logger::info('create or refresh', ['handle' => $handle]);
|
||||
$r = Probe::uri($handle, $network);
|
||||
$data = Probe::uri($handle, Protocol::DIASPORA);
|
||||
|
||||
// Note that Friendica contacts will return a "Diaspora person"
|
||||
// if Diaspora connectivity is enabled on their server
|
||||
if ($r && ($r["network"] === $network)) {
|
||||
self::updateFContact($r);
|
||||
if ($data['network'] ?? '' === Protocol::DIASPORA) {
|
||||
self::updateFContact($data);
|
||||
|
||||
$person = self::getByURL($handle, false, $network);
|
||||
$person = self::getByURL($handle, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,13 +92,25 @@ class FContact
|
|||
*/
|
||||
private static function updateFContact($arr)
|
||||
{
|
||||
$uriid = ItemURI::insert(['uri' => $arr['url'], 'guid' => $arr['guid']]);
|
||||
|
||||
$contact = Contact::getByUriId($uriid, ['id']);
|
||||
if (!empty($contact['id'])) {
|
||||
$last_interaction = DateTimeFormat::utc('now - 180 days');
|
||||
|
||||
$interacted = DBA::count('contact-relation', ["`cid` = ? AND NOT `follows` AND `last-interaction` > ?", $contact['id'], $last_interaction]);
|
||||
$interacting = DBA::count('contact-relation', ["`relation-cid` = ? AND NOT `follows` AND `last-interaction` > ?", $contact['id'], $last_interaction]);
|
||||
$posts = Post::countPosts(['author-id' => $contact['id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]);
|
||||
}
|
||||
|
||||
$fields = ['name' => $arr["name"], 'photo' => $arr["photo"],
|
||||
'request' => $arr["request"], 'nick' => $arr["nick"],
|
||||
'addr' => strtolower($arr["addr"]), 'guid' => $arr["guid"],
|
||||
'batch' => $arr["batch"], 'notify' => $arr["notify"],
|
||||
'poll' => $arr["poll"], 'confirm' => $arr["confirm"],
|
||||
'alias' => $arr["alias"], 'pubkey' => $arr["pubkey"],
|
||||
'uri-id' => ItemURI::insert(['uri' => $arr['url'], 'guid' => $arr['guid']]),
|
||||
'uri-id' => $uriid, 'interacting_count' => $interacting ?? 0,
|
||||
'interacted_count' => $interacted ?? 0, 'post_count' => $posts ?? 0,
|
||||
'updated' => DateTimeFormat::utcNow()];
|
||||
|
||||
$condition = ['url' => $arr["url"], 'network' => $arr["network"]];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue