mirror of
https://github.com/friendica/friendica
synced 2024-11-17 23:03:41 +00:00
Merge pull request #14481 from annando/issue-14121
Issue 14121: Show precise contact counts for own user
This commit is contained in:
commit
4380d7fa12
2 changed files with 69 additions and 10 deletions
|
@ -91,23 +91,59 @@ class Widget
|
||||||
$networks = [Protocol::PHANTOM, Protocol::FACEBOOK, Protocol::APPNET, Protocol::TWITTER, Protocol::ZOT, Protocol::OSTATUS, Protocol::STATUSNET];
|
$networks = [Protocol::PHANTOM, Protocol::FACEBOOK, Protocol::APPNET, Protocol::TWITTER, Protocol::ZOT, Protocol::OSTATUS, Protocol::STATUSNET];
|
||||||
Addon::loadAddons();
|
Addon::loadAddons();
|
||||||
|
|
||||||
if (!Addon::isEnabled("discourse")) {
|
if (!Addon::isEnabled('discourse')) {
|
||||||
$networks[] = Protocol::DISCOURSE;
|
$networks[] = Protocol::DISCOURSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Addon::isEnabled("pumpio")) {
|
if (!Addon::isEnabled('pumpio')) {
|
||||||
$networks[] = Protocol::PUMPIO;
|
$networks[] = Protocol::PUMPIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Addon::isEnabled("tumblr")) {
|
if (!Addon::isEnabled('tumblr')) {
|
||||||
$networks[] = Protocol::TUMBLR;
|
$networks[] = Protocol::TUMBLR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DI::config()->get("system", "diaspora_enabled")) {
|
if (!DI::config()->get('system', 'diaspora_enabled')) {
|
||||||
$networks[] = Protocol::DIASPORA;
|
$networks[] = Protocol::DIASPORA;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Addon::isEnabled("pnut")) {
|
if (!Addon::isEnabled('pnut')) {
|
||||||
|
$networks[] = Protocol::PNUT;
|
||||||
|
}
|
||||||
|
return $networks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return available networks as array
|
||||||
|
*
|
||||||
|
* @return array Supported networks
|
||||||
|
*/
|
||||||
|
public static function availableNetworks(): array
|
||||||
|
{
|
||||||
|
$networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::FEED];
|
||||||
|
Addon::loadAddons();
|
||||||
|
|
||||||
|
if (Addon::isEnabled('discourse')) {
|
||||||
|
$networks[] = Protocol::DISCOURSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Addon::isEnabled('pumpio')) {
|
||||||
|
$networks[] = Protocol::PUMPIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Addon::isEnabled('tumblr')) {
|
||||||
|
$networks[] = Protocol::TUMBLR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DI::config()->get('system', 'diaspora_enabled')) {
|
||||||
|
$networks[] = Protocol::DIASPORA;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (function_exists('imap_open') && !DI::config()->get('system', 'imap_disabled')) {
|
||||||
|
$networks[] = Protocol::MAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Addon::isEnabled('pnut')) {
|
||||||
$networks[] = Protocol::PNUT;
|
$networks[] = Protocol::PNUT;
|
||||||
}
|
}
|
||||||
return $networks;
|
return $networks;
|
||||||
|
@ -382,7 +418,7 @@ class Widget
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('widget/remote_friends_common.tpl');
|
$tpl = Renderer::getMarkupTemplate('widget/remote_friends_common.tpl');
|
||||||
return Renderer::replaceMacros($tpl, [
|
return Renderer::replaceMacros($tpl, [
|
||||||
'$desc' => DI::l10n()->tt("%d contact in common", "%d contacts in common", $total),
|
'$desc' => DI::l10n()->tt('%d contact in common', '%d contacts in common', $total),
|
||||||
'$base' => DI::baseUrl(),
|
'$base' => DI::baseUrl(),
|
||||||
'$nickname' => $nickname,
|
'$nickname' => $nickname,
|
||||||
'$linkmore' => $total > 5 ? 'true' : '',
|
'$linkmore' => $total > 5 ? 'true' : '',
|
||||||
|
@ -576,4 +612,4 @@ class Widget
|
||||||
$channelname
|
$channelname
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,10 @@ namespace Friendica\Factory\Api\Mastodon;
|
||||||
use Friendica\App\BaseURL;
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
use Friendica\Collection\Api\Mastodon\Fields;
|
use Friendica\Collection\Api\Mastodon\Fields;
|
||||||
|
use Friendica\Content\Widget;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Profile\ProfileField\Repository\ProfileField as ProfileFieldRepository;
|
use Friendica\Profile\ProfileField\Repository\ProfileField as ProfileFieldRepository;
|
||||||
use ImagickException;
|
use ImagickException;
|
||||||
|
@ -75,10 +77,15 @@ class Account extends BaseFactory
|
||||||
$fields = new Fields();
|
$fields = new Fields();
|
||||||
|
|
||||||
if (Contact::isLocal($account['url'])) {
|
if (Contact::isLocal($account['url'])) {
|
||||||
$self_contact = Contact::selectFirst(['uid'], ['nurl' => $account['nurl'], 'self' => true]);
|
$profile_uid = User::getIdForContactId($account['id']);
|
||||||
if (!empty($self_contact['uid'])) {
|
if ($profile_uid) {
|
||||||
$profileFields = $this->profileFieldRepo->selectPublicFieldsByUserId($self_contact['uid']);
|
$profileFields = $this->profileFieldRepo->selectPublicFieldsByUserId($profile_uid);
|
||||||
$fields = $this->mstdnFieldFactory->createFromProfileFields($profileFields);
|
$fields = $this->mstdnFieldFactory->createFromProfileFields($profileFields);
|
||||||
|
|
||||||
|
if ($profile_uid == $uid) {
|
||||||
|
$account['ap-followers_count'] = $this->getContactRelationCountForUid($uid, [Contact::FOLLOWER, Contact::FRIEND]);
|
||||||
|
$account['ap-following_count'] = $this->getContactRelationCountForUid($uid, [Contact::SHARING, Contact::FRIEND]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,4 +105,20 @@ class Account extends BaseFactory
|
||||||
|
|
||||||
return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $account, $fields);
|
return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $account, $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getContactRelationCountForUid(int $uid, array $rel): int
|
||||||
|
{
|
||||||
|
$condition = [
|
||||||
|
'uid' => $uid,
|
||||||
|
'rel' => $rel,
|
||||||
|
'self' => false,
|
||||||
|
'deleted' => false,
|
||||||
|
'archive' => false,
|
||||||
|
'pending' => false,
|
||||||
|
'blocked' => false,
|
||||||
|
'network' => Widget::availableNetworks(),
|
||||||
|
];
|
||||||
|
|
||||||
|
return DBA::count('contact', $condition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue