<commit_before><?php
 /* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·  
  ·                                                                             ·
  ·                                                                             ·
  ·                             Q V I T T E R                                   ·
  ·                                                                             ·
  ·              http://github.com/hannesmannerheim/qvitter                     ·
  ·                                                                             ·
  ·                                                                             ·
  ·                                 <o)                                         ·
  ·                                  /_////                                     ·
  ·                                 (____/                                      ·
  ·                                          (o<                                ·
  ·                                   o> \\\\_\                                 ·
  ·                                 \\)   \____)                                ·
  ·                                                                             ·
  ·                                                                             ·    
  ·                                                                             ·
  ·  Qvitter is free  software:  you can  redistribute it  and / or  modify it  ·
  ·  under the  terms of the GNU Affero General Public License as published by  ·
  ·  the Free Software Foundation,  either version three of the License or (at  ·
  ·  your option) any later version.                                            ·
  ·                                                                             ·
  ·  Qvitter is distributed  in hope that  it will be  useful but  WITHOUT ANY  ·
  ·  WARRANTY;  without even the implied warranty of MERCHANTABILTY or FITNESS  ·
  ·  FOR A PARTICULAR PURPOSE.  See the  GNU Affero General Public License for  ·
  ·  more details.                                                              ·
  ·                                                                             ·
  ·  You should have received a copy of the  GNU Affero General Public License  ·
  ·  along with Qvitter. If not, see <http://www.gnu.org/licenses/>.            ·
  ·                                                                             ·
  ·  Contact <EMAIL> if you have any questions.                       ·
  ·                                                                             · 
  · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */

if (!defined('STATUSNET')) {
    exit(1);
}

class ApiQvitterNotificationsAction extends ApiPrivateAuthAction
{
    var $notifications = null;
    var $notices = null;
    var $profiles = null;

    /**
     * Take arguments for running
     *
     * @param array $args $_REQUEST args
     *
     * @return boolean success flag
     *
     */
    function prepare($args)
    {
        parent::prepare($args);

        $this->notifications = $this->getNotifications();

        return true;
    }

    /**
     * Handle the request
     *
     * Just show the notices
     *
     * @param array $args $_REQUEST data (unused)
     *
     * @return void
     */
    function handle($args)
    {
        parent::handle($args);
        $this->showTimeline();
    }

    /**
     * Show the timeline of notices
     *
     * @return void
     */
    function showTimeline()
    {
        
        $notice = null;        
        
        $notifications_populated = array();
        
        if(!empty($this->notifications)) {

			foreach($this->notifications as $notification) {
			
				
				// all but follow has an notice
				if($notification->ntype != 'follow') {
					
					// we need a notice id here, skip this notification if notice id is null
					if($notification->notice_id === null) {
						continue;
						}
					else {
						$notice = self::twitterSimpleStatusArray(Notice::getKV($notification->notice_id));						
						}
					}
					
				$from_profile = Profile::getKV($notification->from_profile_id);
				
				// a user might have deleted their profile, don't show these notifications
				if($from_profile instanceof Profile) {

					$notifications_populated[] = array(
												'id'=> $notification->id,
												'from_profile'=> self::twitterUserArray($from_profile),
												'ntype'=> $notification->ntype,        								        								        								
												'notice'=> $notice,
												'created_at'=>self::dateTwitter($notification->created),
												'is_seen'=>$notification->is_seen        								
												);

					}
				}

			// mark as seen
			foreach($this->notifications as $notification) {
				if($notification->is_seen == 0) {
					$notification->is_seen = 1;
					$notification->update();
					}             
				}
        	
        	}            

        $this->initDocument('json');
        $this->showJsonObjects($notifications_populated);
        $this->endDocument('json');
    }

