It's better to ask the connectors for their profile data

This commit is contained in:
Michael Vogel 2016-01-29 03:02:15 +01:00
parent 8767ea5f52
commit e4c4b8e13e

View file

@ -638,9 +638,14 @@ function notification($params) {
* *
* @param int $itemid ID of the item for which the check should be done * @param int $itemid ID of the item for which the check should be done
* @param int $uid User ID * @param int $uid User ID
* @param str $profile (Optional) Can be used for connector post. Otherwise empty. * @param str $defaulttype (Optional) Forces a notification with this type.
*/ */
function check_item_notification($itemid, $uid, $profile = "", $defaulttype = "") { function check_item_notification($itemid, $uid, $defaulttype = "") {
$notification_data = array("uid" => $uid, "profiles" => array());
call_hooks('check_item_notification', $notification_data);
$profiles = $notification_data["profiles"];
$user = q("SELECT `notify-flags`, `language`, `username`, `email` FROM `user` WHERE `uid` = %d", intval($uid)); $user = q("SELECT `notify-flags`, `language`, `username`, `email` FROM `user` WHERE `uid` = %d", intval($uid));
if (!$user) if (!$user)
@ -649,22 +654,36 @@ function check_item_notification($itemid, $uid, $profile = "", $defaulttype = ""
$owner = q("SELECT `id`, `url` FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1", intval($uid)); $owner = q("SELECT `id`, `url` FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1", intval($uid));
if (!$owner) if (!$owner)
return false; return false;
$local_profile = $owner[0]["url"];
if ($profile == "") $profiles[] = $owner[0]["url"];
$profile = $local_profile;
$profile = normalise_link($profile); $profiles2 = array();
$profile_ssl = str_replace("http://", "https://", normalise_link($profile)); foreach ($profiles AS $profile) {
$profiles2[] = normalise_link($profile);
$profiles2[] = str_replace("http://", "https://", normalise_link($profile));
}
$profiles = $profiles2;
$profile_list = "";
foreach ($profiles AS $profile) {
if ($profile_list != "")
$profile_list .= "', '";
$profile_list .= dbesc($profile);
}
$profile_list = "'".$profile_list."'";
// Only act if it is a "real" post // Only act if it is a "real" post
// We need the additional check for the "local_profile" because of mixed situations on connector networks // We need the additional check for the "local_profile" because of mixed situations on connector networks
$item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-name`, `author-link`, `author-avatar`, `guid`, $item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-name`, `author-link`, `author-avatar`, `guid`,
`parent-uri`, `uri`, `contact-id` `parent-uri`, `uri`, `contact-id`
FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND
NOT (`author-link` IN ('%s', '%s', '%s')) LIMIT 1", NOT (`author-link` IN ($profile_list)) LIMIT 1",
intval($itemid), dbesc(ACTIVITY_POST), dbesc($profile), dbesc($profile_ssl), dbesc($local_profile)); intval($itemid), dbesc(ACTIVITY_POST));
if (!$item) if (!$item)
return false; return false;
@ -712,8 +731,14 @@ function check_item_notification($itemid, $uid, $profile = "", $defaulttype = ""
} }
// Is the user mentioned in this post? // Is the user mentioned in this post?
if ($item[0]["mention"] OR strpos($item[0]["tag"], "=".$profile."]") OR strpos($item[0]["tag"], "=".$profile_ssl."]") OR $tagged = false;
strpos($item[0]["tag"], "=".$local_profile."]") OR ($defaulttype == NOTIFY_TAGSELF)) {
foreach ($profiles AS $profile) {
if (strpos($item[0]["tag"], "=".$profile."]"))
$tagged = true;
}
if ($item[0]["mention"] OR $tagged OR ($defaulttype == NOTIFY_TAGSELF)) {
$params["type"] = NOTIFY_TAGSELF; $params["type"] = NOTIFY_TAGSELF;
$params["verb"] = ACTIVITY_TAG; $params["verb"] = ACTIVITY_TAG;
} }
@ -721,10 +746,10 @@ function check_item_notification($itemid, $uid, $profile = "", $defaulttype = ""
// Is it a post that the user had started or where he interacted? // Is it a post that the user had started or where he interacted?
$parent = q("SELECT `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`parent` = `thread`.`iid` $parent = q("SELECT `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`parent` = `thread`.`iid`
WHERE `thread`.`iid` = %d AND `thread`.`uid` = %d AND NOT `thread`.`ignored` AND WHERE `thread`.`iid` = %d AND `thread`.`uid` = %d AND NOT `thread`.`ignored` AND
(`thread`.`mention` OR `item`.`author-link` IN ('%s', '%s', '%s')) (`thread`.`mention` OR `item`.`author-link` IN ($profile_list))
LIMIT 1", LIMIT 1",
intval($item[0]["parent"]), intval($uid), intval($item[0]["parent"]), intval($uid));
dbesc($profile), dbesc($profile_ssl), dbesc($local_profile));
if ($parent AND !isset($params["type"])) { if ($parent AND !isset($params["type"])) {
$params["type"] = NOTIFY_COMMENT; $params["type"] = NOTIFY_COMMENT;
$params["verb"] = ACTIVITY_POST; $params["verb"] = ACTIVITY_POST;