2012-05-17 18:40:46 -07:00
NEWSBLUR . AssetModel = Backbone . Router . extend ( {
2010-06-08 11:19:41 -04:00
2012-05-17 18:40:46 -07:00
initialize : function ( ) {
this . defaults = {
classifiers : {
titles : { } ,
tags : { } ,
authors : { } ,
feeds : { }
}
} ;
this . feeds = new NEWSBLUR . Collections . Feeds ( ) ;
this . social _feeds = new NEWSBLUR . Collections . SocialSubscriptions ( ) ;
2012-05-23 10:02:30 -07:00
this . folders = new NEWSBLUR . Collections . Folders ( [ ] ) ;
2012-05-17 18:40:46 -07:00
this . favicons = { } ;
2012-05-24 17:32:01 -07:00
this . stories = new NEWSBLUR . Collections . Stories ( ) ;
2012-05-17 18:40:46 -07:00
this . queued _read _stories = { } ;
this . classifiers = { } ;
this . friends = { } ;
this . profile = { } ;
this . user _profile = new NEWSBLUR . Models . User ( ) ;
2012-06-27 23:57:57 -07:00
this . social _services = { } ;
2012-05-17 18:40:46 -07:00
this . user _profiles = new NEWSBLUR . Collections . Users ( ) ;
this . follower _profiles = new NEWSBLUR . Collections . Users ( ) ;
this . following _profiles = new NEWSBLUR . Collections . Users ( ) ;
this . starred _stories = [ ] ;
this . starred _count = 0 ;
this . flags = {
'favicons_fetching' : false ,
2012-05-25 16:42:41 -07:00
'has_chosen_feeds' : false ,
'no_more_stories' : false
2012-05-17 18:40:46 -07:00
} ;
2010-06-08 11:19:41 -04:00
this . ajax = { } ;
2012-02-10 09:24:48 -08:00
this . ajax [ 'rapid' ] = $ . manageAjax . create ( 'rapid' , { queue : false } ) ;
2012-02-03 11:41:01 -08:00
this . ajax [ 'queue' ] = $ . manageAjax . create ( 'queue' , { queue : true } ) ;
2010-10-06 20:26:42 -04:00
this . ajax [ 'queue_clear' ] = $ . manageAjax . create ( 'queue_clear' , { queue : 'clear' } ) ;
2012-02-03 11:41:01 -08:00
this . ajax [ 'feed' ] = $ . manageAjax . create ( 'feed' , { queue : 'clear' , abortOld : true ,
domCompleteTrigger : true } ) ;
this . ajax [ 'feed_page' ] = $ . manageAjax . create ( 'feed_page' , { queue : 'clear' , abortOld : true ,
abortIsNoSuccess : false ,
domCompleteTrigger : true } ) ;
this . ajax [ 'statistics' ] = $ . manageAjax . create ( 'statistics' , { queue : 'clear' , abortOld : true } ) ;
2013-01-30 12:09:58 -08:00
this . ajax [ 'interactions' ] = $ . manageAjax . create ( 'interactions' , { queue : 'clear' , abortOld : true } ) ;
2010-10-06 20:58:29 -04:00
$ . ajaxSettings . traditional = true ;
2010-06-08 11:19:41 -04:00
} ,
make _request : function ( url , data , callback , error _callback , options ) {
var self = this ;
var options = $ . extend ( {
'ajax_group' : 'queue' ,
'traditional' : true ,
2010-10-06 20:26:42 -04:00
'domSuccessTrigger' : true ,
2011-02-28 19:29:19 -05:00
'preventDoubleRequests' : false
2010-06-08 11:19:41 -04:00
} , options ) ;
2011-04-20 09:35:59 -04:00
var request _type = options . request _type || 'POST' ;
2010-07-25 23:13:27 -04:00
var clear _queue = false ;
2010-06-08 11:19:41 -04:00
if ( options [ 'ajax_group' ] == 'feed' ) {
2010-07-25 23:13:27 -04:00
clear _queue = true ;
}
if ( options [ 'ajax_group' ] == 'statistics' ) {
clear _queue = true ;
}
2013-01-30 12:09:58 -08:00
if ( options [ 'ajax_group' ] == 'interactions' ) {
clear _queue = true ;
}
2010-07-25 23:13:27 -04:00
if ( clear _queue ) {
2010-06-08 11:19:41 -04:00
this . ajax [ options [ 'ajax_group' ] ] . clear ( true ) ;
}
2011-10-28 10:29:11 -07:00
this . ajax [ options [ 'ajax_group' ] ] . add ( _ . extend ( {
2010-06-08 11:19:41 -04:00
url : url ,
data : data ,
2010-07-25 23:13:27 -04:00
type : request _type ,
2012-01-02 15:10:57 -08:00
cache : false ,
2012-01-02 15:48:19 -08:00
cacheResponse : false ,
2010-06-08 11:19:41 -04:00
beforeSend : function ( ) {
// NEWSBLUR.log(['beforeSend', options]);
$ . isFunction ( options [ 'beforeSend' ] ) && options [ 'beforeSend' ] ( ) ;
return true ;
} ,
success : function ( o ) {
// NEWSBLUR.log(['make_request 1', o]);
2012-01-23 09:42:05 -08:00
if ( o && o . code < 0 && error _callback ) {
error _callback ( o ) ;
} else if ( $ . isFunction ( callback ) ) {
2010-06-08 11:19:41 -04:00
callback ( o ) ;
}
} ,
2011-02-02 13:07:12 -05:00
error : function ( e , textStatus , errorThrown ) {
2011-11-22 12:08:18 -05:00
if ( errorThrown == 'abort' ) {
return ;
}
2012-10-22 17:07:57 -07:00
NEWSBLUR . log ( [ 'AJAX Error' , e , e . status , textStatus , errorThrown ,
2012-12-28 21:42:52 -08:00
! ! error _callback , error _callback , $ . isFunction ( callback ) ] ) ;
2011-11-22 12:08:18 -05:00
2012-01-08 14:15:22 -08:00
if ( error _callback ) {
2012-07-25 14:03:15 -07:00
error _callback ( e , textStatus , errorThrown ) ;
2010-07-24 15:54:25 -04:00
} else if ( $ . isFunction ( callback ) ) {
2011-02-24 18:51:30 -05:00
var message = "Please create an account. Not much to do without an account." ;
if ( NEWSBLUR . Globals . is _authenticated ) {
message = "Sorry, there was an unhandled error." ;
}
2012-12-28 21:42:52 -08:00
callback ( { 'message' : message , status _code : e . status } ) ;
2010-06-08 11:19:41 -04:00
}
}
2011-10-28 10:29:11 -07:00
} , options ) ) ;
2010-06-08 11:19:41 -04:00
} ,
2012-06-14 17:38:09 -07:00
mark _story _as _read : function ( story , feed , callback ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2012-05-25 18:54:04 -07:00
var read = story . get ( 'read_status' ) ;
2012-02-08 12:20:05 -08:00
2012-05-25 18:54:04 -07:00
if ( ! story . get ( 'read_status' ) ) {
story . set ( 'read_status' , 1 ) ;
2012-02-03 11:41:01 -08:00
if ( NEWSBLUR . Globals . is _authenticated ) {
2012-06-14 17:38:09 -07:00
if ( ! ( feed . id in this . queued _read _stories ) ) { this . queued _read _stories [ feed . id ] = [ ] ; }
this . queued _read _stories [ feed . id ] . push ( story . id ) ;
// NEWSBLUR.log(['Marking Read', this.queued_read_stories, story.id]);
2012-02-03 11:41:01 -08:00
this . make _request ( '/reader/mark_story_as_read' , {
2012-06-14 17:38:09 -07:00
story _id : this . queued _read _stories [ feed . id ] ,
feed _id : feed . id
2012-02-03 11:41:01 -08:00
} , null , null , {
2012-02-10 09:24:48 -08:00
'ajax_group' : $ . browser . msie ? 'rapid' : 'queue_clear' ,
2012-02-03 11:41:01 -08:00
'beforeSend' : function ( ) {
self . queued _read _stories = { } ;
}
} ) ;
}
}
2010-06-08 11:19:41 -04:00
2012-02-08 12:20:05 -08:00
$ . isFunction ( callback ) && callback ( read ) ;
2012-02-03 11:41:01 -08:00
} ,
2012-06-14 17:38:09 -07:00
mark _social _story _as _read : function ( story , social _feed , callback ) {
2012-02-03 11:41:01 -08:00
var self = this ;
2012-05-25 18:54:04 -07:00
var feed _id = story . get ( 'story_feed_id' ) ;
2012-12-13 17:58:19 -08:00
var social _user _id = social _feed && social _feed . get ( 'user_id' ) ;
2012-08-08 11:52:59 -07:00
if ( ! social _user _id ) {
2012-08-10 00:01:59 -07:00
social _user _id = story . get ( 'friend_user_ids' ) [ 0 ] ;
2012-08-08 11:52:59 -07:00
}
2012-11-30 16:12:37 -08:00
if ( ! social _user _id ) {
social _user _id = story . get ( 'public_user_ids' ) [ 0 ] ;
}
2012-05-25 18:54:04 -07:00
var read = story . get ( 'read_status' ) ;
2010-12-15 16:10:54 -05:00
2012-05-25 18:54:04 -07:00
if ( ! story . get ( 'read_status' ) ) {
story . set ( 'read_status' , 1 ) ;
2010-06-08 11:19:41 -04:00
2012-02-03 11:41:01 -08:00
if ( NEWSBLUR . Globals . is _authenticated ) {
if ( ! ( social _user _id in this . queued _read _stories ) ) {
this . queued _read _stories [ social _user _id ] = { } ;
}
if ( ! ( feed _id in this . queued _read _stories [ social _user _id ] ) ) {
this . queued _read _stories [ social _user _id ] [ feed _id ] = [ ] ;
2010-06-08 11:19:41 -04:00
}
2012-06-14 17:38:09 -07:00
this . queued _read _stories [ social _user _id ] [ feed _id ] . push ( story . id ) ;
// NEWSBLUR.log(['Marking Read', this.queued_read_stories, story.id]);
2012-02-03 11:41:01 -08:00
this . make _request ( '/reader/mark_social_stories_as_read' , {
users _feeds _stories : $ . toJSON ( this . queued _read _stories )
} , null , null , {
'ajax_group' : 'queue_clear' ,
'beforeSend' : function ( ) {
self . queued _read _stories = { } ;
}
} ) ;
}
2010-06-08 11:19:41 -04:00
}
2012-02-08 12:20:05 -08:00
$ . isFunction ( callback ) && callback ( read ) ;
2010-06-08 11:19:41 -04:00
} ,
2013-01-23 10:02:14 -08:00
mark _story _as _unread : function ( story _id , feed _id , callback , error _callback ) {
2010-12-30 19:24:52 -05:00
var self = this ;
var read = true ;
2012-05-25 18:54:04 -07:00
var story = this . get _story ( story _id ) ;
story . set ( 'read_status' , 0 ) ;
2010-12-30 19:24:52 -05:00
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/mark_story_as_unread' , {
story _id : story _id ,
feed _id : feed _id
2013-01-23 10:02:14 -08:00
} , null , error _callback , { } ) ;
2010-12-30 19:24:52 -05:00
}
$ . isFunction ( callback ) && callback ( ) ;
} ,
2012-05-25 18:54:04 -07:00
mark _story _as _starred : function ( story _id , callback ) {
2010-11-30 10:30:18 -05:00
var self = this ;
2010-12-02 11:09:09 -05:00
this . starred _count += 1 ;
2010-12-30 18:37:29 -05:00
var story = this . get _story ( story _id ) ;
2012-05-25 18:54:04 -07:00
story . set ( 'starred' , true ) ;
2010-11-30 10:30:18 -05:00
this . make _request ( '/reader/mark_story_as_starred' , {
story _id : story _id ,
2012-05-25 18:54:04 -07:00
feed _id : story . get ( 'story_feed_id' )
2010-11-30 10:30:18 -05:00
} , callback ) ;
} ,
2010-12-02 20:18:33 -05:00
mark _story _as _unstarred : function ( story _id , callback ) {
2010-12-01 09:30:56 -05:00
var self = this ;
2010-12-02 11:09:09 -05:00
this . starred _count -= 1 ;
2010-12-30 18:37:29 -05:00
var story = this . get _story ( story _id ) ;
2012-05-25 18:54:04 -07:00
story . set ( 'starred' , false ) ;
2010-12-01 09:30:56 -05:00
this . make _request ( '/reader/mark_story_as_unstarred' , {
2010-12-02 20:18:33 -05:00
story _id : story _id
2010-12-01 09:30:56 -05:00
} , callback ) ;
} ,
2010-06-08 11:19:41 -04:00
mark _feed _as _read : function ( feed _id , callback ) {
var self = this ;
2010-11-05 20:34:17 -04:00
var feed _ids = _ . isArray ( feed _id )
? _ . select ( feed _id , function ( f ) { return f ; } )
: [ feed _id ] ;
2010-06-08 11:19:41 -04:00
2010-11-30 10:30:18 -05:00
this . make _request ( '/reader/mark_feed_as_read' , {
feed _id : feed _ids
} , callback ) ;
2010-06-08 11:19:41 -04:00
} ,
2012-08-06 17:52:33 -07:00
mark _story _as _shared : function ( params , callback , error _callback ) {
2012-03-08 09:15:33 -08:00
var pre _callback = _ . bind ( function ( data ) {
if ( data . user _profiles ) {
2012-03-22 19:37:19 -07:00
this . add _user _profiles ( data . user _profiles ) ;
2012-03-08 09:15:33 -08:00
}
2012-08-06 17:52:33 -07:00
var story = this . get _story ( params . story _id ) ;
2012-06-06 20:37:20 -07:00
story . set ( data . story ) ;
callback ( data ) ;
2012-03-08 09:15:33 -08:00
} , this ) ;
2012-08-06 17:52:33 -07:00
2012-05-14 16:43:27 -07:00
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/social/share_story' , {
2012-08-06 17:52:33 -07:00
story _id : params . story _id ,
feed _id : params . story _feed _id ,
comments : params . comments ,
source _user _id : params . source _user _id ,
relative _user _id : params . relative _user _id ,
post _to _services : params . post _to _services
2012-05-14 16:43:27 -07:00
} , pre _callback , error _callback ) ;
} else {
error _callback ( ) ;
}
2011-12-14 09:51:47 -08:00
} ,
2012-08-06 17:52:33 -07:00
mark _story _as _unshared : function ( params , callback , error _callback ) {
2012-06-20 20:53:32 -07:00
var pre _callback = _ . bind ( function ( data ) {
if ( data . user _profiles ) {
this . add _user _profiles ( data . user _profiles ) ;
}
2012-08-06 17:52:33 -07:00
var story = this . get _story ( params . story _id ) ;
2012-06-20 20:53:32 -07:00
story . set ( data . story ) ;
callback ( data ) ;
} , this ) ;
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/social/unshare_story' , {
2012-08-06 17:52:33 -07:00
story _id : params . story _id ,
feed _id : params . story _feed _id ,
relative _user _id : params . relative _user _id
2012-06-20 20:53:32 -07:00
} , pre _callback , error _callback ) ;
} else {
error _callback ( ) ;
}
} ,
2012-07-27 18:58:35 -07:00
save _comment _reply : function ( story _id , story _feed _id , comment _user _id , reply _comments , reply _id , callback , error _callback ) {
2012-03-22 19:37:19 -07:00
var pre _callback = _ . bind ( function ( data ) {
if ( data . user _profiles ) {
this . add _user _profiles ( data . user _profiles ) ;
}
callback ( data ) ;
} , this ) ;
this . make _request ( '/social/save_comment_reply' , {
story _id : story _id ,
story _feed _id : story _feed _id ,
comment _user _id : comment _user _id ,
2012-05-01 18:00:54 -07:00
reply _comments : reply _comments ,
2012-07-27 18:58:35 -07:00
reply _id : reply _id
2012-04-23 11:26:36 -07:00
} , pre _callback , error _callback ) ;
2012-03-22 19:37:19 -07:00
} ,
2012-07-28 22:36:50 -07:00
delete _comment _reply : function ( story _id , story _feed _id , comment _user _id , reply _id , callback , error _callback ) {
var pre _callback = _ . bind ( function ( data ) {
if ( data . user _profiles ) {
this . add _user _profiles ( data . user _profiles ) ;
}
callback ( data ) ;
} , this ) ;
this . make _request ( '/social/remove_comment_reply' , {
story _id : story _id ,
story _feed _id : story _feed _id ,
comment _user _id : comment _user _id ,
reply _id : reply _id
} , pre _callback , error _callback ) ;
} ,
2012-07-15 17:59:19 -07:00
like _comment : function ( story _id , story _feed _id , comment _user _id , callback , error _callback ) {
var pre _callback = _ . bind ( function ( data ) {
if ( data . user _profiles ) {
this . add _user _profiles ( data . user _profiles ) ;
}
callback && callback ( data ) ;
} , this ) ;
this . make _request ( '/social/like_comment' , {
story _id : story _id ,
story _feed _id : story _feed _id ,
comment _user _id : comment _user _id
} , pre _callback , error _callback ) ;
} ,
remove _like _comment : function ( story _id , story _feed _id , comment _user _id , callback , error _callback ) {
var pre _callback = _ . bind ( function ( data ) {
if ( data . user _profiles ) {
this . add _user _profiles ( data . user _profiles ) ;
}
callback && callback ( data ) ;
} , this ) ;
this . make _request ( '/social/remove_like_comment' , {
story _id : story _id ,
story _feed _id : story _feed _id ,
comment _user _id : comment _user _id
} , pre _callback , error _callback ) ;
} ,
2012-03-22 19:37:19 -07:00
add _user _profiles : function ( user _profiles ) {
var profiles = _ . reject ( user _profiles , _ . bind ( function ( profile ) {
return profile . id in this . user _profiles . _byId ;
} , this ) ) ;
2012-04-16 11:21:52 -07:00
this . user _profiles . add ( profiles ) ;
2012-03-22 19:37:19 -07:00
} ,
2012-06-15 14:49:59 -07:00
load _feeds : function ( callback , error _callback ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2012-07-17 14:14:45 -07:00
var selected = this . feeds . selected ( ) ;
2012-06-15 14:49:59 -07:00
2012-05-17 18:40:46 -07:00
var pre _callback = function ( feeds , subscriptions ) {
self . flags [ 'favicons_fetching' ] = self . feeds . any ( function ( feed ) { return feed . get ( 'favicons_fetching' ) ; } ) ;
2012-05-17 20:50:08 -07:00
2013-01-14 12:50:00 -08:00
self . folders . reset ( _ . compact ( subscriptions . folders ) , { parse : true } ) ;
2010-12-01 14:11:42 -05:00
self . starred _count = subscriptions . starred _count ;
2012-02-10 12:48:14 -08:00
self . social _feeds . reset ( subscriptions . social _feeds ) ;
2012-03-07 18:35:17 -08:00
self . user _profile . set ( subscriptions . social _profile ) ;
2012-06-27 23:57:57 -07:00
self . social _services = subscriptions . social _services ;
2012-07-17 14:14:45 -07:00
if ( selected ) {
self . feeds . get ( selected ) . set ( 'selected' , true ) ;
}
2011-04-05 19:24:12 -04:00
if ( ! _ . isEqual ( self . favicons , { } ) ) {
2012-05-17 18:40:46 -07:00
self . feeds . each ( function ( feed ) {
2011-05-01 18:57:19 -04:00
if ( self . favicons [ feed . id ] ) {
2012-05-17 18:40:46 -07:00
feed . set ( 'favicon' , self . favicons [ feed . id ] ) ;
2011-05-01 18:57:19 -04:00
}
2011-04-05 19:24:12 -04:00
} ) ;
}
2012-03-12 12:33:54 -07:00
2012-05-18 18:13:45 -07:00
self . flags [ 'has_chosen_feeds' ] = self . feeds . has _chosen _feeds ( ) ;
2012-05-17 20:50:08 -07:00
self . feeds . trigger ( 'reset' ) ;
2012-06-15 14:49:59 -07:00
callback && callback ( ) ;
2010-06-08 11:19:41 -04:00
} ;
2012-05-17 18:40:46 -07:00
this . feeds . fetch ( {
success : pre _callback ,
error : error _callback
2012-03-20 11:15:40 -07:00
} ) ;
2010-06-08 11:19:41 -04:00
} ,
2011-04-05 19:24:12 -04:00
load _feed _favicons : function ( callback , loaded _once , load _all ) {
var pre _callback = _ . bind ( function ( favicons ) {
this . favicons = favicons ;
if ( ! _ . isEqual ( this . feeds , { } ) ) {
2012-05-21 20:08:27 -07:00
this . feeds . each ( function ( feed ) {
2011-05-01 18:57:19 -04:00
if ( favicons [ feed . id ] ) {
2012-05-21 20:08:27 -07:00
feed . set ( 'favicon' , favicons [ feed . id ] ) ;
2011-05-01 18:57:19 -04:00
}
2012-05-21 20:08:27 -07:00
} ) ;
2011-04-05 19:24:12 -04:00
}
callback ( ) ;
} , this ) ;
var data = {
load _all : load _all
} ;
if ( loaded _once ) {
2012-05-21 20:08:27 -07:00
data [ 'feed_ids' ] = _ . compact ( this . feeds . map ( function ( feed ) {
return ! feed . get ( 'favicon' ) && feed . id ;
2011-04-05 19:24:12 -04:00
} ) ) ;
}
2011-04-20 09:35:59 -04:00
this . make _request ( '/reader/favicons' , data , pre _callback , pre _callback , { request _type : 'GET' } ) ;
2011-04-05 19:24:12 -04:00
} ,
2011-11-15 18:19:09 -08:00
load _feed : function ( feed _id , page , first _load , callback , error _callback ) {
2010-06-08 11:19:41 -04:00
var self = this ;
var pre _callback = function ( data ) {
return self . load _feed _precallback ( data , feed _id , callback , first _load ) ;
} ;
2011-02-04 09:56:15 -05:00
this . feed _id = feed _id ;
2010-06-08 11:19:41 -04:00
if ( feed _id ) {
2011-04-21 10:44:50 -04:00
this . make _request ( '/reader/feed/' + feed _id ,
2010-06-08 11:19:41 -04:00
{
2010-10-25 20:20:59 -04:00
page : page ,
2012-07-18 20:19:54 -07:00
feed _address : this . feeds . get ( feed _id ) . get ( 'feed_address' ) ,
order : this . view _setting ( feed _id , 'order' ) ,
2012-12-19 14:21:46 -08:00
read _filter : this . view _setting ( feed _id , 'read_filter' ) ,
query : NEWSBLUR . reader . flags . search
2010-06-08 11:19:41 -04:00
} , pre _callback ,
2011-11-15 18:19:09 -08:00
error _callback ,
2010-06-08 11:19:41 -04:00
{
2011-04-21 10:44:50 -04:00
'ajax_group' : ( page > 1 ? 'feed_page' : 'feed' ) ,
2011-04-20 09:35:59 -04:00
'request_type' : 'GET'
2010-06-08 11:19:41 -04:00
}
) ;
}
} ,
load _feed _precallback : function ( data , feed _id , callback , first _load ) {
2010-12-15 16:10:54 -05:00
var self = this ;
2011-01-14 00:59:51 -05:00
if ( data . dupe _feed _id && this . feed _id == data . dupe _feed _id ) {
feed _id = data . dupe _feed _id ;
}
2011-02-04 09:56:15 -05:00
if ( feed _id == this . feed _id ) {
2012-01-26 18:59:40 -08:00
if ( data . feeds ) {
2012-05-21 20:08:27 -07:00
this . feeds . add ( data . feeds ) ;
2012-01-26 18:59:40 -08:00
}
2012-05-29 11:48:40 -07:00
if ( data . classifiers ) {
2012-12-12 09:02:35 -08:00
if ( _ . string . include ( feed _id , ':' ) ) { // is_river or is_social
2012-05-29 11:48:40 -07:00
_ . extend ( this . classifiers , data . classifiers ) ;
} else {
this . classifiers [ feed _id ] = _ . extend ( { } , this . defaults [ 'classifiers' ] , data . classifiers ) ;
}
}
if ( data . stories && ! data . stories . length ) {
2012-05-25 16:42:41 -07:00
this . flags [ 'no_more_stories' ] = true ;
}
2012-05-29 11:48:40 -07:00
2012-06-05 16:18:30 -07:00
if ( data . user _profiles ) {
var profiles = _ . reject ( data . user _profiles , _ . bind ( function ( profile ) {
return profile . id in this . user _profiles . _byId ;
} , this ) ) ;
this . user _profiles . add ( profiles ) ;
}
2013-01-28 16:13:12 -08:00
if ( data . updated ) {
var feed = this . get _feed ( feed _id ) ;
feed . set ( 'updated' , data . updated ) ;
}
2012-05-29 11:48:40 -07:00
if ( data . stories && first _load ) {
2011-02-27 19:42:22 -05:00
this . feed _tags = data . feed _tags || { } ;
this . feed _authors = data . feed _authors || { } ;
2012-05-24 11:54:10 -07:00
this . active _feed = this . get _feed ( feed _id ) ;
if ( this . active _feed ) {
this . active _feed . set ( {
feed _title : data . feed _title || this . active _feed . get ( 'feed_title' ) ,
updated : data . updated || this . active _feed . get ( 'updated' ) ,
feed _address : data . feed _address || this . active _feed . get ( 'feed_address' )
} , { silent : true } ) ;
if ( this . active _feed . hasChanged ( ) ) {
this . active _feed . change ( ) ;
}
2012-05-21 20:08:27 -07:00
}
2011-02-04 09:56:15 -05:00
this . feed _id = feed _id ;
this . starred _stories = data . starred _stories ;
2012-05-25 16:42:41 -07:00
this . stories . reset ( data . stories , { added : data . stories . length } ) ;
2012-05-29 11:48:40 -07:00
} else if ( data . stories ) {
2012-05-25 16:42:41 -07:00
this . stories . add ( data . stories , { silent : true } ) ;
this . stories . trigger ( 'add' , { added : data . stories . length } ) ;
2011-02-04 09:56:15 -05:00
}
2012-06-05 16:18:30 -07:00
2011-02-04 09:56:15 -05:00
$ . isFunction ( callback ) && callback ( data , first _load ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2010-12-02 11:09:09 -05:00
2011-03-04 12:27:31 -05:00
load _canonical _feed : function ( feed _id , callback ) {
var pre _callback = _ . bind ( function ( data ) {
2012-07-30 16:10:17 -07:00
var feed = this . feeds . get ( data . id ) ;
if ( feed ) {
feed . set ( data ) ;
} else {
this . feeds . add ( data ) ;
}
2011-03-04 12:27:31 -05:00
this . feed _tags = data . feed _tags || { } ;
this . feed _authors = data . feed _authors || { } ;
this . feed _id = feed _id ;
2011-10-24 08:55:28 -07:00
this . classifiers [ feed _id ] = data . classifiers || this . defaults [ 'classifiers' ] ;
2011-03-04 12:27:31 -05:00
callback && callback ( ) ;
} , this ) ;
2013-02-22 16:02:45 -08:00
this . make _request ( '/rss_feeds/feed/' + feed _id , { } , pre _callback , $ . noop , {
request _type : 'GET'
} ) ;
2011-03-04 12:27:31 -05:00
} ,
2011-11-15 18:19:09 -08:00
fetch _starred _stories : function ( page , callback , error _callback , first _load ) {
2010-12-02 20:18:33 -05:00
var self = this ;
var pre _callback = function ( data ) {
2010-12-10 15:26:50 -05:00
return self . load _feed _precallback ( data , 'starred' , callback , first _load ) ;
2010-12-02 20:18:33 -05:00
} ;
2011-02-04 09:56:15 -05:00
this . feed _id = 'starred' ;
2010-12-02 20:18:33 -05:00
2011-04-20 09:35:59 -04:00
this . make _request ( '/reader/starred_stories' , {
2012-12-19 14:21:46 -08:00
page : page ,
query : NEWSBLUR . reader . flags . search
2011-11-15 18:19:09 -08:00
} , pre _callback , error _callback , {
2011-04-20 09:35:59 -04:00
'ajax_group' : ( page ? 'feed_page' : 'feed' ) ,
'request_type' : 'GET'
2010-12-10 15:26:50 -05:00
} ) ;
} ,
2011-11-15 18:19:09 -08:00
fetch _river _stories : function ( feed _id , feeds , page , callback , error _callback , first _load ) {
2010-12-10 15:26:50 -05:00
var self = this ;
var pre _callback = function ( data ) {
2012-06-19 17:50:01 -07:00
self . load _feed _precallback ( data , feed _id , callback , first _load ) ;
if ( NEWSBLUR . reader . flags [ 'non_premium_river_view' ] ) {
var visible _stories = self . stories . visible ( ) . length ;
var max _stories = NEWSBLUR . reader . constants . RIVER _STORIES _FOR _STANDARD _ACCOUNT ;
2012-07-10 15:26:34 -07:00
NEWSBLUR . log ( [ "checking no more stories" , visible _stories , max _stories ] ) ;
2012-06-19 17:50:01 -07:00
if ( visible _stories >= max _stories ) {
self . flags [ 'no_more_stories' ] = true ;
self . stories . trigger ( 'no_more_stories' ) ;
}
}
2010-12-10 15:26:50 -05:00
} ;
2010-12-15 16:10:54 -05:00
2011-02-04 09:56:15 -05:00
this . feed _id = feed _id ;
2011-04-20 09:35:59 -04:00
this . make _request ( '/reader/river_stories' , {
2010-12-10 15:26:50 -05:00
feeds : feeds ,
2010-12-15 16:10:54 -05:00
page : page ,
2013-01-10 12:06:57 -08:00
order : this . view _setting ( feed _id , 'order' ) ,
read _filter : this . view _setting ( feed _id , 'read_filter' )
2011-11-15 18:19:09 -08:00
} , pre _callback , error _callback , {
2012-08-07 14:37:07 -07:00
'ajax_group' : ( page ? 'feed_page' : 'feed' ) ,
'request_type' : 'GET'
} ) ;
} ,
2012-11-30 14:28:55 -08:00
fetch _river _blurblogs _stories : function ( feed _id , page , options , callback , error _callback , first _load ) {
2012-08-07 14:37:07 -07:00
var self = this ;
var pre _callback = function ( data ) {
self . load _feed _precallback ( data , feed _id , callback , first _load ) ;
if ( NEWSBLUR . reader . flags [ 'non_premium_river_view' ] ) {
var visible _stories = self . stories . visible ( ) . length ;
var max _stories = NEWSBLUR . reader . constants . RIVER _STORIES _FOR _STANDARD _ACCOUNT ;
NEWSBLUR . log ( [ "checking no more stories" , visible _stories , max _stories ] ) ;
if ( visible _stories >= max _stories ) {
self . flags [ 'no_more_stories' ] = true ;
self . stories . trigger ( 'no_more_stories' ) ;
}
}
} ;
this . feed _id = feed _id ;
this . make _request ( '/social/river_stories' , {
page : page ,
2012-11-30 14:28:55 -08:00
order : this . view _setting ( feed _id , 'order' ) ,
global _feed : options . global
2012-08-07 14:37:07 -07:00
// read_filter: this.view_setting(feed_id, 'read_filter')
} , pre _callback , error _callback , {
2011-04-20 09:35:59 -04:00
'ajax_group' : ( page ? 'feed_page' : 'feed' ) ,
'request_type' : 'GET'
2010-12-02 11:09:09 -05:00
} ) ;
} ,
2012-05-25 16:42:41 -07:00
fetch _social _stories : function ( feed _id , page , callback , error _callback , first _load ) {
2012-01-25 09:52:34 -08:00
var self = this ;
var pre _callback = function ( data ) {
return self . load _feed _precallback ( data , feed _id , callback , first _load ) ;
} ;
this . feed _id = feed _id ;
2012-05-25 16:42:41 -07:00
var user _id = this . get _feed ( feed _id ) . get ( 'user_id' ) ;
2012-01-25 09:52:34 -08:00
this . make _request ( '/social/stories/' + user _id + '/' , {
2012-07-18 20:19:54 -07:00
page : page ,
order : this . view _setting ( feed _id , 'order' ) ,
read _filter : this . view _setting ( feed _id , 'read_filter' )
2012-01-25 09:52:34 -08:00
} , pre _callback , error _callback , {
'ajax_group' : ( page > 1 ? 'feed_page' : 'feed' ) ,
'request_type' : 'GET'
} ) ;
} ,
2010-09-17 12:40:42 -04:00
get _feeds _trainer : function ( feed _id , callback ) {
2010-08-01 19:12:42 -04:00
var self = this ;
2010-09-21 19:07:36 -04:00
var params = { } ;
if ( feed _id ) {
params [ 'feed_id' ] = feed _id ;
}
2010-08-01 19:12:42 -04:00
2011-04-24 21:27:31 -04:00
this . make _request ( '/reader/feeds_trainer' , params , callback , null , { 'ajax_group' : 'feed' , 'request_type' : 'GET' } ) ;
2010-08-01 19:12:42 -04:00
} ,
2012-02-13 11:07:32 -08:00
get _social _trainer : function ( feed _id , callback ) {
var self = this ;
var params = { } ;
if ( feed _id ) {
params [ 'user_id' ] = feed _id . replace ( 'social:' , '' ) ;
}
this . make _request ( '/social/feed_trainer' , params , callback , null , { 'ajax_group' : 'feed' , 'request_type' : 'GET' } ) ;
} ,
2010-10-29 11:34:33 -04:00
retrain _all _sites : function ( callback ) {
var self = this ;
var params = { } ;
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/retrain_all_sites' , params , callback , null ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
} ,
2012-01-08 14:15:22 -08:00
refresh _feeds : function ( callback , has _unfetched _feeds , feed _id , error _callback ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-08-11 22:02:47 -04:00
var pre _callback = function ( data ) {
2011-02-06 15:04:21 -05:00
self . post _refresh _feeds ( data , callback ) ;
2010-06-08 11:19:41 -04:00
} ;
2010-08-11 22:02:47 -04:00
var data = { } ;
if ( has _unfetched _feeds ) {
data [ 'check_fetch_status' ] = has _unfetched _feeds ;
}
2011-01-30 21:40:00 -05:00
if ( this . flags [ 'favicons_fetching' ] ) {
2012-05-21 20:08:27 -07:00
var favicons _fetching = _ . pluck ( this . feeds . select ( function ( feed , k ) {
return feed . get ( 'favicon_fetching' ) && feed . get ( 'active' ) ;
} ) , 'id' ) ;
2011-01-30 21:40:00 -05:00
if ( favicons _fetching . length ) {
data [ 'favicons_fetching' ] = favicons _fetching ;
2011-11-30 21:27:55 -08:00
} else {
this . flags [ 'favicons_fetching' ] = false ;
2011-01-30 21:40:00 -05:00
}
}
2011-03-09 09:48:24 -05:00
if ( feed _id ) {
data [ 'feed_id' ] = feed _id ;
}
2010-08-11 22:02:47 -04:00
2011-04-23 18:22:52 -04:00
if ( NEWSBLUR . Globals . is _authenticated || feed _id ) {
2012-01-08 14:15:22 -08:00
this . make _request ( '/reader/refresh_feeds' , data , pre _callback , error _callback ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2012-10-22 17:07:57 -07:00
feed _unread _count : function ( feed _id , callback , error _callback ) {
var self = this ;
var pre _callback = function ( data ) {
self . post _refresh _feeds ( data , callback ) ;
} ;
if ( NEWSBLUR . Globals . is _authenticated || feed _id ) {
this . make _request ( '/reader/feed_unread_count' , {
'feed_id' : feed _id
} , pre _callback , error _callback ) ;
}
} ,
2011-02-06 15:04:21 -05:00
post _refresh _feeds : function ( data , callback ) {
2012-03-30 16:03:07 -07:00
if ( ! data . feeds ) return ;
2012-05-21 20:08:27 -07:00
_ . each ( data . feeds , _ . bind ( function ( feed , feed _id ) {
var existing _feed = this . feeds . get ( feed _id ) ;
if ( ! existing _feed ) return ;
var feed _id = feed . id || feed _id ;
2012-05-22 17:39:21 -07:00
2012-05-21 20:08:27 -07:00
if ( feed . id && feed _id != feed . id ) {
2012-05-22 13:25:21 -07:00
NEWSBLUR . log ( [ 'Dupe feed being refreshed' , feed _id , feed . id , this . feeds . get ( f ) , feed ] ) ;
2012-05-21 20:08:27 -07:00
this . feeds . get ( feed . id ) . set ( feed ) ;
2011-02-06 15:04:21 -05:00
}
2012-05-21 20:08:27 -07:00
if ( ( feed [ 'has_exception' ] && ! existing _feed . get ( 'has_exception' ) ) ||
( existing _feed . get ( 'has_exception' ) && ! feed [ 'has_exception' ] ) ) {
existing _feed . set ( 'has_exception' , ! ! feed [ 'has_exception' ] ) ;
2012-01-02 14:47:19 -08:00
}
2012-05-21 20:08:27 -07:00
if ( feed [ 'favicon' ] && existing _feed . get ( 'favicon' ) != feed [ 'favicon' ] ) {
2012-05-22 17:39:21 -07:00
existing _feed . set ( {
'favicon' : feed [ 'favicon' ] ,
'favicon_color' : feed [ 'favicon_color' ] ,
'favicon_fetching' : false
} ) ;
2011-02-06 15:04:21 -05:00
}
2012-05-22 17:39:21 -07:00
existing _feed . set ( feed ) ;
2012-05-21 20:08:27 -07:00
} , this ) ) ;
2012-04-03 17:48:24 -07:00
_ . each ( data . social _feeds , _ . bind ( function ( feed ) {
var social _feed = this . social _feeds . get ( feed . id ) ;
if ( ! social _feed ) return ;
2012-05-22 17:39:21 -07:00
social _feed . set ( feed ) ;
2012-04-03 17:48:24 -07:00
} , this ) ) ;
2012-12-28 21:42:52 -08:00
callback && callback ( data ) ;
2011-02-06 15:04:21 -05:00
} ,
2011-04-21 10:44:50 -04:00
refresh _feed : function ( feed _id , callback ) {
2010-06-08 11:19:41 -04:00
var self = this ;
var pre _callback = function ( data ) {
// NEWSBLUR.log(['refresh_feed pre_callback', data]);
self . load _feed _precallback ( data , feed _id , callback ) ;
} ;
// NEWSBLUR.log(['refresh_feed', feed_id, page, first_load, callback, pre_callback]);
if ( feed _id ) {
2011-04-21 10:44:50 -04:00
this . make _request ( '/reader/feed/' + feed _id ,
2010-06-08 11:19:41 -04:00
{
page : 0 ,
2012-05-22 13:25:21 -07:00
feed _address : this . feeds . get ( feed _id ) . get ( 'feed_address' )
2010-06-08 11:19:41 -04:00
} , pre _callback ,
null ,
{
2011-04-20 09:35:59 -04:00
'ajax_group' : 'feed_page' ,
'request_type' : 'GET'
2010-06-08 11:19:41 -04:00
}
) ;
}
} ,
2013-02-04 16:16:03 -08:00
interactions _count : function ( callback , error _callback ) {
this . make _request ( '/reader/interactions_count' , { } , callback , error _callback , {
'request_type' : 'GET'
} ) ;
} ,
2010-08-11 22:02:47 -04:00
count _unfetched _feeds : function ( ) {
2012-05-21 20:08:27 -07:00
var counts = this . feeds . reduce ( function ( counts , feed ) {
if ( feed . get ( 'active' ) ) {
2012-05-22 17:39:21 -07:00
if ( feed . get ( 'fetched_once' ) || feed . get ( 'has_exception' ) ) {
2010-10-02 17:05:55 -04:00
counts [ 'fetched_feeds' ] += 1 ;
2012-03-30 16:03:07 -07:00
} else {
counts [ 'unfetched_feeds' ] += 1 ;
2010-10-02 17:05:55 -04:00
}
2010-08-11 22:02:47 -04:00
}
2012-05-21 20:08:27 -07:00
return counts ;
} , {
'unfetched_feeds' : 0 ,
'fetched_feeds' : 0
} ) ;
2010-08-11 22:02:47 -04:00
return counts ;
} ,
2012-06-19 13:01:30 -07:00
unfetched _feeds : function ( ) {
return this . feeds . filter ( function ( feed ) {
return feed . get ( 'active' ) && ! feed . get ( 'fetched_once' ) && ! feed . get ( 'has_exception' ) ;
} ) ;
} ,
2012-04-19 22:38:00 -07:00
set _feed : function ( feed _id , feed ) {
if ( ! feed ) {
feed = feed _id ;
feed _id = feed . id ;
}
2012-06-13 11:51:49 -07:00
if ( ! this . feeds . get ( feed ) ) {
this . feeds . add ( feed ) ;
} else {
this . feeds . get ( feed _id ) . set ( feed ) ;
}
return this . feeds . get ( feed _id ) ;
2012-03-14 12:38:59 -07:00
} ,
add _social _feed : function ( feed ) {
2012-03-15 14:00:44 -07:00
var social _feed = this . social _feeds . get ( feed ) ;
2012-03-14 17:48:28 -07:00
if ( ! social _feed ) {
2012-04-16 11:21:52 -07:00
var attributes = feed . attributes ;
if ( ! attributes ) attributes = feed ;
social _feed = new NEWSBLUR . Models . SocialSubscription ( attributes ) ;
2012-03-14 17:48:28 -07:00
this . social _feeds . add ( social _feed ) ;
2012-03-14 12:38:59 -07:00
}
2012-03-14 17:48:28 -07:00
return social _feed ;
2011-03-15 23:42:27 -04:00
} ,
2010-06-08 11:19:41 -04:00
get _feed : function ( feed _id ) {
var self = this ;
2012-01-26 08:43:46 -08:00
if ( _ . string . include ( feed _id , 'social:' ) ) {
2012-05-21 14:36:54 -07:00
return this . social _feeds . get ( feed _id ) ;
2012-01-26 08:43:46 -08:00
} else {
2012-05-19 10:29:27 -07:00
return this . feeds . get ( feed _id ) ;
2012-01-26 08:43:46 -08:00
}
2010-06-08 11:19:41 -04:00
} ,
2012-08-08 11:52:59 -07:00
get _friend _feeds : function ( story ) {
2012-08-09 19:45:08 -07:00
var shares = story . get ( 'shared_by_friends' ) || [ ] ;
var comments = story . get ( 'commented_by_friends' ) || [ ] ;
var friend _user _ids = shares . concat ( comments ) ;
2012-08-08 22:02:05 -07:00
return _ . map ( friend _user _ids , _ . bind ( function ( user _id ) {
2012-08-08 11:52:59 -07:00
return this . social _feeds . get ( 'social:' + user _id ) ;
} , this ) ) ;
} ,
2010-06-08 11:19:41 -04:00
get _feeds : function ( ) {
var self = this ;
return this . feeds ;
} ,
get _folders : function ( ) {
var self = this ;
return this . folders ;
} ,
2012-08-02 12:27:15 -07:00
get _folder : function ( folder _name ) {
return this . folders . find _folder ( folder _name . toLowerCase ( ) ) ;
} ,
2010-06-08 11:19:41 -04:00
get _feed _tags : function ( ) {
return this . feed _tags ;
} ,
get _feed _authors : function ( ) {
return this . feed _authors ;
} ,
2012-05-24 17:32:01 -07:00
get _story : function ( story _id ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2012-05-24 17:32:01 -07:00
return this . stories . get ( story _id ) ;
2010-06-08 11:19:41 -04:00
} ,
2012-04-04 20:54:54 -07:00
get _user : function ( user _id ) {
var user = this . user _profiles . find ( user _id ) ;
if ( ! user && user _id == this . user _profile . get ( 'user_id' ) ) {
user = this . profile ;
}
return user ;
} ,
2011-04-24 01:52:44 -04:00
save _classifier : function ( data , callback ) {
2010-08-11 23:02:17 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
2011-04-24 01:52:44 -04:00
this . make _request ( '/classifier/save' , data , callback ) ;
2010-08-11 23:02:17 -04:00
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
2010-06-08 11:19:41 -04:00
} ,
get _feed _classifier : function ( feed _id , callback ) {
2011-04-24 01:52:44 -04:00
this . make _request ( '/classifier/' + feed _id , { } , callback , null , {
2011-04-20 09:35:59 -04:00
'ajax_group' : 'feed' ,
'request_type' : 'GET'
2010-06-08 11:19:41 -04:00
} ) ;
} ,
2012-05-23 12:10:35 -07:00
delete _feed : function ( feed _id , in _folder , callback ) {
2010-08-11 23:02:17 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
2010-09-14 20:49:28 -04:00
this . make _request ( '/reader/delete_feed' , {
'feed_id' : feed _id ,
'in_folder' : in _folder
} , callback , null ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
} ,
2012-03-19 15:46:59 -07:00
delete _feed _by _url : function ( url , in _folder , callback ) {
this . make _request ( '/reader/delete_feed_by_url/' , {
'url' : url ,
'in_folder' : in _folder || ''
} , callback , function ( ) {
callback ( { 'message' : NEWSBLUR . Globals . is _anonymous ? 'Please create an account. Not much to do without an account.' : 'There was a problem trying to add this site. Please try a different URL.' } ) ;
} ) ;
} ,
2010-09-22 10:12:38 -04:00
delete _folder : function ( folder _name , in _folder , feeds , callback ) {
2010-09-14 20:49:28 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
2010-09-16 10:35:36 -04:00
this . make _request ( '/reader/delete_folder' , {
'folder_name' : folder _name ,
2010-09-22 10:12:38 -04:00
'in_folder' : in _folder ,
'feed_id' : feeds
2010-09-16 10:35:36 -04:00
} , callback , null ) ;
2010-08-11 23:02:17 -04:00
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
2010-12-11 14:02:37 -05:00
} ,
2010-12-11 15:26:45 -05:00
rename _feed : function ( feed _id , feed _title , callback ) {
2010-12-11 14:02:37 -05:00
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/rename_feed' , {
'feed_id' : feed _id ,
2010-12-11 15:26:45 -05:00
'feed_title' : feed _title
2010-12-11 14:02:37 -05:00
} , callback , null ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
} ,
rename _folder : function ( folder _name , new _folder _name , in _folder , callback ) {
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/rename_folder' , {
'folder_name' : folder _name ,
'new_folder_name' : new _folder _name ,
'in_folder' : in _folder
} , callback , null ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
2010-06-08 11:19:41 -04:00
} ,
2012-03-19 15:46:59 -07:00
save _add _url : function ( url , folder , callback , options ) {
options = _ . extend ( { 'auto_active' : true } , options ) ;
2010-06-08 11:19:41 -04:00
this . make _request ( '/reader/add_url/' , {
'url' : url ,
2012-03-19 15:46:59 -07:00
'folder' : folder ,
'auto_active' : options . auto _active
2013-01-25 15:07:27 -08:00
} , callback , function ( data ) {
callback ( { 'message' : NEWSBLUR . Globals . is _anonymous ? 'Please create an account. Not much to do without an account.' : data . message || 'There was a problem trying to add this site. Please try a different URL.' } ) ;
2011-02-24 18:51:30 -05:00
} ) ;
2010-06-08 11:19:41 -04:00
} ,
save _add _folder : function ( folder , parent _folder , callback ) {
this . make _request ( '/reader/add_folder/' , {
'folder' : folder ,
'parent_folder' : parent _folder
2013-01-25 15:16:18 -08:00
} , callback , function ( data ) {
callback ( { 'message' : NEWSBLUR . Globals . is _anonymous ? 'Please create an account. Not much to do without an account.' : data . message || 'There was a problem trying to add this folder.' } ) ;
2011-02-24 18:51:30 -05:00
} ) ;
2010-06-08 11:19:41 -04:00
} ,
2011-11-07 20:50:46 -08:00
move _feed _to _folder : function ( feed _id , in _folder , to _folder , callback ) {
var pre _callback = _ . bind ( function ( data ) {
2013-01-22 09:06:12 -08:00
this . folders . reset ( _ . compact ( data . folders ) , { parse : true } ) ;
2011-11-07 20:50:46 -08:00
return callback ( ) ;
} , this ) ;
2011-09-25 13:18:19 -07:00
this . make _request ( '/reader/move_feed_to_folder' , {
'feed_id' : feed _id ,
'in_folder' : in _folder ,
2011-11-07 20:50:46 -08:00
'to_folder' : to _folder
} , pre _callback ) ;
2011-09-25 13:18:19 -07:00
} ,
2011-11-08 09:20:10 -08:00
move _folder _to _folder : function ( folder _name , in _folder , to _folder , callback ) {
var pre _callback = _ . bind ( function ( data ) {
2013-01-22 09:06:12 -08:00
this . folders . reset ( _ . compact ( data . folders ) , { parse : true } ) ;
2011-11-08 09:20:10 -08:00
return callback ( ) ;
} , this ) ;
this . make _request ( '/reader/move_folder_to_folder' , {
'folder_name' : folder _name ,
'in_folder' : in _folder ,
'to_folder' : to _folder
} , pre _callback ) ;
} ,
2010-06-11 20:55:38 -04:00
preference : function ( preference , value , callback ) {
if ( typeof value == 'undefined' ) {
2010-12-08 20:53:45 -05:00
var pref = NEWSBLUR . Preferences [ preference ] ;
if ( ( /\d+/ ) . test ( pref ) ) return parseInt ( pref , 10 ) ;
return pref ;
2010-06-11 20:55:38 -04:00
}
2010-08-18 20:35:45 -04:00
if ( NEWSBLUR . Preferences [ preference ] == value ) {
return $ . isFunction ( callback ) && callback ( ) ;
}
2010-07-06 14:57:32 -04:00
NEWSBLUR . Preferences [ preference ] = value ;
2010-11-05 10:35:52 -04:00
var preferences = { } ;
preferences [ preference ] = value ;
2012-07-22 23:27:27 -07:00
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/profile/set_preference' , preferences , callback , null ) ;
} else {
if ( callback ) callback ( ) ;
}
2010-10-30 00:27:52 -04:00
} ,
save _preferences : function ( preferences , callback ) {
_ . each ( preferences , function ( value , preference ) {
NEWSBLUR . Preferences [ preference ] = value ;
} ) ;
2010-11-05 10:35:52 -04:00
this . make _request ( '/profile/set_preference' , preferences , callback , null ) ;
2010-06-14 01:01:21 -04:00
} ,
2011-07-27 22:17:34 -07:00
save _account _settings : function ( settings , callback ) {
2012-04-20 08:45:29 -07:00
var self = this ;
this . make _request ( '/profile/set_account_settings' , settings , function ( data ) {
if ( data . social _profile ) {
self . user _profile . set ( data . social _profile ) ;
}
callback ( data ) ;
} , null ) ;
2011-07-27 22:17:34 -07:00
} ,
2012-07-18 20:19:54 -07:00
view _setting : function ( feed _id , setting , callback ) {
if ( _ . isUndefined ( setting ) || _ . isString ( setting ) ) {
setting = setting || 'view' ;
var s = setting . substr ( 0 , 1 ) ;
var feed = NEWSBLUR . Preferences . view _settings [ feed _id + '' ] ;
var default _setting = NEWSBLUR . Preferences [ 'default_' + setting ] ;
if ( setting == 'read_filter' && _ . string . contains ( feed _id , 'river:' ) ) {
default _setting = 'unread' ;
}
return feed && feed [ s ] || default _setting ;
2010-07-06 14:57:32 -04:00
}
2012-07-18 20:19:54 -07:00
var view _settings = _ . clone ( NEWSBLUR . Preferences . view _settings [ feed _id + '' ] ) || { } ;
if ( _ . isString ( view _settings ) ) {
view _settings = { 'view' : view _settings } ;
}
var params = { 'feed_id' : feed _id + '' } ;
_ . each ( [ 'view' , 'order' , 'read_filter' ] , function ( facet ) {
if ( setting [ facet ] ) {
view _settings [ facet . substr ( 0 , 1 ) ] = setting [ facet ] ;
params [ 'feed_' + facet + '_setting' ] = setting [ facet ] ;
}
} ) ;
if ( ! _ . isEqual ( NEWSBLUR . Preferences . view _settings [ feed _id + '' ] , view _settings ) ) {
NEWSBLUR . Preferences . view _settings [ feed _id + '' ] = view _settings ;
this . make _request ( '/profile/set_view_setting' , params , callback , null ) ;
return true ;
}
2010-07-06 14:57:32 -04:00
} ,
2010-09-05 18:08:08 -07:00
collapsed _folders : function ( folder _title , is _collapsed , callback ) {
var folders = NEWSBLUR . Preferences . collapsed _folders ;
var changed = false ;
2010-10-30 00:27:52 -04:00
if ( is _collapsed && ! _ . contains ( NEWSBLUR . Preferences . collapsed _folders , folder _title ) ) {
2010-09-05 18:08:08 -07:00
NEWSBLUR . Preferences . collapsed _folders . push ( folder _title ) ;
changed = true ;
2010-10-21 13:48:08 -04:00
} else if ( ! is _collapsed && _ . contains ( NEWSBLUR . Preferences . collapsed _folders , folder _title ) ) {
2010-09-05 18:08:08 -07:00
NEWSBLUR . Preferences . collapsed _folders = _ . without ( folders , folder _title ) ;
changed = true ;
}
2011-03-30 09:30:45 -04:00
if ( changed ) {
this . make _request ( '/profile/set_collapsed_folders' , {
'collapsed_folders' : $ . toJSON ( NEWSBLUR . Preferences . collapsed _folders )
} , callback , null ) ;
}
2010-09-05 18:08:08 -07:00
} ,
2010-06-14 01:01:21 -04:00
save _mark _read : function ( days , callback ) {
2010-11-05 10:35:52 -04:00
this . make _request ( '/reader/mark_all_as_read' , { 'days' : days } , callback ) ;
2010-06-30 12:17:22 -04:00
} ,
get _features _page : function ( page , callback ) {
2011-04-20 09:35:59 -04:00
this . make _request ( '/reader/features' , { 'page' : page } , callback , callback , { request _type : 'GET' } ) ;
2010-07-11 11:10:45 -04:00
} ,
2011-07-11 18:22:28 -07:00
load _recommended _feed : function ( page , refresh , unmoderated , callback , error _callback ) {
2011-04-09 11:13:02 -04:00
this . make _request ( '/recommendations/load_recommended_feed' , {
2011-07-11 18:22:28 -07:00
'page' : page ,
'refresh' : refresh ,
'unmoderated' : unmoderated
2011-04-20 09:35:59 -04:00
} , callback , error _callback , { request _type : 'GET' } ) ;
2011-03-13 16:24:49 -04:00
} ,
2012-04-12 11:18:56 -07:00
load _interactions _page : function ( page , callback , error _callback ) {
this . make _request ( '/social/interactions' , {
2012-07-09 18:28:11 -07:00
'page' : page ,
'format' : 'html'
2013-01-30 12:09:58 -08:00
} , function ( data ) {
callback ( data , 'interactions' ) ;
} , error _callback , {
'ajax_group' : 'interactions' ,
'request_type' : 'GET'
} ) ;
2012-04-12 11:18:56 -07:00
} ,
load _activities _page : function ( page , callback , error _callback ) {
this . make _request ( '/profile/activities' , {
2012-07-09 18:28:11 -07:00
'page' : page ,
'format' : 'html'
2013-01-30 12:09:58 -08:00
} , function ( data ) {
callback ( data , 'activities' ) ;
} , error _callback , {
'ajax_group' : 'interactions' ,
'request_type' : 'GET'
} ) ;
2012-04-12 11:18:56 -07:00
} ,
2011-07-11 18:44:47 -07:00
approve _feed _in _moderation _queue : function ( feed _id , date , callback ) {
2011-07-11 18:22:28 -07:00
this . make _request ( '/recommendations/approve_feed' , {
'feed_id' : feed _id ,
2011-07-11 18:44:47 -07:00
'date' : date ,
2011-07-11 18:22:28 -07:00
'unmoderated' : true
} , callback , { request _type : 'GET' } ) ;
} ,
decline _feed _in _moderation _queue : function ( feed _id , callback ) {
this . make _request ( '/recommendations/decline_feed' , {
'feed_id' : feed _id ,
'unmoderated' : true
} , callback , { request _type : 'GET' } ) ;
} ,
2011-04-24 22:47:20 -04:00
load _dashboard _graphs : function ( callback , error _callback ) {
this . make _request ( '/statistics/dashboard_graphs' , { } , callback , error _callback , { request _type : 'GET' } ) ;
2011-12-18 18:03:40 -08:00
} ,
load _feedback _table : function ( callback , error _callback ) {
this . make _request ( '/statistics/feedback_table' , { } , callback , error _callback , { request _type : 'GET' } ) ;
2011-04-24 22:47:20 -04:00
} ,
2010-07-11 11:10:45 -04:00
save _feed _order : function ( folders , callback ) {
2010-11-05 10:35:52 -04:00
this . make _request ( '/reader/save_feed_order' , { 'folders' : $ . toJSON ( folders ) } , callback ) ;
2010-07-25 23:13:27 -04:00
} ,
get _feed _statistics : function ( feed _id , callback ) {
2011-04-24 00:05:39 -04:00
this . make _request ( '/rss_feeds/statistics/' + feed _id , { } , callback , callback , {
2011-04-20 09:35:59 -04:00
'ajax_group' : 'statistics' ,
2012-01-02 16:33:13 -08:00
'request_type' : 'GET'
2010-07-25 23:13:27 -04:00
} ) ;
2010-08-17 23:40:03 -04:00
} ,
2012-02-16 18:36:52 -08:00
get _social _statistics : function ( social _feed _id , callback ) {
this . make _request ( '/social/statistics/' + _ . string . ltrim ( social _feed _id , 'social:' ) , { } , callback , callback , {
'ajax_group' : 'statistics' ,
'request_type' : 'GET'
} ) ;
} ,
2011-04-07 10:30:05 -04:00
get _feed _recommendation _info : function ( feed _id , callback ) {
2011-04-24 00:05:39 -04:00
this . make _request ( '/recommendations/load_feed_info/' + feed _id , { } , callback , callback , {
2011-04-20 09:35:59 -04:00
'ajax_group' : 'statistics' ,
'request_type' : 'GET'
2011-04-07 10:30:05 -04:00
} ) ;
} ,
2011-11-12 18:19:57 -08:00
get _feed _settings : function ( feed _id , callback ) {
this . make _request ( '/rss_feeds/feed_settings/' + feed _id , { } , callback , callback , {
'ajax_group' : 'statistics' ,
'request_type' : 'GET'
} ) ;
} ,
2012-02-16 18:36:52 -08:00
get _social _settings : function ( social _feed _id , callback ) {
this . make _request ( '/social/settings/' + _ . string . ltrim ( social _feed _id , 'social:' ) , { } , callback , callback , {
'ajax_group' : 'statistics' ,
'request_type' : 'GET'
} ) ;
} ,
2010-08-17 23:40:03 -04:00
start _import _from _google _reader : function ( callback ) {
this . make _request ( '/import/import_from_google_reader/' , { } , callback ) ;
2010-08-25 10:18:08 -04:00
} ,
2011-04-07 10:30:05 -04:00
save _recommended _site : function ( data , callback ) {
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/recommendations/save_recommended_feed' , data , callback ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
} ,
2012-01-08 14:15:22 -08:00
save _exception _retry : function ( feed _id , callback , error _callback ) {
2010-08-25 10:18:08 -04:00
var self = this ;
2011-02-06 15:04:21 -05:00
var pre _callback = function ( data ) {
// NEWSBLUR.log(['refresh_feed pre_callback', data]);
self . post _refresh _feeds ( data , callback ) ;
} ;
2011-04-23 18:22:52 -04:00
this . make _request ( '/rss_feeds/exception_retry' , {
'feed_id' : feed _id ,
2012-05-22 13:25:21 -07:00
'reset_fetch' : ! ! ( this . feeds . get ( feed _id ) . get ( 'has_feed_exception' ) ||
this . feeds . get ( feed _id ) . get ( 'has_page_exception' ) )
2012-01-08 14:15:22 -08:00
} , pre _callback , error _callback ) ;
2010-08-25 20:43:35 -04:00
} ,
2012-04-06 16:21:16 -07:00
save _exception _change _feed _link : function ( feed _id , feed _link , callback , error _callback ) {
2010-08-25 20:43:35 -04:00
var self = this ;
2011-02-06 15:04:21 -05:00
2010-08-25 20:43:35 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/rss_feeds/exception_change_feed_link' , {
'feed_id' : feed _id ,
'feed_link' : feed _link
2012-04-06 16:21:16 -07:00
} , function ( data ) {
// NEWSBLUR.log(['save_exception_change_feed_link pre_callback', feed_id, feed_link, data]);
2012-12-28 21:42:52 -08:00
if ( data . code < 0 || data . status _code != 200 ) {
return callback ( data ) ;
}
2012-04-06 16:21:16 -07:00
self . post _refresh _feeds ( data , callback ) ;
} , error _callback ) ;
2010-08-25 20:43:35 -04:00
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
} ,
2012-04-06 16:21:16 -07:00
save _exception _change _feed _address : function ( feed _id , feed _address , callback , error _callback ) {
2010-08-25 20:43:35 -04:00
var self = this ;
2011-02-06 15:04:21 -05:00
2010-08-25 20:43:35 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/rss_feeds/exception_change_feed_address' , {
'feed_id' : feed _id ,
'feed_address' : feed _address
2012-04-06 16:21:16 -07:00
} , function ( data ) {
// NEWSBLUR.log(['save_exception_change_feed_address pre_callback', feed_id, feed_address, data]);
2012-12-28 21:42:52 -08:00
if ( data . code < 0 || data . status _code != 200 ) {
return callback ( data ) ;
}
2012-04-06 16:21:16 -07:00
self . post _refresh _feeds ( data , callback ) ;
} , error _callback ) ;
2010-08-25 10:18:08 -04:00
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
2010-09-28 18:53:57 -04:00
} ,
save _feed _chooser : function ( approved _feeds , callback ) {
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/save_feed_chooser' , {
2010-11-05 20:34:17 -04:00
'approved_feeds' : _ . select ( approved _feeds , function ( f ) { return f ; } )
2010-09-28 18:53:57 -04:00
} , callback ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
2011-02-27 16:13:22 -05:00
} ,
2011-10-28 10:29:11 -07:00
send _story _email : function ( data , callback , error _callback ) {
2011-05-06 10:06:13 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
2011-10-28 10:29:11 -07:00
this . make _request ( '/reader/send_story_email' , data , callback , error _callback , { 'timeout' : 6000 } ) ;
2011-05-06 10:06:13 -04:00
} else {
2011-05-09 10:30:07 -04:00
callback ( { 'code' : - 1 , 'message' : 'You must be logged in to send a story over email.' } ) ;
2011-05-06 10:06:13 -04:00
}
} ,
2011-05-20 00:18:23 -04:00
load _tutorial : function ( data , callback ) {
2012-04-04 16:09:01 -07:00
this . make _request ( '/reader/load_tutorial' , data , callback , null , {
request _type : 'GET'
} ) ;
2011-05-18 22:33:42 -04:00
} ,
2011-12-22 13:36:03 -08:00
fetch _friends : function ( callback ) {
2012-04-04 16:09:01 -07:00
this . make _request ( '/social/load_user_friends' , null , _ . bind ( function ( data ) {
this . user _profile . set ( data . user _profile ) ;
2012-08-14 00:26:42 -07:00
this . social _services = data . services ;
2013-01-14 12:50:00 -08:00
this . follower _profiles . reset ( data . follower _profiles ) ;
this . following _profiles . reset ( data . following _profiles ) ;
2012-01-03 09:29:21 -08:00
callback ( data ) ;
2012-04-04 16:09:01 -07:00
} , this ) , null , {
request _type : 'GET'
} ) ;
2011-12-22 13:36:03 -08:00
} ,
2012-10-24 18:52:24 -07:00
fetch _follow _requests : function ( callback ) {
this . make _request ( '/social/load_follow_requests' , null , _ . bind ( function ( data ) {
this . user _profile . set ( data . user _profile ) ;
callback ( data ) ;
} , this ) , null , {
request _type : 'GET'
} ) ;
} ,
2012-02-22 09:11:35 -08:00
fetch _user _profile : function ( user _id , callback ) {
2012-07-09 12:41:25 -07:00
this . make _request ( '/social/profile' , {
'user_id' : user _id ,
'include_activities_html' : true
} , _ . bind ( function ( data ) {
2012-04-10 17:28:00 -07:00
this . add _user _profiles ( data . profiles ) ;
callback ( data ) ;
} , this ) , callback , {
2012-04-04 16:09:01 -07:00
request _type : 'GET'
} ) ;
2012-02-21 10:06:12 -08:00
} ,
2013-02-22 16:02:45 -08:00
search _for _feeds : function ( query , callback ) {
this . make _request ( '/rss_feeds/feed_autocomplete' , {
'query' : query ,
'format' : 'full' ,
'v' : 2
} , callback , callback , {
ajax _group : 'feed' ,
request _type : 'GET'
} ) ;
} ,
2012-03-13 16:58:50 -07:00
search _for _friends : function ( query , callback ) {
2012-03-20 16:46:38 -07:00
this . make _request ( '/social/find_friends' , { 'query' : query } , callback , callback , {
ajax _group : 'feed' ,
request _type : 'GET'
} ) ;
2012-03-13 16:58:50 -07:00
} ,
2011-12-22 13:36:03 -08:00
disconnect _social _service : function ( service , callback ) {
2012-03-19 11:15:26 -07:00
this . make _request ( '/oauth/' + service + '_disconnect/' , null , callback ) ;
2011-12-22 13:36:03 -08:00
} ,
2012-04-04 16:09:01 -07:00
load _current _user _profile : function ( callback ) {
this . make _request ( '/social/load_user_profile' , null , _ . bind ( function ( data ) {
this . user _profile . set ( data . user _profile ) ;
callback ( data ) ;
} , this ) , null , {
request _type : 'GET'
} ) ;
} ,
2012-01-04 09:42:35 -08:00
save _user _profile : function ( data , callback ) {
2012-04-04 16:09:01 -07:00
this . make _request ( '/social/save_user_profile/' , data , _ . bind ( function ( response ) {
this . user _profile . set ( response . user _profile ) ;
callback ( response ) ;
} , this ) ) ;
2011-12-25 20:50:59 -08:00
} ,
2012-07-10 00:17:45 -07:00
save _blurblog _settings : function ( data , callback ) {
this . make _request ( '/social/save_blurblog_settings/' , data , _ . bind ( function ( response ) {
this . user _profile . set ( response . user _profile ) ;
callback ( response ) ;
} , this ) ) ;
} ,
2012-01-04 09:42:35 -08:00
follow _user : function ( user _id , callback ) {
2012-04-04 16:09:01 -07:00
this . make _request ( '/social/follow' , { 'user_id' : user _id } , _ . bind ( function ( data ) {
2012-07-10 15:26:34 -07:00
NEWSBLUR . log ( [ "follow data" , data ] ) ;
2012-01-04 09:42:35 -08:00
this . user _profile . set ( data . user _profile ) ;
var following _profile = this . following _profiles . detect ( function ( profile ) {
return profile . get ( 'user_id' ) == data . follow _profile . user _id ;
} ) ;
2012-01-05 20:54:24 -08:00
var follow _user ;
2012-01-04 09:42:35 -08:00
if ( following _profile ) {
2012-01-05 20:54:24 -08:00
follow _user = following _profile . set ( data . follow _profile ) ;
2012-01-04 09:42:35 -08:00
} else {
this . following _profiles . add ( data . follow _profile ) ;
}
2012-03-15 11:33:00 -07:00
this . social _feeds . remove ( data . follow _subscription ) ;
2012-02-10 12:48:14 -08:00
this . social _feeds . add ( data . follow _subscription ) ;
2012-07-25 23:57:10 -07:00
callback ( data ) ;
2012-04-04 16:09:01 -07:00
} , this ) ) ;
2012-01-04 09:42:35 -08:00
} ,
unfollow _user : function ( user _id , callback ) {
2012-04-04 16:09:01 -07:00
this . make _request ( '/social/unfollow' , { 'user_id' : user _id } , _ . bind ( function ( data ) {
2012-01-04 09:42:35 -08:00
this . user _profile . set ( data . user _profile ) ;
this . following _profiles . remove ( function ( profile ) {
2012-01-05 20:54:24 -08:00
return profile . get ( 'user_id' ) == data . unfollow _profile . user _id ;
2012-01-04 09:42:35 -08:00
} ) ;
2012-02-10 12:48:14 -08:00
this . social _feeds . remove ( data . unfollow _profile . id ) ;
2012-07-25 23:57:10 -07:00
callback ( data ) ;
2012-04-04 16:09:01 -07:00
} , this ) ) ;
2012-01-04 09:42:35 -08:00
} ,
2012-10-24 18:52:24 -07:00
approve _follower : function ( user _id , callback ) {
this . make _request ( '/social/approve_follower' , { 'user_id' : user _id } , _ . bind ( function ( data ) {
callback ( data ) ;
} , this ) ) ;
} ,
ignore _follower : function ( user _id , callback ) {
this . make _request ( '/social/ignore_follower' , { 'user_id' : user _id } , _ . bind ( function ( data ) {
callback ( data ) ;
} , this ) ) ;
} ,
2012-01-11 22:01:06 -08:00
load _public _story _comments : function ( story _id , feed _id , callback ) {
2012-06-29 21:25:35 -07:00
this . make _request ( '/social/public_comments' , {
2012-01-11 22:01:06 -08:00
'story_id' : story _id ,
2012-03-15 14:00:44 -07:00
'feed_id' : feed _id
2012-04-04 20:54:54 -07:00
} , _ . bind ( function ( data ) {
if ( data . user _profiles ) {
this . add _user _profiles ( data . user _profiles ) ;
}
2012-06-05 16:18:30 -07:00
var comments = new NEWSBLUR . Collections . Comments ( data . comments ) ;
callback ( comments ) ;
2012-04-04 20:54:54 -07:00
} , this ) , null , { request _type : 'GET' } ) ;
2012-01-11 22:01:06 -08:00
} ,
2012-12-03 15:03:47 -08:00
fetch _payment _history : function ( callback ) {
this . make _request ( '/profile/payment_history' , { } , callback , null , { request _type : 'GET' } ) ;
} ,
2012-03-19 11:15:26 -07:00
follow _twitter _account : function ( username , callback ) {
this . make _request ( '/oauth/follow_twitter_account' , { 'username' : username } , callback ) ;
} ,
unfollow _twitter _account : function ( username , callback ) {
this . make _request ( '/oauth/unfollow_twitter_account' , { 'username' : username } , callback ) ;
} ,
2013-01-08 18:33:30 -08:00
fetch _original _text : function ( story _id , feed _id , callback , error _callback ) {
2013-02-12 12:07:16 -08:00
var story = this . get _story ( story _id ) ;
2013-01-08 18:33:30 -08:00
this . make _request ( '/rss_feeds/original_text' , {
story _id : story _id ,
feed _id : feed _id
2013-02-12 12:07:16 -08:00
} , function ( data ) {
story . set ( 'original_text' , data . original _text ) ;
callback ( data ) ;
} , error _callback , {
2013-01-08 18:33:30 -08:00
request _type : 'GET' ,
2013-01-08 19:29:02 -08:00
ajax _group : 'statistics'
2013-01-08 18:33:30 -08:00
} ) ;
} ,
2012-07-01 12:00:30 -07:00
recalculate _story _scores : function ( feed _id , options ) {
options = options || { } ;
2012-05-25 18:54:04 -07:00
this . stories . each ( _ . bind ( function ( story , i ) {
if ( story . get ( 'story_feed_id' ) != feed _id ) return ;
2012-05-25 22:13:50 -07:00
var intelligence = {
author : 0 ,
feed : 0 ,
tags : 0 ,
title : 0
} ;
2012-05-25 18:54:04 -07:00
2012-07-01 12:00:30 -07:00
_ . each ( this . classifiers [ feed _id ] . titles , function ( classifier _score , classifier _title ) {
2012-06-12 16:13:34 -07:00
if ( intelligence . title <= 0 &&
story . get ( 'story_title' , '' ) . indexOf ( classifier _title ) != - 1 ) {
2012-05-25 18:54:04 -07:00
intelligence . title = classifier _score ;
2011-02-27 16:13:22 -05:00
}
2012-07-01 12:00:30 -07:00
} ) ;
2011-02-27 16:13:22 -05:00
2012-07-01 12:00:30 -07:00
_ . each ( this . classifiers [ feed _id ] . authors , function ( classifier _score , classifier _author ) {
2012-06-12 16:13:34 -07:00
if ( intelligence . author <= 0 &&
story . get ( 'story_authors' , '' ) . indexOf ( classifier _author ) != - 1 ) {
2012-05-25 18:54:04 -07:00
intelligence . author = classifier _score ;
2011-02-27 16:13:22 -05:00
}
2012-07-01 12:00:30 -07:00
} ) ;
2011-02-27 16:13:22 -05:00
2012-07-01 12:00:30 -07:00
_ . each ( this . classifiers [ feed _id ] . tags , function ( classifier _score , classifier _tag ) {
2012-06-12 16:13:34 -07:00
if ( intelligence . tags <= 0 &&
story . get ( 'story_tags' ) && _ . contains ( story . get ( 'story_tags' ) , classifier _tag ) ) {
2012-05-25 18:54:04 -07:00
intelligence . tags = classifier _score ;
2011-02-27 16:13:22 -05:00
}
2012-07-01 12:00:30 -07:00
} ) ;
2011-02-27 16:13:22 -05:00
2012-07-01 12:00:30 -07:00
_ . each ( this . classifiers [ feed _id ] . feeds , function ( classifier _score , classifier _feed _id ) {
2012-06-12 16:13:34 -07:00
if ( intelligence . feed <= 0 &&
story . get ( 'story_feed_id' ) == classifier _feed _id ) {
2012-05-25 18:54:04 -07:00
intelligence . feed = classifier _score ;
2011-02-27 16:13:22 -05:00
}
2012-07-01 12:00:30 -07:00
} ) ;
2012-05-25 18:54:04 -07:00
2012-07-01 12:00:30 -07:00
story . set ( 'intelligence' , intelligence , options ) ;
2011-02-27 16:13:22 -05:00
} , this ) ) ;
2010-06-08 11:19:41 -04:00
}
2010-08-25 10:18:08 -04:00
2012-05-17 18:40:46 -07:00
} ) ;