    /**
     * Get notices
     *
     * @return array notices
     */
    function getNotifications()
    {
        $notices = array();<commit_msg>No need to test if it's empty when we're running foreach<commit_after><?php
 /* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·  
  ·                                                                             ·
  ·                                                                             ·
  ·                             Q V I T T E R                                   ·
  ·                                                                             ·
  ·              http://github.com/hannesmannerheim/qvitter                     ·
  ·                                                                             ·
  ·                                                                             ·
  ·                                 <o)                                         ·
  ·                                  /_////                                     ·
  ·                                 (____/                                      ·
  ·                                          (o<                                ·
  ·                                   o> \\\\_\                                 ·
  ·                                 \\)   \____)                                ·
  ·                                                                             ·
  ·                                                                             ·    
  ·                                                                             ·
  ·  Qvitter is free  software:  you can  redistribute it  and / or  modify it  ·
  ·  under the  terms of the GNU Affero General Public License as published by  ·
  ·  the Free Software Foundation,  either version three of the License or (at  ·
  ·  your option) any later version.                                            ·
  ·                                                                             ·
  ·  Qvitter is distributed  in hope that  it will be  useful but  WITHOUT ANY  ·
  ·  WARRANTY;  without even the implied warranty of MERCHANTABILTY or FITNESS  ·
  ·  FOR A PARTICULAR PURPOSE.  See the  GNU Affero General Public License for  ·
  ·  more details.                                                              ·
  ·                                                                             ·
  ·  You should have received a copy of the  GNU Affero General Public License  ·
  ·  along with Qvitter. If not, see <http://www.gnu.org/licenses/>.            ·
  ·                                                                             ·
  ·  Contact <EMAIL> if you have any questions.                       ·
  ·                                                                             · 
  · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */

if (!defined('STATUSNET')) {
    exit(1);
}

class ApiQvitterNotificationsAction extends ApiPrivateAuthAction
{
    var $notifications = array();
    var $notices = null;
    var $profiles = null;

    /**
     * Take arguments for running
     *
     * @param array $args $_REQUEST args
     *
     * @return boolean success flag
     *
     */
    function prepare($args)
    {
        parent::prepare($args);

        $this->notifications = $this->getNotifications();

        return true;
    }

    /**
     * Handle the request
     *
     * Just show the notices
     *
     * @param array $args $_REQUEST data (unused)
     *
     * @return void
     */
    function handle($args)
    {
        parent::handle($args);
        $this->showTimeline();
    }

    /**
     * Show the timeline of notices
     *
     * @return void
     */
    function showTimeline()
    {
        
        $notice = null;        
        
        $notifications_populated = array();
        
			foreach($this->notifications as $notification) {
			
				
				// all but follow has an notice
				if($notification->ntype != 'follow') {
					
					// we need a notice id here, skip this notification if notice id is null
					if($notification->notice_id === null) {
						continue;
						}
					else {
						$notice = self::twitterSimpleStatusArray(Notice::getKV($notification->notice_id));						
						}
					}
					
				$from_profile = Profile::getKV($notification->from_profile_id);
				
				// a user might have deleted their profile, don't show these notifications
				if($from_profile instanceof Profile) {

					$notifications_populated[] = array(
												'id'=> $notification->id,
												'from_profile'=> self::twitterUserArray($from_profile),
												'ntype'=> $notification->ntype,        								        								        								
												'notice'=> $notice,
												'created_at'=>self::dateTwitter($notification->created),
												'is_seen'=>$notification->is_seen        								
												);

					}
				}

			// mark as seen
			foreach($this->notifications as $notification) {
				if($notification->is_seen == 0) {
					$notification->is_seen = 1;
					$notification->update();
					}             
				}

        $this->initDocument('json');
        $this->showJsonObjects($notifications_populated);
        $this->endDocument('json');
    }

    /**
     * Get notices
     *
     * @return array notices
     */
    function getNotifications()
    {
        $notices = array();
{'fraction_non_alphanumeric': 0.09832971595734642, 'fraction_numerical': 0.000566197980560536, 'mean_word_length': 0.8447345517841601, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 136, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4104866', 'n_tokens_mistral': 2834, 'n_tokens_neox': 2364, 'n_words': 826}