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\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 Contact\Relation::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`
75 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
79 return Contact\Relation::countCommonFollowers($sourceId, $targetPublicContact['id'] ?? 0, $condition);
83 * Returns the cross-section between the local user contacts and one of their contact's own relationships
84 * as known by the local node.
86 * @param integer $uid local user id
87 * @param integer $cid user contact id to compare friends with
88 * @param integer $start optional, default 0
89 * @param integer $limit optional, default 9999
90 * @param boolean $shuffle optional, default false
94 public static function commonFriends($uid, $cid, $start = 0, $limit = 9999, $shuffle = false)
96 $sourceId = Contact::getPublicIdByUserId($uid);
98 $targetIds = Contact::getPublicAndUserContacID($cid, $uid);
101 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
105 return Contact\Relation::listCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition, $limit, $start, $shuffle);
109 * Returns the cross-section between a local user and a remote visitor contact's own relationships
110 * as known by the local node.
112 * @param integer $uid local user id
113 * @param integer $zcid remote visitor contact zcid
114 * @param integer $start optional, default 0
115 * @param integer $limit optional, default 9999
116 * @param boolean $shuffle optional, default false
120 public static function commonFriendsZcid($uid, $zcid, $start = 0, $limit = 9999, $shuffle = false)
122 $sourceId = Contact::getPublicIdByUserId($uid);
124 $targetPublicContact = DI::dba()->fetchFirst("
127 JOIN `gcontact` z ON z.`nurl` = c.`nurl`
135 'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
139 return Contact\Relation::listCommonFollows($sourceId, $targetPublicContact['id'] ?? 0, $condition, $limit, $start, $shuffle);
143 * @param integer $uid user
144 * @param integer $cid cid
148 public static function countAllFriends($uid, $cid)
150 $cids = Contact::getPublicAndUserContacID($cid, $uid);
152 return Contact\Relation::countFollows($cids['public'] ?? 0);
156 * @param integer $uid user
157 * @param integer $cid cid
158 * @param integer $start optional, default 0
159 * @param integer $limit optional, default 80
163 public static function allFriends($uid, $cid, $start = 0, $limit = 80)
165 $cids = Contact::getPublicAndUserContacID($cid, $uid);
167 return Contact\Relation::listFollows($cids['public'] ?? 0, [], $limit, $start);