3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model;
25 use Friendica\Core\Protocol;
26 use Friendica\Database\DBA;
27 use Friendica\Util\DateTimeFormat;
30 * This class handles GlobalContact related functions
35 * @param integer $uid id
36 * @param integer $cid id
40 public static function countCommonFriends($uid, $cid)
42 $sourceId = Contact::getPublicIdByUserId($uid);
44 $targetIds = Contact::getPublicAndUserContacID($cid, $uid);
47 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
51 return ContactRelation::countCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition);
55 * @param integer $uid id
56 * @param integer $zcid zcid
60 public static function countCommonFriendsZcid($uid, $zcid)
62 $sourceId = Contact::getPublicIdByUserId($uid);
64 $targetPublicContact = DI::dba()->fetchFirst("
67 JOIN `gcontact` z ON z.`nurl` = c.`nurl`
74 return ContactRelation::countCommonFollowers($sourceId, $targetPublicContact['id'] ?? 0);
78 * Returns the cross-section between the local user contacts and one of their contact's own relationships
79 * as known by the local node.
81 * @param integer $uid local user id
82 * @param integer $cid user contact id to compare friends with
83 * @param integer $start optional, default 0
84 * @param integer $limit optional, default 9999
85 * @param boolean $shuffle optional, default false
89 public static function commonFriends($uid, $cid, $start = 0, $limit = 9999, $shuffle = false)
91 $sourceId = Contact::getPublicIdByUserId($uid);
93 $targetIds = Contact::getPublicAndUserContacID($cid, $uid);
96 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
100 return ContactRelation::listCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition, $limit, $start, $shuffle);
104 * Returns the cross-section between a local user and a remote visitor contact's own relationships
105 * as known by the local node.
107 * @param integer $uid local user id
108 * @param integer $zcid remote visitor contact zcid
109 * @param integer $start optional, default 0
110 * @param integer $limit optional, default 9999
111 * @param boolean $shuffle optional, default false
115 public static function commonFriendsZcid($uid, $zcid, $start = 0, $limit = 9999, $shuffle = false)
117 $sourceId = Contact::getPublicIdByUserId($uid);
119 $targetPublicContact = DI::dba()->fetchFirst("
122 JOIN `gcontact` z ON z.`nurl` = c.`nurl`
129 return ContactRelation::listCommonFollows($sourceId, $targetPublicContact['id'] ?? 0, [], $limit, $start, $shuffle);
133 * @param integer $uid user
134 * @param integer $cid cid
138 public static function countAllFriends($uid, $cid)
140 $cids = Contact::getPublicAndUserContacID($cid, $uid);
142 return ContactRelation::countFollows($cids['public'] ?? 0);
146 * @param integer $uid user
147 * @param integer $cid cid
148 * @param integer $start optional, default 0
149 * @param integer $limit optional, default 80
153 public static function allFriends($uid, $cid, $start = 0, $limit = 80)
155 $cids = Contact::getPublicAndUserContacID($cid, $uid);
157 return ContactRelation::listFollows($cids['public'] ?? 0, [], $limit, $start);