Channel visibility rules can now be set for each contact

This commit is contained in:
Michael 2023-09-12 10:55:33 +00:00
parent c6c4d93b3b
commit 229e7dcee5
10 changed files with 308 additions and 112 deletions

View file

@ -37,6 +37,10 @@ use PDOException;
*/
class User
{
const VISIBILITY_DEFAULT = 0;
const VISIBILITY_NEVER = 1;
const VISIBILITY_ALWAYS = 2;
const VISIBILITY_REDUCED = 3;
/**
* Insert a user-contact for a given contact array
*
@ -314,6 +318,53 @@ class User
return $collapsed;
}
/**
* Set the channel visibility for contact id and user id
*
* @param int $cid Either public contact id or user's contact id
* @param int $uid User ID
* @param int $visibility Set type of visibility
* @return void
* @throws \Exception
*/
public static function setChannelVisibility(int $cid, int $uid, int $visibility)
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
return;
}
DBA::update('user-contact', ['channel-visibility' => $visibility], ['cid' => $cdata['public'], 'uid' => $uid], true);
}
/**
* Returns the channel visibility state for contact id and user id
*
* @param int $cid Either public contact id or user's contact id
* @param int $uid User ID
* @return int the type of visibility in channels
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function getChannelVisibility(int $cid, int $uid): int
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
return false;
}
$visibility = self::VISIBILITY_DEFAULT;
if (!empty($cdata['public'])) {
$public_contact = DBA::selectFirst('user-contact', ['channel-visibility'], ['cid' => $cdata['public'], 'uid' => $uid]);
if (DBA::isResult($public_contact)) {
$visibility = $public_contact['channel-visibility'] ?? self::VISIBILITY_DEFAULT;
}
}
return $visibility;
}
/**
* Set/Release that the user is blocked by the contact
*