3 * @copyright Copyright (C) 2010-2021, the Friendica project
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\Contact;
24 use Friendica\Database\DBA;
25 use Friendica\Model\Contact;
28 * This class provides information about user related contacts based on the "user-contact" table.
33 * Block contact id for user id
35 * @param int $cid Either public contact id or user's contact id
36 * @param int $uid User ID
37 * @param boolean $blocked Is the contact blocked or unblocked?
40 public static function setBlocked($cid, $uid, $blocked)
42 $cdata = Contact::getPublicAndUserContacID($cid, $uid);
47 if ($cdata['user'] != 0) {
48 DBA::update('contact', ['blocked' => $blocked], ['id' => $cdata['user'], 'pending' => false]);
51 DBA::update('user-contact', ['blocked' => $blocked], ['cid' => $cdata['public'], 'uid' => $uid], true);
55 * Returns "block" state for contact id and user id
57 * @param int $cid Either public contact id or user's contact id
58 * @param int $uid User ID
60 * @return boolean is the contact id blocked for the given user?
63 public static function isBlocked($cid, $uid)
65 $cdata = Contact::getPublicAndUserContacID($cid, $uid);
70 $public_blocked = false;
72 if (!empty($cdata['public'])) {
73 $public_contact = DBA::selectFirst('user-contact', ['blocked'], ['cid' => $cdata['public'], 'uid' => $uid]);
74 if (DBA::isResult($public_contact)) {
75 $public_blocked = $public_contact['blocked'];
79 $user_blocked = $public_blocked;
81 if (!empty($cdata['user'])) {
82 $user_contact = DBA::selectFirst('contact', ['blocked'], ['id' => $cdata['user'], 'pending' => false]);
83 if (DBA::isResult($user_contact)) {
84 $user_blocked = $user_contact['blocked'];
88 if ($user_blocked != $public_blocked) {
89 DBA::update('user-contact', ['blocked' => $user_blocked], ['cid' => $cdata['public'], 'uid' => $uid], true);
96 * Ignore contact id for user id
98 * @param int $cid Either public contact id or user's contact id
99 * @param int $uid User ID
100 * @param boolean $ignored Is the contact ignored or unignored?
103 public static function setIgnored($cid, $uid, $ignored)
105 $cdata = Contact::getPublicAndUserContacID($cid, $uid);
110 if ($cdata['user'] != 0) {
111 DBA::update('contact', ['readonly' => $ignored], ['id' => $cdata['user'], 'pending' => false]);
114 DBA::update('user-contact', ['ignored' => $ignored], ['cid' => $cdata['public'], 'uid' => $uid], true);
118 * Returns "ignore" state for contact id and user id
120 * @param int $cid Either public contact id or user's contact id
121 * @param int $uid User ID
123 * @return boolean is the contact id ignored for the given user?
126 public static function isIgnored($cid, $uid)
128 $cdata = Contact::getPublicAndUserContacID($cid, $uid);
133 $public_ignored = false;
135 if (!empty($cdata['public'])) {
136 $public_contact = DBA::selectFirst('user-contact', ['ignored'], ['cid' => $cdata['public'], 'uid' => $uid]);
137 if (DBA::isResult($public_contact)) {
138 $public_ignored = $public_contact['ignored'];
142 $user_ignored = $public_ignored;
144 if (!empty($cdata['user'])) {
145 $user_contact = DBA::selectFirst('contact', ['readonly'], ['id' => $cdata['user'], 'pending' => false]);
146 if (DBA::isResult($user_contact)) {
147 $user_ignored = $user_contact['readonly'];
151 if ($user_ignored != $public_ignored) {
152 DBA::update('user-contact', ['ignored' => $user_ignored], ['cid' => $cdata['public'], 'uid' => $uid], true);
155 return $user_ignored;
159 * Set "collapsed" for contact id and user id
161 * @param int $cid Either public contact id or user's contact id
162 * @param int $uid User ID
163 * @param boolean $collapsed are the contact's posts collapsed or uncollapsed?
166 public static function setCollapsed($cid, $uid, $collapsed)
168 $cdata = Contact::getPublicAndUserContacID($cid, $uid);
173 DBA::update('user-contact', ['collapsed' => $collapsed], ['cid' => $cdata['public'], 'uid' => $uid], true);
177 * Returns "collapsed" state for contact id and user id
179 * @param int $cid Either public contact id or user's contact id
180 * @param int $uid User ID
182 * @return boolean is the contact id blocked for the given user?
183 * @throws HTTPException\InternalServerErrorException
184 * @throws \ImagickException
186 public static function isCollapsed($cid, $uid)
188 $cdata = Contact::getPublicAndUserContacID($cid, $uid);
195 if (!empty($cdata['public'])) {
196 $public_contact = DBA::selectFirst('user-contact', ['collapsed'], ['cid' => $cdata['public'], 'uid' => $uid]);
197 if (DBA::isResult($public_contact)) {
198 $collapsed = $public_contact['collapsed'];