function handle($data)
 {
     // JSON object with Twitter data
     $status = $data['status'];
     // Twitter user ID this incoming data belongs to.
     $receiver = $data['for_user'];
     $importer = new TwitterImport();
     $notice = $importer->importStatus($status);
     if ($notice instanceof Notice) {
         try {
             $flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE);
             common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice " . $notice->id . " to attentions for user " . $flink->user_id);
             try {
                 Attention::saveNew($notice, $flink->getProfile());
             } catch (Exception $e) {
                 // Log the exception, but make sure we don't bail out, we
                 // still have a queue item to remove here-after.
                 common_log(LOG_ERR, "Failed adding notice {$notice->id} to attentions for user {$flink->user_id}: " . $e->getMessage());
             }
         } catch (NoResultException $e) {
             common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user " . $receiver);
         }
     }
     return true;
 }
 /**
  * Handle distribution of a notice after we've saved it:
  * @li add to local recipient inboxes
  * @li send email notifications to local @-reply targets
  * @li run final EndNoticeSave plugin events
  * @li put any remaining post-processing into the queues
  *
  * If this function indicates failure, a warning will be logged
  * and the item is placed back in the queue to be re-run.
  *
  * @param Notice $notice
  * @return boolean true on success, false on failure
  */
 public function handle(Notice $notice)
 {
     // We have to manually add attentions to non-profile subs and non-mentions
     $ptAtts = $notice->getAttentionsFromProfileTags();
     foreach (array_keys($ptAtts) as $profile_id) {
         $profile = Profile::getKV('id', $profile_id);
         if ($profile instanceof Profile) {
             try {
                 common_debug('Adding Attention for ' . $notice->getID() . ' profile ' . $profile->getID());
                 Attention::saveNew($notice, $profile);
             } catch (Exception $e) {
                 $this->logit($notice, $e);
             }
         }
     }
     try {
         $notice->sendReplyNotifications();
     } catch (Exception $e) {
         $this->logit($notice, $e);
     }
     try {
         Event::handle('EndNoticeDistribute', array($notice));
     } catch (Exception $e) {
         $this->logit($notice, $e);
     }
     try {
         Event::handle('EndNoticeSave', array($notice));
     } catch (Exception $e) {
         $this->logit($notice, $e);
     }
     try {
         // Enqueue for other handlers
         common_enqueue_notice($notice);
     } catch (Exception $e) {
         $this->logit($notice, $e);
     }
     return true;
 }
예제 #3
0
 /**
  * Saves an attention for a profile (user or group) which means
  * it shows up in their home feed and such.
  */
 function saveAttention(Profile $target, $reason = null)
 {
     if ($target->isGroup()) {
         // FIXME: Make sure we check (for both local and remote) users are in the groups they send to!
         // legacy notification method, will still be in use for quite a while I think
         $this->addToGroupInbox($target->getGroup());
     } else {
         if ($target->hasBlocked($this->getProfile())) {
             common_log(LOG_INFO, "Not saving reply to profile {$target->id} ({$uri}) from sender {$sender->id} because of a block.");
             return false;
         }
     }
     if ($target->isLocal()) {
         // legacy notification method, will still be in use for quite a while I think
         $this->saveReply($target->getID());
     }
     $att = Attention::saveNew($this, $target, $reason);
     self::blow('reply:stream:%d', $target->getID());
     return true;
 }