<?php
-
/**
- * @file src/Model/UserItem.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
*/
namespace Friendica\Model;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\Strings;
+use Friendica\Model\Tag;
class UserItem
{
*/
public static function setNotification(int $iid)
{
- $fields = ['id', 'uid', 'body', 'parent', 'gravity', 'tag', 'contact-id', 'thr-parent', 'parent-uri', 'author-id'];
+ $fields = ['id', 'uri-id', 'uid', 'body', 'parent', 'gravity', 'tag', 'contact-id', 'thr-parent', 'parent-uri', 'author-id'];
$item = Item::selectFirst($fields, ['id' => $iid, 'origin' => false]);
if (!DBA::isResult($item)) {
return;
}
// Or the contact is a mentioned forum
- $tags = DBA::select('term', ['url'], ['otype' => TERM_OBJ_POST, 'oid' => $item['id'], 'type' => TERM_MENTION, 'uid' => $uid]);
+ $tags = DBA::select('tag-view', ['url'], ['uri-id' => $item['uri-id'], 'type' => [Tag::MENTION, Tag::EXCLUSIVE_MENTION]]);
while ($tag = DBA::fetch($tags)) {
$condition = ['nurl' => Strings::normaliseLink($tag['url']), 'uid' => $uid, 'notify_new_posts' => true, 'contact-type' => Contact::TYPE_COMMUNITY];
if (DBA::exists('contact', $condition)) {
return true;
}
}
+ DBA::close($tags);
return false;
}
*/
private static function checkImplicitMention(array $item, array $profiles)
{
- foreach ($profiles AS $profile) {
- if (strpos($item['tag'], '=' . $profile.']') || strpos($item['body'], '=' . $profile . ']')) {
- if (strpos($item['body'], $profile) === false) {
+ $mentions = Tag::getByURIId($item['uri-id'], [Tag::IMPLICIT_MENTION]);
+ foreach ($mentions as $mention) {
+ foreach ($profiles as $profile) {
+ if (Strings::compareLink($profile, $mention['url'])) {
return true;
}
}
*/
private static function checkExplicitMention(array $item, array $profiles)
{
- foreach ($profiles AS $profile) {
- if (strpos($item['tag'], '=' . $profile.']') || strpos($item['body'], '=' . $profile . ']')) {
- if (!(strpos($item['body'], $profile) === false)) {
+ $mentions = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::EXCLUSIVE_MENTION]);
+ foreach ($mentions as $mention) {
+ foreach ($profiles as $profile) {
+ if (Strings::compareLink($profile, $mention['url'])) {
return true;
}
}