From 533f07e87422466b45242a583fa93313fbbdc44c Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sun, 15 Dec 2019 13:14:55 +0000
Subject: [PATCH] Issue 6867: Only display direct mentions in the corresponding
 API endpoint

---
 database.sql                  | 3 ++-
 include/api.php               | 4 ++--
 static/dbstructure.config.php | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/database.sql b/database.sql
index 13e7e34cff..cbb724d189 100644
--- a/database.sql
+++ b/database.sql
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2019.12-rc (Dalmatian Bellflower)
--- DB_UPDATE_VERSION 1325
+-- DB_UPDATE_VERSION 1326
 -- ------------------------------------------
 
 
@@ -637,6 +637,7 @@ CREATE TABLE IF NOT EXISTS `item` (
 	 INDEX `resource-id` (`resource-id`),
 	 INDEX `deleted_changed` (`deleted`,`changed`),
 	 INDEX `uid_wall_changed` (`uid`,`wall`,`changed`),
+	 INDEX `mention_uid_id` (`mention`,`uid`,`id`),
 	 INDEX `uid_eventid` (`uid`,`event-id`),
 	 INDEX `icid` (`icid`),
 	 INDEX `iaid` (`iaid`),
diff --git a/include/api.php b/include/api.php
index b1030335d6..a32efa37e4 100644
--- a/include/api.php
+++ b/include/api.php
@@ -2165,8 +2165,8 @@ function api_statuses_mentions($type)
 
 	$start = max(0, ($page - 1) * $count);
 
-	$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `author-id` != ?
-		AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `thread`.`uid` = ? AND `thread`.`mention` AND NOT `thread`.`ignored`)",
+	$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `author-id` != ? AND `mention`
+		AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `thread`.`uid` = ? AND NOT `thread`.`ignored`)",
 		api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $user_info['pid'], api_user()];
 
 	if ($max_id > 0) {
diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php
index 5b02ab1df3..078d7c1177 100755
--- a/static/dbstructure.config.php
+++ b/static/dbstructure.config.php
@@ -34,7 +34,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-	define('DB_UPDATE_VERSION', 1325);
+	define('DB_UPDATE_VERSION', 1326);
 }
 
 return [
@@ -705,6 +705,7 @@ return [
 			"resource-id" => ["resource-id"],
 			"deleted_changed" => ["deleted", "changed"],
 			"uid_wall_changed" => ["uid", "wall", "changed"],
+			"mention_uid_id" => ["mention", "uid", "id"],
 			"uid_eventid" => ["uid", "event-id"],
 			"icid" => ["icid"],
 			"iaid" => ["iaid"],