]> git.mxchange.org Git - friendica.git/blob - src/Model/UserItem.php
26c42f10931caffb38da7f95584d7ba7f0c98d1e
[friendica.git] / src / Model / UserItem.php
1 <?php
2
3 /**
4  * @file src/Model/UserItem.php
5  */
6
7 namespace Friendica\Model;
8
9 use Friendica\Database\DBA;
10
11 class UserItem
12 {
13         /**
14          * Checks an item for notifications and sets the "notification-type" field
15          *
16          * @param array $item The message array that is checked for notifications
17          * @param int   $uid  User ID
18          */
19         public static function setNotification($item, $uid)
20         {
21         }
22
23         private static function checkShared($item, $uid)
24         {
25                 if ($item['gravity'] != GRAVITY_PARENT) {
26                         return false;
27                 }
28
29                 // Send a notification for every new post?
30                 // Either the contact had posted something directly
31                 if (DBA::exists('contact', ['id' => $item['contact-id'], 'notify_new_posts' => true])) {
32                         return true;
33                 }
34
35                 // Or the contact is a mentioned forum
36                 $tags = DBA::select('term', ['url'], ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => TERM_MENTION, 'uid' => $uid]);
37                 while ($tag = DBA::fetch($tags)) {
38                         $condition = ['nurl' => Strings::normaliseLink($tag["url"]), 'uid' => $uid, 'notify_new_posts' => true, 'contact-type' => Contact::TYPE_COMMUNITY];
39                         if (DBA::exists('contact', $condition)) {
40                                 return true;
41                         }
42                 }
43
44                 return false;
45         }
46
47         // Is the user mentioned in this post?
48         private static function checkTagged($item, $uid)
49         {
50                 if ($item["mention"]) {
51                         return true;
52                 }
53
54                 foreach ($profiles AS $profile) {
55                         if (strpos($item["tag"], "=".$profile."]") || strpos($item["body"], "=".$profile."]"))
56                                 return true;
57                 }
58
59                 if ($defaulttype == NOTIFY_TAGSELF) {
60                         return true;
61                 }
62
63                 return false;
64         }
65
66         private static function checkCommented($item, $uid)
67         {
68                 // Is it a post that the user had started?
69                 $fields = ['ignored', 'mention'];
70                 $thread = Item::selectFirstThreadForUser($uid, $fields, ['iid' => $item["parent"], 'deleted' => false]);
71
72                 if ($thread['mention'] && !$thread['ignored']) {
73                         return true;
74                 }
75
76                 // And now we check for participation of one of our contacts in the thread
77                 $condition = ['parent' => $item["parent"], 'author-id' => $contacts, 'deleted' => false];
78
79                 if (!$thread['ignored'] && Item::exists($condition)) {
80                         return true;
81                 }
82
83                 return false;
84         }
85 }