////                                                                            -*- coding:utf-8; -*-
// Startup configuration for difference feed's message harvester.
//
vo.inc( 'code/votorola/s/share/JSON.jsm' );
vo.inc( 'code/votorola/s/share/wiki.jsm' );
vo.inc( 'code/votorola/s/share/wikiURIResolver.jsm' );
vo.inc( 'vote-server.jsm' );



    /** Called prior to construction of the harvester.
      *
      *     haCC - harvester construction context, per
      *       votorola/_/javadoc/votorola/a/diff/VOHarvester.ConstructionContext.html
      */
    function contructingHarvester( haCC )
    {
        haCC.setCrossforumService( 'http://metagovernment.tuxfamily.org/crossforum/' );
        haCC.setDiffService( 'http://' + _hvv_voteServer.serverName + ':8080/'
          + _hvv_voteServer.name + '/w/D' );

        var ircCC = haCC.ircHarvesterCC();
        ircCC.addChannel( '#metagov' );
        ircCC.setHostname( 'irc.freenode.net' );
        ircCC.setName( '#metagov on freenode' );
        ircCC.setUsername( _hvv_voteServer.name == 'v'? 'xfbot': _hvv_voteServer.name + '-xfbot' );
        ircCC.setWebPFunction( 'wpIRC_freenode_metagov' );

        var mailCC = haCC.maildirHarvesterCC();
        mailCC.setInterval( 60/*seconds*/ ); // for polling the maildir
        mailCC.setName( 'metagoverment' );
        mailCC.setWebPFunction( 'wpMail_start_metagovernment' );
        _hvv_voteServer.contructingMaildirHarvester( mailCC );
    }



    /** Undocumented.
      */
    function ircNickname( mailishUsername )
    {
        var userPageName = "User:" + mailishUsername;
        var userPage = vo_s_share_wiki.setPagePropertiesFromRDF(
          {}, userPageName, JSON.parse( voteServer.wikiCache().readRDF_JSON(
            userPageName, false /* TODO change to false */ )));
        var nickname = vo_s_share_wiki.valueFromRDF( userPage['Property:IRC nickname'] );
        return nickname;
    }



    /** Undocumented.  [Liable to break in future releases.  Instead, caller ought to pass
      * a single context parameter to each function as required.]
      */
    function init( ps ) { voteServer = ps; }



    var voteServer;



    function wpIRC_freenode_metagov( wp )
    {
        wp.setUrl( _hvv_voteServer.hostURL + '/home/' + _hvv_voteServer.name // channel logs
          + '/votorola/out/voharvester/irclog/' + wp.ident() );
    }



    /** Undocumented.
      *
      *     wp - context of a web service provider, per
      *       votorola/_/javadoc/votorola/a/diff/feed/Harvester.WebProviderContext.html
      */
    function wpMail_start_metagovernment( wp )
    {
       if( wp.ident() == 'scraper' ) wp.setIdent( '' );
        wp.setUrl( 'http://metagovernment.org/pipermail/start_metagovernment.org/' + wp.ident() );
    }