X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FNotice.php;fp=classes%2FNotice.php;h=79b034e76f9bb9055b5365f630b241c29758d03d;hb=31c1177970124cee31823cab3a11542c23b4126d;hp=a158a4930df6f4eb4aa3c1d1401f3933f1845d3b;hpb=0a71622aa731c62c89ba84ef86d21fd168521ee1;p=quix0rs-gnu-social.git diff --git a/classes/Notice.php b/classes/Notice.php index a158a4930d..79b034e76f 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -437,6 +437,12 @@ class Notice extends Memcached_DataObject $notice->saveGroups(); } + if (isset($peopletags)) { + $notice->saveProfileTags($peopletags); + } else { + $notice->saveProfileTags(); + } + if (isset($urls)) { $notice->saveKnownUrls($urls); } else { @@ -841,6 +847,7 @@ class Notice extends Memcached_DataObject } $users = $this->getSubscribedUsers(); + $ptags = $this->getProfileTags(); // FIXME: kind of ignoring 'transitional'... // we'll probably stop supporting inboxless mode @@ -864,11 +871,22 @@ class Notice extends Memcached_DataObject } } - foreach ($recipients as $recipient) { - if (!array_key_exists($recipient, $ni)) { - $ni[$recipient] = NOTICE_INBOX_SOURCE_REPLY; + foreach ($ptags as $ptag) { + $users = $ptag->getUserSubscribers(); + foreach ($users as $id) { + if (!array_key_exists($id, $ni)) { + $user = User::staticGet('id', $id); + if (!$user->hasBlocked($profile)) { + $ni[$id] = NOTICE_INBOX_SOURCE_PROFILE_TAG; + } } } + } + + foreach ($recipients as $recipient) { + if (!array_key_exists($recipient, $ni)) { + $ni[$recipient] = NOTICE_INBOX_SOURCE_REPLY; + } // Exclude any deleted, non-local, or blocking recipients. $profile = $this->getProfile(); @@ -964,6 +982,39 @@ class Notice extends Memcached_DataObject return $ids; } + function getProfileTags() + { + // Don't save ptags for repeats, for now. + + if (!empty($this->repeat_of)) { + return array(); + } + + // XXX: cache me + + $ptags = array(); + + $ptagi = new Profile_tag_inbox(); + + $ptagi->selectAdd(); + $ptagi->selectAdd('profile_tag_id'); + + $ptagi->notice_id = $this->id; + + if ($ptagi->find()) { + while ($ptagi->fetch()) { + $profile_list = Profile_list::staticGet('id', $ptagi->profile_tag_id); + if ($profile_list) { + $ptags[] = $profile_list; + } + } + } + + $ptagi->free(); + + return $ptags; + } + /** * Record this notice to the given group inboxes for delivery. * Overrides the regular parsing of !group markup. @@ -1085,6 +1136,69 @@ class Notice extends Memcached_DataObject return true; } + /** + * record targets into profile_tag_inbox. + * @return array of Profile_list objects + */ + function saveProfileTags($known=array()) + { + // Don't save ptags for repeats, for now + + if (!empty($this->repeat_of)) { + return array(); + } + + if (is_array($known)) { + $ptags = $known; + } else { + $ptags = array(); + } + + $ptag = new Profile_tag(); + $ptag->tagged = $this->profile_id; + + if($ptag->find()) { + while($ptag->fetch()) { + $plist = Profile_list::getByTaggerAndTag($ptag->tagger, $ptag->tag); + $ptags[] = clone($plist); + } + } + + foreach ($ptags as $target) { + $this->addToProfileTagInbox($target); + } + + return $ptags; + } + + function addToProfileTagInbox($plist) + { + $ptagi = Profile_tag_inbox::pkeyGet(array('profile_tag_id' => $plist->id, + 'notice_id' => $this->id)); + + if (empty($ptagi)) { + + $ptagi = new Profile_tag_inbox(); + + $ptagi->query('BEGIN'); + $ptagi->profile_tag_id = $plist->id; + $ptagi->notice_id = $this->id; + $ptagi->created = $this->created; + + $result = $ptagi->insert(); + if (!$result) { + common_log_db_error($ptagi, 'INSERT', __FILE__); + throw new ServerException(_('Problem saving profile_tag inbox.')); + } + + $ptagi->query('COMMIT'); + + self::blow('profile_tag:notice_ids:%d', $ptagi->profile_tag_id); + } + + return true; + } + /** * Save reply records indicating that this notice needs to be * delivered to the local users with the given URIs.