Merge remote-tracking branch 'friendica/stable' into develop

# Conflicts:
#	composer.lock
This commit is contained in:
Hypolite Petovan 2020-09-20 15:32:58 -04:00
commit a852455d0e
154 changed files with 26577 additions and 25630 deletions

View file

@ -320,13 +320,18 @@ class APContact
$apcontact['updated'] = DateTimeFormat::utcNow();
DBA::update('apcontact', $apcontact, ['url' => $url], true);
// We delete the old entry when the URL is changed
if (($url != $apcontact['url']) && DBA::exists('apcontact', ['url' => $url]) && DBA::exists('apcontact', ['url' => $apcontact['url']])) {
if ($url != $apcontact['url']) {
Logger::info('Delete changed profile url', ['old' => $url, 'new' => $apcontact['url']]);
DBA::delete('apcontact', ['url' => $url]);
}
if (DBA::exists('apcontact', ['url' => $apcontact['url']])) {
DBA::update('apcontact', $apcontact, ['url' => $apcontact['url']]);
} else {
DBA::replace('apcontact', $apcontact);
}
Logger::info('Updated profile', ['url' => $url]);
return $apcontact;

View file

@ -1909,7 +1909,7 @@ class Contact
$ret['pubkey'] = $new_pubkey;
}
if (($ret['addr'] != $contact['addr']) || (!empty($ret['alias']) && ($ret['alias'] != $contact['alias']))) {
if ((!empty($ret['addr']) && ($ret['addr'] != $contact['addr'])) || (!empty($ret['alias']) && ($ret['alias'] != $contact['alias']))) {
$ret['uri-date'] = DateTimeFormat::utcNow();
}

View file

@ -58,6 +58,15 @@ class Item
const PT_DOCUMENT = 19;
const PT_EVENT = 32;
const PT_TAG = 64;
const PT_TO = 65;
const PT_CC = 66;
const PT_BTO = 67;
const PT_BCC = 68;
const PT_FOLLOWER = 69;
const PT_ANNOUNCEMENT = 70;
const PT_COMMENT = 71;
const PT_STORED = 72;
const PT_GLOBAL = 73;
const PT_PERSONAL_NOTE = 128;
// Field list that is used to display the items
@ -202,19 +211,7 @@ class Item
return [];
}
if (empty($condition) || !is_array($condition)) {
$condition = ['iid' => $pinned];
} else {
reset($condition);
$first_key = key($condition);
if (!is_int($first_key)) {
$condition['iid'] = $pinned;
} else {
$values_string = substr(str_repeat("?, ", count($pinned)), 0, -2);
$condition[0] = '(' . $condition[0] . ") AND `iid` IN (" . $values_string . ")";
$condition = array_merge($condition, $pinned);
}
}
$condition = DBA::mergeConditions(['iid' => $pinned], $condition);
return self::selectThreadForUser($uid, $selected, $condition, $params);
}
@ -1704,6 +1701,11 @@ class Item
'photo' => $item['owner-avatar'], 'network' => $item['network']];
$item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default);
$actor = ($item['gravity'] == GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
if (!$item['origin'] && in_array($item['post-type'], [self::PT_ARTICLE, self::PT_COMMENT, self::PT_GLOBAL]) && Contact::isSharing($actor, $item['uid'])) {
$item['post-type'] = self::PT_FOLLOWER;
}
// Ensure that there is an avatar cache
Contact::checkAvatarCache($item['author-id']);
Contact::checkAvatarCache($item['owner-id']);
@ -2006,10 +2008,10 @@ class Item
*/
private static function setOwnerforResharedItem(array $item)
{
$parent = self::selectFirst(['id', 'owner-id', 'author-id', 'author-link', 'origin'],
['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]);
$parent = self::selectFirst(['id', 'owner-id', 'author-id', 'author-link', 'origin', 'post-type'],
['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
if (!DBA::isResult($parent)) {
Logger::error('Parent not found', ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]);
Logger::error('Parent not found', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
return;
}
@ -2019,19 +2021,24 @@ class Item
return;
}
if ($author['contact-type'] != Contact::TYPE_COMMUNITY) {
logger::info('The resharer is no forum: quit', ['resharer' => $item['author-id'], 'owner' => $parent['owner-id'], 'author' => $parent['author-id'], 'uid' => $item['uid']]);
return;
}
$cid = Contact::getIdForURL($author['url'], $item['uid']);
if (empty($cid) || !Contact::isSharing($cid, $item['uid'])) {
logger::info('The resharer is not a following contact: quit', ['resharer' => $author['url'], 'uid' => $item['uid']]);
Logger::info('The resharer is not a following contact: quit', ['resharer' => $author['url'], 'uid' => $item['uid']]);
return;
}
Item::update(['owner-id' => $item['author-id'], 'contact-id' => $cid], ['id' => $parent['id']]);
Logger::info('Change owner of the parent', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid'], 'owner-id' => $item['author-id'], 'contact-id' => $cid]);
if ($author['contact-type'] != Contact::TYPE_COMMUNITY) {
if (!in_array($parent['post-type'], [self::PT_ARTICLE, self::PT_COMMENT]) || Contact::isSharing($parent['owner-id'], $item['uid'])) {
Logger::info('The resharer is no forum: quit', ['resharer' => $item['author-id'], 'owner' => $parent['owner-id'], 'author' => $parent['author-id'], 'uid' => $item['uid']]);
return;
}
self::update(['post-type' => self::PT_ANNOUNCEMENT], ['id' => $parent['id']]);
Logger::info('Set announcement post-type', ['uri-id' => $item['uri-id'], 'thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
return;
}
self::update(['owner-id' => $item['author-id'], 'contact-id' => $cid], ['id' => $parent['id']]);
Logger::info('Change owner of the parent', ['uri-id' => $item['uri-id'], 'thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid'], 'owner-id' => $item['author-id'], 'contact-id' => $cid]);
}
/**
@ -2237,6 +2244,8 @@ class Item
return 0;
}
$item['post-type'] = self::PT_STORED;
$item = array_merge($item, $fields);
$stored = self::storeForUser($item, $uid);

View file

@ -24,10 +24,39 @@ namespace Friendica\Model;
use Friendica\Content\Text;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;
use Friendica\DI;
class ItemContent
{
public static function getURIIdListBySearch(string $search, int $uid = 0, int $start = 0, int $limit = 100)
{
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE))
AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid];
$params = [
'order' => ['uri-id' => true],
'group_by' => ['uri-id'],
'limit' => [$start, $limit]
];
$tags = DBA::select('item', ['uri-id'], $condition, $params);
$uriids = [];
while ($tag = DBA::fetch($tags)) {
$uriids[] = $tag['uri-id'];
}
DBA::close($tags);
return $uriids;
}
public static function countBySearch(string $search, int $uid = 0)
{
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE))
AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid];
return DBA::count('item', $condition);
}
/**
* Convert a message into plaintext for connectors to other networks
*

View file

@ -129,9 +129,12 @@ class Mail
}
$me = DBA::selectFirst('contact', [], ['uid' => local_user(), 'self' => true]);
$contact = DBA::selectFirst('contact', [], ['id' => $recipient, 'uid' => local_user()]);
if (!DBA::isResult($me)) {
return -2;
}
if (!(count($me) && (count($contact)))) {
$contact = DBA::selectFirst('contact', [], ['id' => $recipient, 'uid' => local_user()]);
if (!DBA::isResult($contact)) {
return -2;
}

View file

@ -304,7 +304,7 @@ class Profile
$profile_is_dfrn = $profile['network'] == Protocol::DFRN;
$profile_is_native = in_array($profile['network'], Protocol::NATIVE_SUPPORT);
$local_user_is_self = local_user() && local_user() == ($profile['uid'] ?? 0);
$local_user_is_self = $profile['self'] ?? false;
$visitor_is_authenticated = (bool)self::getMyURL();
$visitor_is_following =
in_array($visitor_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND])
@ -354,13 +354,7 @@ class Profile
// Fetch the account type
$account_type = Contact::getAccountType($profile);
if (!empty($profile['address'])
|| !empty($profile['location'])
|| !empty($profile['locality'])
|| !empty($profile['region'])
|| !empty($profile['postal-code'])
|| !empty($profile['country-name'])
) {
if (!empty($profile['address']) || !empty($profile['location'])) {
$location = DI::l10n()->t('Location:');
}
@ -427,10 +421,6 @@ class Profile
$p['about'] = BBCode::convert($p['about']);
}
if (empty($p['address']) && !empty($p['location'])) {
$p['address'] = $p['location'];
}
if (isset($p['address'])) {
$p['address'] = BBCode::convert($p['address']);
}

View file

@ -440,6 +440,21 @@ class Tag
return $return;
}
/**
* Counts posts for given tag
*
* @param string $search
* @param integer $uid
* @return integer number of posts
*/
public static function countByTag(string $search, int $uid = 0)
{
$condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid];
$params = ['group_by' => ['uri-id']];
return DBA::count('tag-search-view', $condition, $params);
}
/**
* Search posts for given tag
*

View file

@ -51,8 +51,8 @@ class UserItem
*/
public static function setNotification(int $iid)
{
$fields = ['id', 'uri-id', 'uid', 'body', 'parent', 'gravity', 'tag',
'contact-id', 'thr-parent', 'parent-uri', 'author-id', 'verb'];
$fields = ['id', 'uri-id', 'parent-uri-id', 'uid', 'body', 'parent', 'gravity', 'tag',
'private', 'contact-id', 'thr-parent', 'parent-uri', 'author-id', 'verb'];
$item = Item::selectFirst($fields, ['id' => $iid, 'origin' => false]);
if (!DBA::isResult($item)) {
return;
@ -63,14 +63,26 @@ class UserItem
return;
}
// fetch all users in the thread
if ($item['uid'] == 0) {
$uids = [];
} else {
// Always include the item user
$uids = [$item['uid']];
}
// Add every user who participated so far in this thread
// This can only happen with participations on global items. (means: uid = 0)
$users = DBA::p("SELECT DISTINCT(`contact`.`uid`) FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` != 0
WHERE `parent` IN (SELECT `parent` FROM `item` WHERE `id`=?)", $iid);
while ($user = DBA::fetch($users)) {
self::setNotificationForUser($item, $user['uid']);
$uids[] = $user['uid'];
}
DBA::close($users);
foreach (array_unique($uids) as $uid) {
self::setNotificationForUser($item, $uid);
}
}
/**