First testable version
This commit is contained in:
parent
4bfd0abec7
commit
3a1798d1c3
1 changed files with 73 additions and 11 deletions
|
@ -6,7 +6,10 @@
|
|||
|
||||
namespace Friendica\Model;
|
||||
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class UserItem
|
||||
{
|
||||
|
@ -18,6 +21,66 @@ class UserItem
|
|||
*/
|
||||
public static function setNotification($item, $uid)
|
||||
{
|
||||
if (self::checkShared($item, $uid)) {
|
||||
echo "shared\n";
|
||||
}
|
||||
|
||||
$profiles = self::getProfileForUser($uid);
|
||||
|
||||
if (self::checkTagged($item, $uid, $profiles)) {
|
||||
echo "tagged\n";
|
||||
}
|
||||
|
||||
if (self::checkCommented($item, $uid, $profiles)) {
|
||||
echo "commented\n";
|
||||
}
|
||||
}
|
||||
|
||||
private static function getProfileForUser($uid)
|
||||
{
|
||||
$notification_data = ["uid" => $uid, "profiles" => []];
|
||||
Hook::callAll('check_item_notification', $notification_data);
|
||||
|
||||
$profiles = $notification_data["profiles"];
|
||||
|
||||
$fields = ['nickname'];
|
||||
$user = DBA::selectFirst('user', $fields, ['uid' => $uid]);
|
||||
if (!DBA::isResult($user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$owner = DBA::selectFirst('contact', ['url'], ['self' => true, 'uid' => $uid]);
|
||||
if (!DBA::isResult($owner)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// This is our regular URL format
|
||||
$profiles[] = $owner["url"];
|
||||
|
||||
// Notifications from Diaspora are often with an URL in the Diaspora format
|
||||
$profiles[] = DI::baseUrl()."/u/".$user["nickname"];
|
||||
|
||||
$profiles2 = [];
|
||||
|
||||
foreach ($profiles AS $profile) {
|
||||
// Check for invalid profile urls. 13 should be the shortest possible profile length:
|
||||
// http://a.bc/d
|
||||
// Additionally check for invalid urls that would return the normalised value "http:"
|
||||
if ((strlen($profile) >= 13) && (Strings::normaliseLink($profile) != "http:")) {
|
||||
if (!in_array($profile, $profiles2))
|
||||
$profiles2[] = $profile;
|
||||
|
||||
$profile = Strings::normaliseLink($profile);
|
||||
if (!in_array($profile, $profiles2))
|
||||
$profiles2[] = $profile;
|
||||
|
||||
$profile = str_replace("http://", "https://", $profile);
|
||||
if (!in_array($profile, $profiles2))
|
||||
$profiles2[] = $profile;
|
||||
}
|
||||
}
|
||||
|
||||
return $profiles2;
|
||||
}
|
||||
|
||||
private static function checkShared($item, $uid)
|
||||
|
@ -45,34 +108,33 @@ class UserItem
|
|||
}
|
||||
|
||||
// Is the user mentioned in this post?
|
||||
private static function checkTagged($item, $uid)
|
||||
private static function checkTagged($item, $uid, $profiles)
|
||||
{
|
||||
if ($item["mention"]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($profiles AS $profile) {
|
||||
if (strpos($item["tag"], "=".$profile."]") || strpos($item["body"], "=".$profile."]"))
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($defaulttype == NOTIFY_TAGSELF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function checkCommented($item, $uid)
|
||||
// Fetch all contacts for the given profiles
|
||||
private static function checkCommented($item, $uid, $profiles)
|
||||
{
|
||||
// Is it a post that the user had started?
|
||||
$fields = ['ignored', 'mention'];
|
||||
$thread = Item::selectFirstThreadForUser($uid, $fields, ['iid' => $item["parent"], 'deleted' => false]);
|
||||
|
||||
if ($thread['mention'] && !$thread['ignored']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$contacts = [];
|
||||
$ret = DBA::select('contact', ['id'], ['uid' => 0, 'nurl' => $profiles]);
|
||||
while ($contact = DBA::fetch($ret)) {
|
||||
$contacts[] = $contact['id'];
|
||||
}
|
||||
DBA::close($ret);
|
||||
|
||||
// And now we check for participation of one of our contacts in the thread
|
||||
$condition = ['parent' => $item["parent"], 'author-id' => $contacts, 'deleted' => false];
|
||||
|
||||
|
|
Loading…
Reference in a new issue