]> git.mxchange.org Git - friendica.git/blob - src/Worker/Notifier.php
Merge pull request #6209 from MrPetovan/task/move-config-to-php-array
[friendica.git] / src / Worker / Notifier.php
1 <?php
2 /**
3  * @file src/Worker/Notifier.php
4  */
5 namespace Friendica\Worker;
6
7 use Friendica\BaseObject;
8 use Friendica\Core\Addon;
9 use Friendica\Core\Config;
10 use Friendica\Core\Hook;
11 use Friendica\Core\Logger;
12 use Friendica\Core\Protocol;
13 use Friendica\Core\Worker;
14 use Friendica\Database\DBA;
15 use Friendica\Model\Contact;
16 use Friendica\Model\Conversation;
17 use Friendica\Model\Group;
18 use Friendica\Model\Item;
19 use Friendica\Model\PushSubscriber;
20 use Friendica\Model\User;
21 use Friendica\Network\Probe;
22 use Friendica\Protocol\ActivityPub;
23 use Friendica\Protocol\Diaspora;
24 use Friendica\Protocol\OStatus;
25 use Friendica\Protocol\Salmon;
26
27 /*
28  * The notifier is typically called with:
29  *
30  *              Worker::add(PRIORITY_HIGH, "Notifier", COMMAND, ITEM_ID);
31  *
32  * where COMMAND is one of the following:
33  *
34  *              activity                                (in diaspora.php, dfrn_confirm.php, profiles.php)
35  *              comment-import                  (in diaspora.php, items.php)
36  *              comment-new                             (in item.php)
37  *              drop                                    (in diaspora.php, items.php, photos.php)
38  *              edit_post                               (in item.php)
39  *              event                                   (in events.php)
40  *              like                                    (in like.php, poke.php)
41  *              mail                                    (in message.php)
42  *              suggest                                 (in fsuggest.php)
43  *              tag                                             (in photos.php, poke.php, tagger.php)
44  *              tgroup                                  (in items.php)
45  *              wall-new                                (in photos.php, item.php)
46  *              removeme                                (in Contact.php)
47  *              relocate                                (in uimport.php)
48  *
49  * and ITEM_ID is the id of the item in the database that needs to be sent to others.
50  */
51
52 class Notifier
53 {
54         public static function execute($cmd, $item_id)
55         {
56                 $a = BaseObject::getApp();
57
58                 Logger::log('Invoked: ' . $cmd . ': ' . $item_id, Logger::DEBUG);
59
60                 $top_level = false;
61                 $recipients = [];
62                 $url_recipients = [];
63
64                 $normal_mode = true;
65                 $recipients_relocate = [];
66
67                 if ($cmd == Delivery::MAIL) {
68                         $normal_mode = false;
69                         $message = DBA::selectFirst('mail', ['uid', 'contact-id'], ['id' => $item_id]);
70                         if (!DBA::isResult($message)) {
71                                 return;
72                         }
73                         $uid = $message['uid'];
74                         $recipients[] = $message['contact-id'];
75                 } elseif ($cmd == Delivery::SUGGESTION) {
76                         $normal_mode = false;
77                         $suggest = DBA::selectFirst('fsuggest', ['uid', 'cid'], ['id' => $item_id]);
78                         if (!DBA::isResult($suggest)) {
79                                 return;
80                         }
81                         $uid = $suggest['uid'];
82                         $recipients[] = $suggest['cid'];
83                 } elseif ($cmd == Delivery::REMOVAL) {
84                         $r = q("SELECT `contact`.*, `user`.`prvkey` AS `uprvkey`,
85                                         `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
86                                         `user`.`page-flags`, `user`.`prvnets`, `user`.`account-type`, `user`.`guid`
87                                 FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
88                                         WHERE `contact`.`uid` = %d AND `contact`.`self` LIMIT 1",
89                                         intval($item_id));
90                         if (!$r) {
91                                 return;
92                         }
93                         $user = $r[0];
94
95                         $r = q("SELECT * FROM `contact` WHERE NOT `self` AND `uid` = %d", intval($item_id));
96                         if (!$r) {
97                                 return;
98                         }
99                         foreach ($r as $contact) {
100                                 Contact::terminateFriendship($user, $contact, true);
101                         }
102
103                         $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0);
104                         foreach ($inboxes as $inbox) {
105                                 Logger::log('Account removal for user ' . $item_id . ' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
106                                 Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $a->queue['created'], 'dont_fork' => true],
107                                         'APDelivery', Delivery::REMOVAL, '', $inbox, $item_id);
108                         }
109
110                         return;
111                 } elseif ($cmd == Delivery::RELOCATION) {
112                         $normal_mode = false;
113                         $uid = $item_id;
114
115                         $recipients_relocate = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND `network` IN ('%s', '%s')",
116                                                 intval($uid), Protocol::DFRN, Protocol::DIASPORA);
117                 } else {
118                         // find ancestors
119                         $condition = ['id' => $item_id, 'visible' => true, 'moderated' => false];
120                         $target_item = Item::selectFirst([], $condition);
121
122                         if (!DBA::isResult($target_item) || !intval($target_item['parent'])) {
123                                 return;
124                         }
125
126                         $parent_id = intval($target_item['parent']);
127                         $uid = $target_item['contact-uid'];
128                         $updated = $target_item['edited'];
129
130                         $condition = ['parent' => $parent_id, 'visible' => true, 'moderated' => false];
131                         $params = ['order' => ['id']];
132                         $ret = Item::select([], $condition, $params);
133
134                         if (!DBA::isResult($ret)) {
135                                 return;
136                         }
137
138                         $items = Item::inArray($ret);
139
140                         // avoid race condition with deleting entries
141                         if ($items[0]['deleted']) {
142                                 foreach ($items as $item) {
143                                         $item['deleted'] = 1;
144                                 }
145                         }
146
147                         if ((count($items) == 1) && ($items[0]['id'] === $target_item['id']) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
148                                 Logger::log('Top level post');
149                                 $top_level = true;
150                         }
151                 }
152
153                 $owner = User::getOwnerDataById($uid);
154                 if (!$owner) {
155                         return;
156                 }
157
158                 $walltowall = ($top_level && ($owner['id'] != $items[0]['contact-id']) ? true : false);
159
160                 // Should the post be transmitted to Diaspora?
161                 $diaspora_delivery = true;
162
163                 // If this is a public conversation, notify the feed hub
164                 $public_message = true;
165
166                 // Do a PuSH
167                 $push_notify = false;
168
169                 // Deliver directly to a forum, don't PuSH
170                 $direct_forum_delivery = false;
171
172                 $followup = false;
173                 $recipients_followup = [];
174
175                 if (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::RELOCATION])) {
176                         $parent = $items[0];
177
178                         self::activityPubDelivery($a, $cmd, $item_id, $uid, $target_item, $parent);
179
180                         $fields = ['network', 'author-id', 'owner-id'];
181                         $condition = ['uri' => $target_item["thr-parent"], 'uid' => $target_item["uid"]];
182                         $thr_parent = Item::selectFirst($fields, $condition);
183
184                         Logger::log('GUID: ' . $target_item["guid"] . ': Parent is ' . $parent['network'] . '. Thread parent is ' . $thr_parent['network'], Logger::DEBUG);
185
186                         // This is IMPORTANT!!!!
187
188                         // We will only send a "notify owner to relay" or followup message if the referenced post
189                         // originated on our system by virtue of having our hostname somewhere
190                         // in the URI, AND it was a comment (not top_level) AND the parent originated elsewhere.
191
192                         // if $parent['wall'] == 1 we will already have the parent message in our array
193                         // and we will relay the whole lot.
194
195                         $localhost = str_replace('www.','',$a->getHostName());
196                         if (strpos($localhost,':')) {
197                                 $localhost = substr($localhost,0,strpos($localhost,':'));
198                         }
199                         /**
200                          *
201                          * Be VERY CAREFUL if you make any changes to the following several lines. Seemingly innocuous changes
202                          * have been known to cause runaway conditions which affected several servers, along with
203                          * permissions issues.
204                          *
205                          */
206
207                         $relay_to_owner = false;
208
209                         if (!$top_level && ($parent['wall'] == 0) && (stristr($target_item['uri'],$localhost))) {
210                                 $relay_to_owner = true;
211                         }
212
213
214                         if (($cmd === 'uplink') && (intval($parent['forum_mode']) == 1) && !$top_level) {
215                                 $relay_to_owner = true;
216                         }
217
218                         // until the 'origin' flag has been in use for several months
219                         // we will just use it as a fallback test
220                         // later we will be able to use it as the primary test of whether or not to relay.
221
222                         if (!$target_item['origin']) {
223                                 $relay_to_owner = false;
224                         }
225                         if ($parent['origin']) {
226                                 $relay_to_owner = false;
227                         }
228
229                         // Special treatment for forum posts
230                         if (self::isForumPost($target_item, $owner)) {
231                                 $relay_to_owner = true;
232                                 $direct_forum_delivery = true;
233                         }
234
235                         // Avoid that comments in a forum thread are sent to OStatus
236                         if (self::isForumPost($parent, $owner)) {
237                                 $direct_forum_delivery = true;
238                         }
239
240                         if ($relay_to_owner) {
241                                 // local followup to remote post
242                                 $followup = true;
243                                 $public_message = false; // not public
244                                 $recipients = [$parent['contact-id']];
245                                 $recipients_followup  = [$parent['contact-id']];
246
247                                 Logger::log('Followup ' . $target_item['guid'] . ' to ' . $parent['contact-id'], Logger::DEBUG);
248
249                                 //if (!$target_item['private'] && $target_item['wall'] &&
250                                 if (!$target_item['private'] &&
251                                         (strlen($target_item['allow_cid'].$target_item['allow_gid'].
252                                                 $target_item['deny_cid'].$target_item['deny_gid']) == 0))
253                                         $push_notify = true;
254
255                                 if (($thr_parent && ($thr_parent['network'] == Protocol::OSTATUS)) || ($parent['network'] == Protocol::OSTATUS)) {
256                                         $push_notify = true;
257
258                                         if ($parent["network"] == Protocol::OSTATUS) {
259                                                 // Distribute the message to the DFRN contacts as if this wasn't a followup since OStatus can't relay comments
260                                                 // Currently it is work at progress
261                                                 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s' AND NOT `blocked` AND NOT `pending` AND NOT `archive`",
262                                                         intval($uid),
263                                                         DBA::escape(Protocol::DFRN)
264                                                 );
265                                                 if (DBA::isResult($r)) {
266                                                         foreach ($r as $rr) {
267                                                                 $recipients_followup[] = $rr['id'];
268                                                         }
269                                                 }
270                                         }
271                                 }
272
273                                 if ($direct_forum_delivery) {
274                                         $push_notify = false;
275                                 }
276
277                                 Logger::log('Notify ' . $target_item["guid"] .' via PuSH: ' . ($push_notify ? "Yes":"No"), Logger::DEBUG);
278                         } else {
279                                 $followup = false;
280
281                                 Logger::log('Distributing directly ' . $target_item["guid"], Logger::DEBUG);
282
283                                 // don't send deletions onward for other people's stuff
284
285                                 if ($target_item['deleted'] && !intval($target_item['wall'])) {
286                                         Logger::log('Ignoring delete notification for non-wall item');
287                                         return;
288                                 }
289
290                                 if (strlen($parent['allow_cid'])
291                                         || strlen($parent['allow_gid'])
292                                         || strlen($parent['deny_cid'])
293                                         || strlen($parent['deny_gid'])) {
294                                         $public_message = false; // private recipients, not public
295                                 }
296
297                                 $allow_people = expand_acl($parent['allow_cid']);
298                                 $allow_groups = Group::expand(expand_acl($parent['allow_gid']),true);
299                                 $deny_people  = expand_acl($parent['deny_cid']);
300                                 $deny_groups  = Group::expand(expand_acl($parent['deny_gid']));
301
302                                 // if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
303                                 // a delivery fork. private groups (forum_mode == 2) do not uplink
304
305                                 if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== 'uplink')) {
306                                         Worker::add($a->queue['priority'], 'Notifier', 'uplink', $item_id);
307                                 }
308
309                                 foreach ($items as $item) {
310                                         $recipients[] = $item['contact-id'];
311                                         // pull out additional tagged people to notify (if public message)
312                                         if ($public_message && strlen($item['inform'])) {
313                                                 $people = explode(',',$item['inform']);
314                                                 foreach ($people as $person) {
315                                                         if (substr($person,0,4) === 'cid:') {
316                                                                 $recipients[] = intval(substr($person,4));
317                                                         } else {
318                                                                 $url_recipients[] = substr($person,4);
319                                                         }
320                                                 }
321                                         }
322                                 }
323
324                                 if (count($url_recipients)) {
325                                         Logger::log('Deliver ' . $target_item["guid"] . ' to _recipients ' . json_decode($url_recipients));
326                                 }
327
328                                 $recipients = array_unique(array_merge($recipients, $allow_people, $allow_groups));
329                                 $deny = array_unique(array_merge($deny_people, $deny_groups));
330                                 $recipients = array_diff($recipients, $deny);
331                         }
332
333                         // If the thread parent is OStatus then do some magic to distribute the messages.
334                         // We have not only to look at the parent, since it could be a Friendica thread.
335                         if (($thr_parent && ($thr_parent['network'] == Protocol::OSTATUS)) || ($parent['network'] == Protocol::OSTATUS)) {
336                                 $diaspora_delivery = false;
337
338                                 Logger::log('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent['author-id']." - Owner: ".$thr_parent['owner-id'], Logger::DEBUG);
339
340                                 // Send a salmon to the parent author
341                                 $probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['author-id']]);
342                                 if (DBA::isResult($probed_contact) && !empty($probed_contact["notify"])) {
343                                         Logger::log('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]);
344                                         $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
345                                 }
346
347                                 // Send a salmon to the parent owner
348                                 $probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['owner-id']]);
349                                 if (DBA::isResult($probed_contact) && !empty($probed_contact["notify"])) {
350                                         Logger::log('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]);
351                                         $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
352                                 }
353
354                                 // Send a salmon notification to every person we mentioned in the post
355                                 $arr = explode(',',$target_item['tag']);
356                                 foreach ($arr as $x) {
357                                         //Logger::log('Checking tag '.$x, Logger::DEBUG);
358                                         $matches = null;
359                                         if (preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
360                                                         $probed_contact = Probe::uri($matches[1]);
361                                                 if ($probed_contact["notify"] != "") {
362                                                         Logger::log('Notify mentioned user '.$probed_contact["url"].': '.$probed_contact["notify"]);
363                                                         $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
364                                                 }
365                                         }
366                                 }
367
368                                 // It only makes sense to distribute answers to OStatus messages to Friendica and OStatus - but not Diaspora
369                                 $networks = [Protocol::OSTATUS, Protocol::DFRN];
370                         } else {
371                                 $networks = [Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA, Protocol::MAIL];
372                         }
373                 } else {
374                         $public_message = false;
375                 }
376
377                 // If this is a public message and pubmail is set on the parent, include all your email contacts
378                 if (!empty($target_item) && function_exists('imap_open') && !Config::get('system','imap_disabled')) {
379                         if (!strlen($target_item['allow_cid']) && !strlen($target_item['allow_gid'])
380                                 && !strlen($target_item['deny_cid']) && !strlen($target_item['deny_gid'])
381                                 && intval($target_item['pubmail'])) {
382                                 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s'",
383                                         intval($uid),
384                                         DBA::escape(Protocol::MAIL)
385                                 );
386                                 if (DBA::isResult($r)) {
387                                         foreach ($r as $rr) {
388                                                 $recipients[] = $rr['id'];
389                                         }
390                                 }
391                         }
392                 }
393
394                 if (($cmd == Delivery::RELOCATION)) {
395                         $contacts = $recipients_relocate;
396                 } else {
397                         if ($followup) {
398                                 $recipients = $recipients_followup;
399                         }
400                         $condition = ['id' => $recipients, 'self' => false,
401                                 'blocked' => false, 'pending' => false, 'archive' => false];
402                         if (!empty($networks)) {
403                                 $condition['network'] = $networks;
404                         }
405                         $result = DBA::select('contact', ['id', 'url', 'network', 'batch'], $condition);
406                         $contacts = DBA::toArray($result);
407                 }
408
409                 $conversants = [];
410                 $batch_delivery = false;
411
412                 if ($public_message && !in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION]) && !$followup) {
413                         $r1 = [];
414
415                         if ($diaspora_delivery) {
416                                 $batch_delivery = true;
417
418                                 $r1 = q("SELECT `batch`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`name`) AS `name`, ANY_VALUE(`network`) AS `network`
419                                         FROM `contact` WHERE `network` = '%s' AND `batch` != ''
420                                         AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch`",
421                                         DBA::escape(Protocol::DIASPORA),
422                                         intval($owner['uid']),
423                                         intval(Contact::SHARING)
424                                 );
425
426                                 // Fetch the participation list
427                                 // The function will ensure that there are no duplicates
428                                 $r1 = Diaspora::participantsForThread($item_id, $r1);
429
430                                 // Add the relay to the list, avoid duplicates
431                                 if (!$followup) {
432                                         $r1 = Diaspora::relayList($item_id, $r1);
433                                 }
434                         }
435
436                         $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false,
437                                 'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]];
438
439                         $r2 = DBA::toArray(DBA::select('contact', ['id', 'name', 'network'], $condition));
440
441                         $r = array_merge($r2, $r1);
442
443                         if (DBA::isResult($r)) {
444                                 foreach ($r as $rr) {
445                                         $conversants[] = $rr['id'];
446                                         Logger::log('Public delivery of item ' . $target_item["guid"] . ' (' . $item_id . ') to ' . json_encode($rr), Logger::DEBUG);
447                                         Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
448                                                 'Delivery', $cmd, $item_id, (int)$rr['id']);
449                                 }
450                         }
451
452                         $push_notify = true;
453                 }
454
455                 // delivery loop
456                 if (DBA::isResult($contacts)) {
457                         foreach ($contacts as $contact) {
458                                 // Don't deliver to Diaspora if it already had been done as batch delivery
459                                 if (($contact['network'] == Protocol::DIASPORA) && $batch_delivery) {
460                                         Logger::log('Already delivered  id ' . $item_id . ' via batch to ' . json_encode($contact), Logger::DEBUG);
461                                         continue;
462                                 }
463
464                                 // Don't deliver to folks who have already been delivered to
465                                 if (in_array($contact['id'], $conversants)) {
466                                         Logger::log('Already delivered id ' . $item_id. ' to ' . json_encode($contact), Logger::DEBUG);
467                                         continue;
468                                 }
469
470                                 Logger::log('Delivery of item ' . $item_id . ' to ' . json_encode($contact), Logger::DEBUG);
471                                 Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
472                                                 'Delivery', $cmd, $item_id, (int)$contact['id']);
473                         }
474                 }
475
476                 // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts
477                 // They are especially used for notifications to OStatus users that don't follow us.
478                 if (!Config::get('system', 'dfrn_only') && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) {
479                         $slap = OStatus::salmon($target_item, $owner);
480                         foreach ($url_recipients as $url) {
481                                 if ($url) {
482                                         Logger::log('Salmon delivery of item ' . $item_id . ' to ' . $url);
483                                         $deliver_status = Salmon::slapper($owner, $url, $slap);
484                                         /// @TODO Redeliver/queue these items on failure, though there is no contact record
485                                 }
486                         }
487                 }
488
489                 // Notify PuSH subscribers (Used for OStatus distribution of regular posts)
490                 if ($push_notify) {
491                         Logger::log('Activating internal PuSH for item '.$item_id, Logger::DEBUG);
492
493                         // Handling the pubsubhubbub requests
494                         PushSubscriber::publishFeed($owner['uid'], $a->queue['priority']);
495                 }
496
497                 Logger::log('Calling hooks for ' . $cmd . ' ' . $item_id, Logger::DEBUG);
498
499                 if ($normal_mode) {
500                         Hook::fork($a->queue['priority'], 'notifier_normal', $target_item);
501                 }
502
503                 Addon::callHooks('notifier_end',$target_item);
504
505                 return;
506         }
507
508         private static function activityPubDelivery($a, $cmd, $item_id, $uid, $target_item, $parent)
509         {
510                 $inboxes = [];
511                 $personal = false;
512
513                 if ($target_item['origin']) {
514                         $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid);
515                         Logger::log('Origin item ' . $item_id . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG);
516                 } elseif (!DBA::exists('conversation', ['item-uri' => $target_item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB])) {
517                         Logger::log('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.', Logger::DEBUG);
518                         return;
519                 } else {
520                         // Remote items are transmitted via the personal inboxes.
521                         // Doing so ensures that the dedicated receiver will get the message.
522                         $personal = true;
523                         Logger::log('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG);
524                 }
525
526                 if ($parent['origin']) {
527                         $parent_inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, $personal);
528                         $inboxes = array_merge($inboxes, $parent_inboxes);
529                 }
530
531                 if (empty($inboxes)) {
532                         Logger::log('No inboxes found for item ' . $item_id . ' with URL ' . $target_item['uri'] . '. It will not be distributed.', Logger::DEBUG);
533                         return;
534                 }
535
536                 // Fill the item cache
537                 ActivityPub\Transmitter::createCachedActivityFromItem($item_id, true);
538
539                 foreach ($inboxes as $inbox) {
540                         Logger::log('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
541
542                         Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
543                                         'APDelivery', $cmd, $item_id, $inbox, $uid);
544                 }
545         }
546
547         private static function isForumPost($item, $owner) {
548                 if (($item['author-id'] == $item['owner-id']) ||
549                         ($owner['id'] == $item['contact-id']) ||
550                         ($item['uri'] != $item['parent-uri'])) {
551                         return false;
552                 }
553
554                 $fields = ['forum', 'prv'];
555                 $condition = ['id' => $item['contact-id']];
556                 $contact = DBA::selectFirst('contact', $fields, $condition);
557                 if (!DBA::isResult($contact)) {
558                         // Should never happen
559                         return false;
560                 }
561
562                 // Is the post from a forum?
563                 return ($contact['forum'] || $contact['prv']);
564         }
565 }