'nick' => $user['nickname'],
'pubkey' => $user['pubkey'],
'prvkey' => $user['prvkey'],
- 'photo' => User::getAvatarUrlForId($user['uid']),
- 'thumb' => User::getAvatarUrlForId($user['uid'], Proxy::SIZE_THUMB),
- 'micro' => User::getAvatarUrlForId($user['uid'], Proxy::SIZE_MICRO),
+ 'photo' => User::getAvatarUrl($user),
+ 'thumb' => User::getAvatarUrl($user, Proxy::SIZE_THUMB),
+ 'micro' => User::getAvatarUrl($user, Proxy::SIZE_MICRO),
'blocked' => 0,
'pending' => 0,
'url' => DI::baseUrl() . '/profile/' . $user['nickname'],
return false;
}
- $fields = ['nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey'];
+ $fields = ['uid', 'nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey'];
$user = DBA::selectFirst('user', $fields, ['uid' => $uid, 'account_expired' => false]);
if (!DBA::isResult($user)) {
return false;
$fields['micro'] = self::getDefaultAvatar($fields, Proxy::SIZE_MICRO);
}
- $fields['avatar'] = User::getAvatarUrlForId($uid);
+ $fields['avatar'] = User::getAvatarUrl($user);
$fields['forum'] = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
$fields['prv'] = $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP;
$fields['unsearchable'] = !$profile['net-publish'];
// Update the profile
$fields = [
- 'photo' => User::getAvatarUrlForId($uid),
- 'thumb' => User::getAvatarUrlForId($uid, Proxy::SIZE_THUMB)
+ 'photo' => User::getAvatarUrl($user),
+ 'thumb' => User::getAvatarUrl($user, Proxy::SIZE_THUMB)
];
DBA::update('profile', $fields, ['uid' => $uid]);
* Sends an unfriend message. Removes the contact for two-way unfriending or sharing only protocols (feed an mail)
*
* @param array $user User unfriending
- * @param array $contact Contact unfriended
+ * @param array $contact Contact (uid != 0) unfriended
* @param boolean $two_way Revoke eventual inbound follow as well
- * @return bool|null true if successful, false if not, null if no action was performed
+ * @return bool|null true if successful, false if not, null if no remote action was performed
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function terminateFriendship(array $user, array $contact, bool $two_way = false): bool
+ public static function terminateFriendship(array $user, array $contact): ?bool
{
- $result = Protocol::terminateFriendship($user, $contact, $two_way);
+ $result = Protocol::terminateFriendship($user, $contact);
- if ($two_way || in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
+ if ($contact['rel'] == Contact::SHARING || in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
self::remove($contact['id']);
} else {
self::update(['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
return $result;
}
+ /**
+ * Revoke follow privileges of the remote user contact
+ *
+ * @param array $contact Contact unfriended
+ * @return bool|null Whether the remote operation is successful or null if no remote operation was performed
+ * @throws HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ public static function revokeFollow(array $contact): ?bool
+ {
+ if (empty($contact['network'])) {
+ throw new \InvalidArgumentException('Empty network in contact array');
+ }
+
+ if (empty($contact['uid'])) {
+ throw new \InvalidArgumentException('Unexpected public contact record');
+ }
+
+ $result = Protocol::revokeFollow($contact);
+
+ // A null value here means the remote network doesn't support explicit follow revocation, we can still
+ // break the locally recorded relationship
+ if ($result !== false) {
+ if ($contact['rel'] == self::FRIEND) {
+ self::update(['rel' => self::SHARING], ['id' => $contact['id']]);
+ } else {
+ self::remove($contact['id']);
+ }
+ }
+
+ return $result;
+ }
+
+
/**
* Marks a contact for archival after a communication issue delay
*
$pm_url = '';
$status_link = '';
$photos_link = '';
- $contact_drop_link = '';
$poke_link = '';
if ($uid == 0) {
$posts_link = DI::baseUrl() . '/contact/' . $contact['id'] . '/conversations';
- if (!$contact['self']) {
- $contact_drop_link = DI::baseUrl() . '/contact/' . $contact['id'] . '/drop?confirm=1';
- }
-
$follow_link = '';
$unfollow_link = '';
- if (!$contact['self'] && in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
+ if (!$contact['self'] && Protocol::supportsFollow($contact['network'])) {
if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
$unfollow_link = 'unfollow?url=' . urlencode($contact['url']) . '&auto=1';
} elseif(!$contact['pending']) {
}
}
- if (!empty($follow_link) || !empty($unfollow_link)) {
- $contact_drop_link = '';
- }
-
/**
* Menu array:
* "name" => [ "Label", "link", (bool)Should the link opened in a new tab? ]
'photos' => [DI::l10n()->t('View Photos') , $photos_link , true],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
- 'drop' => [DI::l10n()->t('Drop Contact') , $contact_drop_link, false],
'pm' => [DI::l10n()->t('Send PM') , $pm_url , false],
'poke' => [DI::l10n()->t('Poke') , $poke_link , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true],
* Get avatar link for given contact id
*
* @param integer $cid contact id
- * @param string $size One of the ProxyUtils::SIZE_* constants
+ * @param string $size One of the Proxy::SIZE_* constants
* @param string $updated Contact update date
* @return string avatar link
*/
- public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = ''):string
+ public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''):string
{
// We have to fetch the "updated" variable when it wasn't provided
// The parameter can be provided to improve performance
- if (empty($updated)) {
- $contact = self::getById($cid, ['updated']);
- $updated = $contact['updated'] ?? '';
+ if (empty($updated) || empty($guid)) {
+ $account = DBA::selectFirst('account-user-view', ['updated', 'guid'], ['id' => $cid]);
+ $updated = $account['updated'] ?? '';
+ $guid = $account['guid'] ?? '';
}
+ $guid = urlencode($guid);
+
$url = DI::baseUrl() . '/photo/contact/';
switch ($size) {
case Proxy::SIZE_MICRO:
$url .= Proxy::PIXEL_LARGE . '/';
break;
}
- return $url . $cid . ($updated ? '?ts=' . strtotime($updated) : '');
+ return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : '');
}
/**
*
* @param string $url contact url
* @param integer $uid user id
- * @param string $size One of the ProxyUtils::SIZE_* constants
+ * @param string $size One of the Proxy::SIZE_* constants
* @return string avatar link
*/
public static function getAvatarUrlForUrl(string $url, int $uid, string $size = ''):string
* Get header link for given contact id
*
* @param integer $cid contact id
- * @param string $size One of the ProxyUtils::SIZE_* constants
+ * @param string $size One of the Proxy::SIZE_* constants
* @param string $updated Contact update date
* @return string header link
*/
- public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = ''):string
+ public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''):string
{
// We have to fetch the "updated" variable when it wasn't provided
// The parameter can be provided to improve performance
- if (empty($updated)) {
- $contact = self::getById($cid, ['updated']);
- $updated = $contact['updated'] ?? '';
+ if (empty($updated) || empty($guid)) {
+ $account = DBA::selectFirst('account-user-view', ['updated', 'guid'], ['id' => $cid]);
+ $updated = $account['updated'] ?? '';
+ $guid = $account['guid'] ?? '';
}
+ $guid = urlencode($guid);
+
$url = DI::baseUrl() . '/photo/header/';
switch ($size) {
case Proxy::SIZE_MICRO:
break;
}
- return $url . $cid . ($updated ? '?ts=' . strtotime($updated) : '');
+ return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : '');
}
/**
if (!empty($cids)) {
// Delete possibly existing cached user contact avatars
- Photo::delete(['uid' => $uids, 'contact-id' => $cids, 'album' => Photo::CONTACT_PHOTOS]);
+ Photo::delete(['uid' => $uids, 'contact-id' => $cids, 'photo-type' => Photo::CONTACT_AVATAR]);
}
}
}
$update = false;
- $guid = $ret['guid'] ?? '';
+ $guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST));
// make sure to not overwrite existing values with blank entries except some technical fields
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
self::updateAvatar($id, $ret['photo'], $update);
}
+ $uriid = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
+
if (!$update) {
self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => false, 'last-update' => $updated, 'success_update' => $updated]);
return true;
}
- if (empty($guid)) {
- $ret['uri-id'] = ItemURI::getIdByURI($ret['url']);
- } else {
- $ret['uri-id'] = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
- }
-
+ $ret['uri-id'] = $uriid;
$ret['nurl'] = Strings::normaliseLink($ret['url']);
$ret['updated'] = $updated;
$ret['failed'] = false;
// Ensure to always have the correct network type, independent from the connection request method
self::updateFromProbe($contact['id']);
- Post\UserNotification::insertNotication($contact['id'], Verb::getID(Activity::FOLLOW), $importer['uid']);
+ Post\UserNotification::insertNotification($contact['id'], Activity::FOLLOW, $importer['uid']);
return true;
} else {
self::updateAvatar($contact_id, $photo, true);
- Post\UserNotification::insertNotication($contact_id, Verb::getID(Activity::FOLLOW), $importer['uid']);
+ Post\UserNotification::insertNotification($contact_id, Activity::FOLLOW, $importer['uid']);
$contact_record = DBA::selectFirst('contact', ['id', 'network', 'name', 'url', 'photo'], ['id' => $contact_id]);
}
// check supported networks
+ $networks = [Protocol::DFRN, Protocol::ACTIVITYPUB];
if (DI::config()->get('system', 'diaspora_enabled')) {
- $diaspora = Protocol::DIASPORA;
- } else {
- $diaspora = Protocol::DFRN;
+ $networks[] = Protocol::DIASPORA;
}
if (!DI::config()->get('system', 'ostatus_disabled')) {
- $ostatus = Protocol::OSTATUS;
- } else {
- $ostatus = Protocol::DFRN;
+ $networks[] = Protocol::OSTATUS;
+ }
+
+ $condition = ['network' => $networks, 'failed' => false, 'deleted' => false, 'uid' => $uid];
+
+ if ($uid == 0) {
+ $condition['blocked'] = false;
}
// check if we search only communities or every contact
if ($mode === 'community') {
- $extra_sql = sprintf(' AND `contact-type` = %d', self::TYPE_COMMUNITY);
- } else {
- $extra_sql = '';
+ $condition['contact-type'] = self::TYPE_COMMUNITY;
}
$search .= '%';
- $results = DBA::p("SELECT * FROM `contact`
- WHERE (NOT `unsearchable` OR `nurl` IN (SELECT `nurl` FROM `owner-view` where `publish` OR `net-publish`))
- AND `network` IN (?, ?, ?, ?) AND
- NOT `failed` AND `uid` = ? AND
- (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?) $extra_sql
- ORDER BY `nurl` DESC LIMIT 1000",
- Protocol::DFRN, Protocol::ACTIVITYPUB, $ostatus, $diaspora, $uid, $search, $search, $search
- );
+ $condition = DBA::mergeConditions($condition,
+ ["(NOT `unsearchable` OR `nurl` IN (SELECT `nurl` FROM `owner-view` WHERE `publish` OR `net-publish`))
+ AND (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?)", $search, $search, $search]);
- $contacts = DBA::toArray($results);
+ $contacts = self::selectToArray([], $condition);
return $contacts;
}